Merge pull request #2 from DLC-link/push-to-ecr #10
Workflow file for this run
This file contains hidden or 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
| name: Build and push Docker image | |
| on: | |
| push: | |
| branches: | |
| - '**' | |
| tags: | |
| - 'v*' | |
| permissions: | |
| contents: read | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # 1) Configure AWS creds (needed for ECR auth) | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.TF_AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.TF_AWS_SECRET_ACCESS_KEY }} | |
| aws-region: us-east-1 | |
| # 2) Login to Public ECR | |
| - name: Login to Amazon ECR Public | |
| id: login-ecr-public | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| with: | |
| registry-type: public | |
| - name: Compute image tags | |
| id: vars | |
| run: | | |
| REGISTRY="public.ecr.aws" | |
| ALIAS="dlc-link" | |
| REPO="cantcost" | |
| IMAGE="${REGISTRY}/${ALIAS}/${REPO}" | |
| if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then | |
| TAG_NAME="${GITHUB_REF_NAME}" # e.g. v1.2.3 | |
| echo "tags=${IMAGE}:${TAG_NAME},${IMAGE}:latest" >> $GITHUB_OUTPUT | |
| else | |
| SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7) | |
| echo "tags=${IMAGE}:sha-${SHORT_SHA}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Build and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: ${{ steps.vars.outputs.tags }} |