Skip to content

fix: release drafter configuration #55

fix: release drafter configuration

fix: release drafter configuration #55

name: Build and Publish Docker Image
on:
push:
branches:
- 'dev'
- 'main'
paths-ignore:
- '**/terraform/**'
env:
IMAGE_NAME: bcgov/otp-provider
GITHUB_REGISTRY: ghcr.io
IMAGE_TAG: dev
jobs:
build-and-push-image:
permissions:
contents: write
packages: write
runs-on: ubuntu-24.04
environment:
name: ${{ github.ref == 'refs/heads/main' && 'Production' || 'Sandbox' }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Log in to github container registry
uses: docker/login-action@v4
with:
registry: ${{ env.GITHUB_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up docker buildx
uses: docker/setup-buildx-action@v4
- name: Cache docker layers
uses: actions/cache@v5
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Create release tag
id: release
if: github.ref == 'refs/heads/main'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: release-drafter/release-drafter@v7
with:
config-name: .github/release.yml
- name: Set image tag
id: set_image_tag
run: |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
echo "IMAGE_TAG=${{ steps.release.outputs.tag_name }}" >> $GITHUB_ENV
else
echo "IMAGE_TAG=dev" >> $GITHUB_ENV
fi
- name: Build and push image
uses: docker/build-push-action@v7
with:
context: .
push: true
tags: ${{ env.GITHUB_REGISTRY }}/${{env.IMAGE_NAME}}:${{ env.IMAGE_TAG }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache