Skip to content

Commit

Permalink
Create main.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
crawftv authored Nov 20, 2024
1 parent e4b70e6 commit 1586e5b
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/main.yml
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 }}"

0 comments on commit 1586e5b

Please sign in to comment.