Skip to content

Docker Build and Push (OSLC RefImpl) #86

Docker Build and Push (OSLC RefImpl)

Docker Build and Push (OSLC RefImpl) #86

Workflow file for this run

name: "Docker Build and Push (OSLC RefImpl)"
on:
push:
branches: [main]
paths:
- 'src/**'
- '.github/workflows/docker.yml'
release:
types: [published]
schedule:
# Weekly rebuild every Friday at 3:00 AM UTC to get latest base image updates
- cron: '0 3 * * 5'
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_BASE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
server: [server-rm, server-cm, server-qm, server-am]
include:
- server: server-rm
description: "OSLC Requirements Management Reference Implementation"
- server: server-cm
description: "OSLC Change Management Reference Implementation"
- server: server-qm
description: "OSLC Quality Management Reference Implementation"
- server: server-am
description: "OSLC Asset Management Reference Implementation"
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Check build trigger
run: |
if [ "${{ github.event_name }}" = "schedule" ]; then
echo "🔄 This is a scheduled weekly rebuild to update base images"
elif [ "${{ github.event_name }}" = "release" ]; then
echo "🚀 This is a release build"
else
echo "📦 This is a regular build triggered by push"
fi
echo "Building ${{ matrix.server }} (${{ matrix.description }})"
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_BASE_NAME }}/${{ matrix.server }}
tags: |
# For pushes to master branch or scheduled builds, tag as "latest"
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || github.event_name == 'schedule' }}
# For releases, create semantic version tags
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
labels: |
org.opencontainers.image.title=OSLC RefImpl ${{ matrix.server }}
org.opencontainers.image.description=${{ matrix.description }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ./src
file: ./src/${{ matrix.server }}/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha,scope=${{ matrix.server }}
cache-to: type=gha,mode=max,scope=${{ matrix.server }}
# For scheduled builds, don't use cache to ensure fresh base images
no-cache: ${{ github.event_name == 'schedule' }}
pull: true
- name: Output image details
run: |
echo "Image for ${{ matrix.server }} has been pushed to:"
echo "${{ steps.meta.outputs.tags }}" | while read -r tag; do
echo " - $tag"
done