Skip to content

Build & push images #1168

Build & push images

Build & push images #1168

Workflow file for this run

name: Build & push images
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
# Build new images immediately after a push to main
push:
branches:
- main
paths-ignore:
- '.github/**'
# Build PR images with a `-pr###` suffix to test
pull_request:
branches:
- main
# Build every day at 6:00 UTC to keep Python and Node minor versions updated
schedule:
- cron: '0 6 * * *'
# Allow running on-demand
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python: ['3.13', '3.12', '3.11']
node: ['22', '20']
steps:
- uses: actions/checkout@v4
- name: Configure tag & caching
run: |
# Set tag
TAG="py${{ matrix.python }}-node${{ matrix.node }}"
# Append a PR identifier if necessary
PR="${{ github.event.pull_request.number }}"
if [ ! -z "$PR" ]; then TAG="$TAG-pr$PR"; fi
echo "TAG=$TAG" >> $GITHUB_ENV
# Disable cache-from in scheduled runs to ensure fresh minor versions
# every day for both Python and Node
if [ "${{ github.event_name }}" = "schedule" ]
then
CACHEFROM=""
else
CACHEFROM="type=gha"
fi
echo "CACHEFROM=$CACHEFROM" >> $GITHUB_ENV
- name: Prepare image metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/oddbird/pyjs
tags: |
type=raw,value=${{ env.TAG }}
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: ${{ env.CACHEFROM }}
cache-to: type=gha,mode=max
build-args: |
NODE_VERSION=${{ matrix.node }}
PYTHON_VERSION=${{ matrix.python }}
keep-alive:
name: Push commit to keep this workflow alive
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
git fetch origin # Fetch remote commits on all branches
FIFTY_DAYS=4320000 # In seconds
TIME_SINCE_COMMIT=$(expr $(date +%s) - $(git log --all -1 --format=%ct))
if [ "$TIME_SINCE_COMMIT" -gt "$FIFTY_DAYS" ]; then
git config user.name github-actions
git config user.email [email protected]
git commit --allow-empty -m "Keep alive commit"
git push -f origin ${{ github.ref_name }}:gh-actions-keep-alive
else
echo "Keep-alive commit not needed... yet"
fi