Update build-docker.yml #19
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 Docker Image | |
on: | |
workflow_dispatch: | |
pull_request: | |
branches: [ "main" ] | |
paths: | |
- .github/workflows/build-docker.yml | |
- Dockerfile | |
push: | |
branches: [ "main" ] | |
release: | |
types: [ "published" ] | |
env: | |
PUSH_IMAGE: true | |
IMAGE_NAME: juliencaposiena/ATAC | |
RUST_VERSION: "1.79" | |
jobs: | |
build-and-publish: | |
name: Build and Publish Docker Image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.IMAGE_NAME }} | |
tags: | | |
# When the main branch gets updated, don't tag it as 'main'; instead, tag it as 'latest' | |
type=ref,event=branch,enable=false | |
type=raw,value=latest,enable={{is_default_branch}} | |
type=semver,pattern={{raw}} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
if: ${{ env.PUSH_IMAGE == 'true' && github.event_name != 'pull_request' }} | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
build-args: RUST_VERSION=${{ env.RUST_VERSION }} | |
push: ${{ env.PUSH_IMAGE == 'true' && github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
# Reuse docker build cache | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |