Skip to content

Build and push Caddy image to Docker Hub and GitHub Container Registry #6

Build and push Caddy image to Docker Hub and GitHub Container Registry

Build and push Caddy image to Docker Hub and GitHub Container Registry #6

# Author: Hung Vu
# Granular action for only build and push caddy image
name: Build and push Caddy image to Docker Hub and GitHub Container Registry
on:
workflow_dispatch:
jobs:
build-and-publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
# Seems like we need to checkout the repo first
# because docker build push does not work for nested directories
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub Container Registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker images
id: meta
uses: docker/metadata-action@v5
with:
images: |
docker.io/hunghvu/blogfolio-caddy
ghcr.io/hunghvu/blogfolio-caddy
# If we want to reference a subdir
# https://github.com/docker/build-push-action/issues/528
# https://github.com/docker/build-push-action/issues/888
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./infras/containers/caddy/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64