Skip to content

Build and Push Docker Image #12

Build and Push Docker Image

Build and Push Docker Image #12

name: Build and Push Docker Image
# Mirrors the Makefile's `build` (docker build --no-cache) and `push`
# (docker push) targets from https://github.com/aphrc-nocode/no-code-devops
on:
push:
branches: [main]
tags: ['v*']
workflow_dispatch: {}
env:
IMAGE_NAME: no-code-app # same as IMAGE_NAME in the Makefile
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Makefile uses IMAGE_VERSION=latest on normal builds and
# RELEASE_VERSION=release when cutting a release. We replicate
# that: a git tag push (v*) builds the "release" tag, everything
# else builds "latest".
- name: Determine image tag
id: vars
run: |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
echo "tag=release" >> "$GITHUB_OUTPUT"
else
echo "tag=latest" >> "$GITHUB_OUTPUT"
fi
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
push: true
no-cache: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.tag }}