Skip to content

Build And Push Docker image #619

Build And Push Docker image

Build And Push Docker image #619

name: Build And Push Docker image
on:
schedule:
- cron: "0 23 * * *"
push:
tags:
- "v*.*.*"
pull_request:
branches:
- "main"
workflow_dispatch:
jobs:
build_and_push:
name: Docker Build and Push
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=schedule
type=ref,event=branch,suffix=-{{ sha }}
type=ref,event=pr
type=semver,pattern={{version}},value=${{ github.event.release.tag_name }}
type=raw,value=stable,enable=${{ startsWith(github.ref, 'refs/tags/') }}
flavor: |
latest=true
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
platforms: linux/amd64,linux/arm64 # also support the new mac architecture (requires buildx)
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# use layer caching. Don't forget mode=max to also cache the build image
# (vs only the final image - mode: min)
cache-from: type=gha
cache-to: type=gha,mode=max