Skip to content

Build and push Web image to Docker Hub and GitHub Container Registry #43

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

Build and push Web image to Docker Hub and GitHub Container Registry #43

# Author: Hung Vu
# Granular action for only build and push web image
name: Build and push Web image to Docker Hub
on:
workflow_dispatch:
jobs:
build-and-publish:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- dockerfile: ./apps/web/Dockerfile
image: docker.io/hunghvu/blogfolio-web
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: Extract metadata (tags, labels) for Docker images
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ matrix.image }}
# 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: ${{ matrix.dockerfile }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64