Skip to content

Container Build and Push #44

Container Build and Push

Container Build and Push #44

name: Container Build and Push
on:
push:
branches:
- "main"
workflow_dispatch:
schedule:
# Do a daily rebuild at 2:00 AM UTC
- cron: '0 2 * * *'
env:
GITHUB_REGISTRY: ghcr.io
jobs:
# Branch push job - builds and pushes to both registries
branch-push:
# This workflow is only for pushing builds from the official repo
if: github.repository_owner == 'chairemobilite'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# Matrix strategy to build both client and server image
strategy:
fail-fast: false
matrix:
include:
- name: client
context: client
dockerfile: client/Dockerfile
- name: server
context: .
dockerfile: serveur/Dockerfile
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Generate Docker tags for branch
id: branch-meta
uses: docker/metadata-action@v6
with:
images: |
${{ env.GITHUB_REGISTRY }}/${{ github.repository }}-${{ matrix.name }}
tags: |
# Tag as latest for main
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
# Include the branch name as a tag
type=ref,event=branch
- name: Build and push ${{ matrix.name }} images
uses: docker/build-push-action@v7
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
push: true
tags: ${{ steps.branch-meta.outputs.tags }}
labels: ${{ steps.branch-meta.outputs.labels }}
cache-from: type=gha,scope=${{ matrix.name }}
cache-to: type=gha,mode=max,scope=${{ matrix.name }}