Build and Publish ReefGuideAPI.jl Docker Image #29
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
# This workflow builds and publishes the ReefGuideAPI base Docker image to GitHub Container Registry (ghcr.io) | |
# It is triggered when a push is made to the main branch. | |
# Additional notes: | |
# - The workflow uses the github.repository context to name the image, ensuring it's tied to your repository | |
# - The GITHUB_TOKEN is automatically provided by GitHub Actions, no need to set it up manually | |
# - The Docker metadata action automatically generates appropriate tags based on the release version | |
# - The Julia version can be easily updated by changing the JULIA_VERSION environment variable at the top of the workflow | |
name: Build and Publish ReefGuideAPI.jl Docker Image | |
on: | |
workflow_dispatch: | |
# push: | |
# branches: | |
# - main | |
release: | |
types: [published] | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }}/reefguide-src | |
JULIA_VERSION: 1.10.5 | |
# Set to true to use a fixed ReefGuideAPI version for debugging, false to use the release version | |
USE_FIXED_REEFGUIDEAPI_VERSION: true | |
# TODO this doesn't make sense until the releasing is sorted out | |
# The fixed ReefGuideAPI version to use when USE_FIXED_REEFGUIDEAPI_VERSION is true | |
FIXED_REEFGUIDEAPI_VERSION: "0.1.0" | |
jobs: | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
# Step 1: Checkout the repository code | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# Step 2: Extract the version number from the release tag | |
# This removes the 'v' prefix from the tag (e.g., 'v1.2.3' becomes '1.2.3') | |
- name: Extract version from tag | |
id: get_version | |
run: | | |
if ${{ env.USE_FIXED_REEFGUIDEAPI_VERSION == 'true' }}; then | |
echo "Using fixed ReefGuideAPI version: ${{ env.FIXED_REEFGUIDEAPI_VERSION }}" | |
echo "VERSION=${{ env.FIXED_REEFGUIDEAPI_VERSION }}" >> $GITHUB_OUTPUT | |
elif [ "${{ github.event_name }}" = "release" ]; then | |
RELEASE_VERSION=${GITHUB_REF#refs/tags/v} | |
echo "Using release version: $RELEASE_VERSION" | |
echo "VERSION=$RELEASE_VERSION" >> $GITHUB_OUTPUT | |
else | |
echo "No version specified and not a release event. Using default version." | |
echo "VERSION=${{ env.FIXED_REEFGUIDEAPI_VERSION }}" >> $GITHUB_OUTPUT | |
fi | |
# Step 3: Log in to the GitHub Container Registry | |
# This uses the provided GitHub token for authentication | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Step 4: Extract metadata for Docker | |
# This step generates tags and labels for the Docker image | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}}.{{minor}}.{{patch}} | |
type=semver,pattern={{major}} | |
type=ref,event=branch | |
type=sha,format=long | |
type=sha,format=short | |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} | |
# Step 5: Build and push the Docker image | |
# This step builds the reefguide-src image and pushes it to the registry | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
target: reefguide-src # Specifies which stage of the Dockerfile to build | |
push: true # Pushes the image to the registry | |
tags: ${{ steps.meta.outputs.tags }} # Uses the tags generated in the metadata step | |
labels: ${{ steps.meta.outputs.labels }} # Uses the labels generated in the metadata step | |
# Passes the Julia and ReefGuideAPI versions to the Dockerfile | |
# TODO bring back this build arg when releasing is ready | |
# REEFGUIDE_VERSION=${{ steps.get_version.outputs.VERSION }} | |
build-args: | | |
JULIA_VERSION=${{ env.JULIA_VERSION }} |