Merge pull request #7 from cm-jones/dev #2
This file contains hidden or 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: Docker Build and Publish | |
on: | |
push: | |
branches: main | |
# Only trigger when Dockerfile or docker-compose changes | |
paths: | |
- "docker/**" | |
- ".github/workflows/docker-publish.yaml" | |
- "src/**" | |
- "include/**" | |
- "CMakeLists.txt" | |
- ".version" | |
# Allow manual triggering | |
workflow_dispatch: | |
env: | |
# Use docker.io for Docker Hub | |
REGISTRY: docker.io | |
# github.repository as <account>/<repo> | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-${{ vars.UBUNTU_VERSION }} | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Set up BuildKit Docker container builder to enable more efficient builds | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
# Login to Docker Hub | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
# Extract Ubuntu version from .version file | |
- name: Extract Ubuntu version | |
id: ubuntu_version | |
run: | | |
UBUNTU_VERSION=$(grep "UBUNTU_VERSION" .version | cut -d= -f2) | |
echo "UBUNTU_VERSION=$UBUNTU_VERSION" >> $GITHUB_ENV | |
# Extract version for tagging | |
- name: Extract version | |
id: version | |
run: | | |
VERSION=$(grep "THALES_VERSION" .version | cut -d= -f2) | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
# Build and push Docker image for multiple platforms | |
- name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./docker/Dockerfile | |
push: true | |
platforms: linux/amd64,linux/arm64 | |
build-args: | | |
UBUNTU_VERSION=${{ env.UBUNTU_VERSION }} | |
tags: | | |
${{ env.REGISTRY }}/${{ github.repository_owner }}/thales:latest | |
${{ env.REGISTRY }}/${{ github.repository_owner }}/thales:${{ env.VERSION }} | |
${{ env.REGISTRY }}/${{ github.repository_owner }}/thales:${{ env.VERSION }}-${{ env.SHA_SHORT }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |