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_dispatch: | ||
workflow_call: | ||
secrets: | ||
GITHUB_TOKEN: | ||
Check failure on line 7 in .github/workflows/docker-build-and-publish.yml GitHub Actions / .github/workflows/docker-build-and-publish.ymlInvalid workflow file
|
||
required: true | ||
jobs: | ||
# define job to build and publish docker image | ||
build-and-publish: | ||
name: Build and Publish Docker image | ||
# run only when code is compiling and tests are passing | ||
runs-on: ubuntu-latest | ||
# steps to perform in job | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
- name: Docker metadata | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
# list of Docker images to use as base name for tags | ||
images: | | ||
ghcr.io/${{ github.repository }} | ||
# generate Docker tags based on the following events/attributes | ||
tags: | | ||
type=ref,event=branch | ||
type=ref,event=pr | ||
type=semver,pattern={{version}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
type=semver,pattern={{major}} | ||
type=sha | ||
type=raw,value=latest,enable={{is_default_branch}} | ||
# setup Docker buld action | ||
- name: Set up Docker Buildx | ||
id: docker_build | ||
uses: docker/setup-buildx-action@v2 | ||
# - name: Login to DockerHub | ||
# uses: docker/login-action@v2 | ||
# with: | ||
# username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
# password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
- name: Login to Github Packages | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Build and Publish to GitHub Container Registry | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
build-args: | | ||
VERSION=${{ github.event.release.tag_name }} | ||
RELEASE_TIME=${{ github.event.release.created_at }} | ||
GIT_REPO=${{ github.repository }} | ||
GIT_COMMIT_SHA=${{ github.sha }} | ||
GIT_COMMIT_TIME=${{ github.event.push.head_commit.timestamp }} | ||
GIT_REF=${{ github.ref_name }} | ||
GIT_WORKFLOW_SHA=${{ github.workflow_sha }} | ||
cache-from: type=registry,ref=${{ github.ref_name }} | ||
cache-to: type=inline | ||
- name: Image digest | ||
run: echo ${{ steps.docker_build.outputs.digest }} |