Build and push CMS image to Docker Hub and GitHub Container Registry #21
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
# Author: Hung Vu | |
# Granular action for only build and push cms image | |
name: Build and push CMS 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-cms | |
ghcr.io/hunghvu/blogfolio-cms | |
# 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: ./apps/cms/Dockerfile | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
platforms: linux/amd64,linux/arm64 |