Build Docker image and push to GHCR #2
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
name: Build Docker image and push to GHCR | |
on: | |
# Enable manual launching | |
workflow_dispatch: | |
# Run when we push to main and have changed the Go code or Dockerfile | |
push: | |
branches: | |
- main | |
paths: | |
- "**/*.go" | |
- "Dockerfile" | |
- "go.*" | |
# Run at 00:00 every Monday to catch base image upgrades | |
schedule: | |
- cron: "0 0 * * 1" | |
env: | |
DOCKER_IMAGE: ghcr.io/${{ github.repository }}/adder:latest | |
jobs: | |
build-push-image: | |
runs-on: ubuntu-latest | |
# Turn on write permission for packages so we can push to GHCR | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} # Username of whoever kicked off this job | |
password: ${{ secrets.GITHUB_TOKEN }} # Token for the permissions given to this runner | |
- name: Build and push image | |
uses: docker/build-push-action@v5 | |
with: | |
tags: ${{ env.DOCKER_IMAGE }} | |
build-args: "GO_VERSION=${{ vars.GO_VERSION }}" | |
push: true | |