Skip to content

Build image via GA

Build image via GA #2

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
# Writes a throwaway .env file into the build context from repo
# secrets, so the real .env never needs to be committed. Keep .env
# in .gitignore.
- name: Create .env file
run: |
cat <<EOF > .env
email_host=${{ secrets.EMAIL_HOST }}
email_port=${{ secrets.EMAIL_PORT }}
email_username=${{ secrets.EMAIL_USERNAME }}
email_password=${{ secrets.EMAIL_PASSWORD }}
from_email=${{ secrets.FROM_EMAIL }}
APP_ID=${{ secrets.APP_ID }}
EOF
- 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 }}