Build and Publish Docker Image #5
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 and Publish Docker Image | |
on: | |
workflow_run: | |
workflows: ["Test"] | |
types: | |
- completed | |
jobs: | |
build: | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
repository: ${{ github.event.workflow_run.head_repository.full_name }} | |
ref: ${{ github.event.workflow_run.head_branch }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract version and commit hash | |
id: version | |
run: | | |
echo "VERSION=$(jq -r .version < package.json)-${{ github.sha }}" >> $GITHUB_ENV | |
echo "SHORT_SHA=$(echo ${GITHUB_SHA} | head -c 8)" >> $GITHUB_ENV | |
- name: Lowercase GitHub repository name | |
run: | | |
echo "IMAGE_NAME=${{ github.repository }} | tr '[:upper:]' '[:lower:]'" >> $GITHUB_ENV | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: Containerfile | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: | | |
ghcr.io/${{ env.IMAGE_NAME }}:latest, | |
ghcr.io/${{ env.IMAGE_NAME }}:${{ env.VERSION }}, | |
ghcr.io/${{ env.IMAGE_NAME }}:${{ env.VERSION }}-${{ env.SHORT_SHA }} |