Build & publish ECS/Fargate worker image to ECR #165
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
name: Build & publish ECS/Fargate worker image to ECR | |
on: | |
workflow_dispatch: | |
workflow_call: | |
inputs: | |
ref: | |
description: 'Branch ref to checkout. Needed for pull_request_target to be able to pull correct ref.' | |
type: string | |
secrets: | |
ECR_WORKER_IMAGE_PUSH_ROLE_ARN: | |
description: 'ARN of the IAM role to assume to push the image to ECR.' | |
required: true | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
build_docker_image: | |
runs-on: ubuntu-latest | |
env: | |
# From PR's this is overridden by a head ref by the caller workflow. defaults to commit sha when not passed (e.g. workflow_dispatch or call from main branch) | |
WORKER_VERSION: ${{ inputs.ref || github.sha }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: ${{ inputs.ref || null }} | |
fetch-depth: 0 | |
- name: Show git ref | |
run: | | |
echo GITHUB REF ${{ github.ref }} | |
echo GITHUB PR HEAD SHA ${{ github.event.pull_request.head.sha }} | |
echo GITHUB SHA ${{ github.sha }} | |
echo WORKER_VERSION ENV ${{ env.WORKER_VERSION }} | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-region: us-east-1 | |
audience: sts.amazonaws.com | |
role-to-assume: ${{ secrets.ECR_WORKER_IMAGE_PUSH_ROLE_ARN }} | |
role-session-name: OIDCSession | |
mask-aws-account-id: true | |
- name: Login to Amazon ECR Public | |
id: login-ecr-public | |
uses: aws-actions/amazon-ecr-login@v1 | |
with: | |
registry-type: public | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 | |
with: | |
images: public.ecr.aws/d8a4z9o5/artillery-worker | |
tags: | | |
type=semver,pattern={{version}} | |
- name: Build the Docker image | |
run: | | |
docker build . --build-arg="WORKER_VERSION=${{ env.WORKER_VERSION }}" --tag public.ecr.aws/d8a4z9o5/artillery-worker:${{ env.WORKER_VERSION }} -f ./packages/artillery/lib/platform/aws-ecs/worker/Dockerfile | |
- name: Push Docker image | |
run: | | |
docker push public.ecr.aws/d8a4z9o5/artillery-worker:${{ env.WORKER_VERSION }} |