-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: Build and Push to ECR | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
types: | ||
- closed | ||
branches: | ||
- main | ||
|
||
env: | ||
AWS_REGION: us-east-1 | ||
ECR_REPOSITORY: crawfordc | ||
APP_NAME: theseus | ||
DOCKERFILE_PATH: ./app | ||
|
||
|
||
jobs: | ||
build-and-push: | ||
if: github.event.pull_request.merged == true || github.event_name == 'push' | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v2 | ||
|
||
- name: Build, tag, and push image to Amazon ECR | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
run: | | ||
# Build with cache | ||
docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$APP_NAME || true | ||
docker build \ | ||
--cache-from $ECR_REGISTRY/$ECR_REPOSITORY:$APP_NAME \ | ||
--tag $ECR_REGISTRY/$ECR_REPOSITORY:$APP_NAME \ | ||
--tag $ECR_REGISTRY/$ECR_REPOSITORY:$APP_NAME-$IMAGE_TAG \ | ||
-f $DOCKERFILE_PATH/Dockerfile \ | ||
$DOCKERFILE_PATH | ||
# Push both tags | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$APP_NAME | ||
- name: Output Image URIs | ||
run: | | ||
echo "Latest Image = ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ env.APP_NAME }}" |