Merge pull request #1 from gmarzot/gmarzot_vcm_enhancements #4
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 and Publish Docker Images | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- '[0-9]+.[0-9]+.[0-9]+' | |
workflow_dispatch: | |
env: | |
REGISTRY: ghcr.io | |
OWNER: ${{ github.repository_owner }} | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
strategy: | |
matrix: | |
image: [nginx, node-red] | |
platform: [linux/amd64, linux/arm64] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Add this line | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Get version from git | |
id: get_version | |
run: | | |
VERSION=$(git describe --tags --always) | |
# Trim hash if version contains a -g followed by hash | |
VERSION=$(echo $VERSION | sed 's/-g[0-9a-f]\+$//') | |
echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
- name: Extract metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.OWNER }}/vcache-mgr-${{ matrix.image }} | |
tags: | | |
type=ref,event=tag | |
type=raw,value=${{ steps.get_version.outputs.version }},enable=${{ github.event_name == 'workflow_dispatch' }} | |
- name: Set Dockerfile path | |
id: dockerfile | |
run: | | |
case "${{ matrix.image }}" in | |
"nginx") | |
echo "path=./context/nginx/Dockerfile" >> $GITHUB_OUTPUT | |
;; | |
"node-red") | |
echo "path=./context/node-red/Dockerfile.release" >> $GITHUB_OUTPUT | |
;; | |
esac | |
- name: Build and push image | |
uses: docker/build-push-action@v5 | |
with: | |
context: './context' | |
file: ${{ steps.dockerfile.outputs.path }} | |
platforms: ${{ matrix.platform }} | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |