Skip to content

Workflow file for this run

name: Build and push docker image for branch or tag
on:
release:
types: [ released ]
push:
branches: ['**']
permissions:
id-token: write
contents: read
env:
ECR_REPO_URL: ${{ secrets.AWS_RELEASE_ECR_REPO }}
DEV_ECR_REPO_URL: ${{ secrets.AWS_DEVELOPMENT_ECR_REPO }}
jobs:
build-zxcvbn-i18n-api-container:
name: Build zxcvbn-i18n-api container
runs-on: ubuntu-latest
if: github.repository == 'ScientaNL/zxcvbn-i18n-api'
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Set Github environment variables
uses: ScientaNL/[email protected]
- name: Checkout repository
uses: actions/checkout@v4
- name: Configure AWS Credentials for release
uses: aws-actions/configure-aws-credentials@v4
if: github.event_name == 'release'
with:
aws-region: eu-central-1
role-to-assume: ${{ secrets.AWS_RELEASE_ECR_ROLE }}
role-session-name: "GithubActions-Release"
- name: Login to Amazon ECR Operations
id: login-ecr-ops
if: github.event_name == 'release'
uses: aws-actions/amazon-ecr-login@v2
with:
registries: ${{ secrets.AWS_OPERATIONS_ACCOUNT_ID }}
- name: Configure AWS Credentials for development
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: eu-west-3
role-to-assume: ${{ secrets.AWS_DEVELOPMENT_ECR_ROLE }}
role-session-name: "GithubActions-DEV"
- name: Login to Amazon ECR Development
id: login-ecr-dev
uses: aws-actions/amazon-ecr-login@v2
with:
registries: ${{ secrets.AWS_DEVELOPMENT_ACCOUNT_ID }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build & push Docker image
uses: docker/build-push-action@v6
with:
push: true
tags: |
${{ env.DEV_ECR_REPO_URL }}/scienta/zxcvbn-i18n-api:${{ github.event_name == 'push' && 'branch-' || '' }}${{env.GITHUB_REF_NAME_SLUG}}
${{ github.event_name == 'release' && format('{0}/scienta/zxcvbn-i18n-api:{1}', env.ECR_REPO_URL, env.GITHUB_REF_NAME_SLUG) || '' }}
build-args: |
- API_VERSION=${{ github.event_name == 'push' && format('{0}-{1}', env.GITHUB_REF_NAME_SLUG, env.GITHUB_SHA_SHORT) || env.GITHUB_REF_NAME_SLUG }}
cache-from: type=registry,ref=${{ env.DEV_ECR_REPO_URL }}/scienta/zxcvbn-i18n-api:cache
cache-to: image-manifest=true,oci-mediatypes=true,type=registry,mode=max,ref=${{ env.DEV_ECR_REPO_URL }}/scienta/zxcvbn-i18n-api:cache