Skip to content

Temporarily build on a branch #1

Temporarily build on a branch

Temporarily build on a branch #1

Workflow file for this run

name: Build and Push Docker Image
on:
push:
branches:
- master
- dockerise
tags:
- 'v*'
pull_request:
branches:
- master
env:
ECR_REGISTRY: 929887798640.dkr.ecr.us-east-2.amazonaws.com
ECR_REPOSITORY: gwtm_cron_listener
AWS_REGION: us-east-2
jobs:
build:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Extract metadata (tags, labels)
id: meta
run: |
# Generate tags
TAGS="${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest"
# If this is a tag push, also tag with the version
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
TAGS="$TAGS,${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${VERSION}"
fi
# If this is a branch push, also tag with the commit SHA
if [[ $GITHUB_REF == refs/heads/* ]]; then
TAGS="$TAGS,${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${GITHUB_SHA::8}"
fi
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: |
org.opencontainers.image.created=${{ steps.meta.outputs.date }}
org.opencontainers.image.source=${{ github.repositoryUrl }}
org.opencontainers.image.revision=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Image digest
run: echo "Image pushed successfully"