Skip to content

Publish Docker Images to GitHub Container Registry #226

Publish Docker Images to GitHub Container Registry

Publish Docker Images to GitHub Container Registry #226

name: Publish Docker Images to GitHub Container Registry
on:
push:
branches:
- main
workflow_run:
workflows: ["Check for New Docker Package in Another Repo"]
types:
- completed
jobs:
push_to_registry:
name: Push multi-platform docker images to ghcr.io
runs-on: ubuntu-latest
# Only run the job if the trigger was a push to main, or if the triggering workflow was successful
if: github.event_name == 'push' || (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')
steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download tag artifact from triggering workflow
if: github.event_name == 'workflow_run'
uses: actions/download-artifact@v4
with:
name: new-tag-artifact
path: .
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 24
# cache: "pnpm"
# - uses: pnpm/action-setup@v4
# name: Install pnpm
# with:
# run_install: false
- name: Install dependencies
run: npm ci
# - name: Build
# run: npm run build
- name: Prepare Dockerfile in a temporary directory
run: |
# Create a temporary directory outside the build context
mkdir -p /tmp/docker-build
# Copy the base Dockerfile to the temporary location
cp node_modules/@browserless.io/browserless/docker/sdk/Dockerfile /tmp/docker-build/Dockerfile
# Perform all modifications on the temporary Dockerfile
sed -i '/COPY src src/a COPY static static' /tmp/docker-build/Dockerfile
sed -i '/COPY static static/a COPY start.sh .' /tmp/docker-build/Dockerfile
sed -i '/COPY start.sh .*/a RUN chmod +x ./start.sh' /tmp/docker-build/Dockerfile
sed -i 's|RUN npm install|RUN npm ci|' /tmp/docker-build/Dockerfile
sed -i 's|CMD \["npm", "start"\]|CMD \["./start.sh"\]|' /tmp/docker-build/Dockerfile
- name: Determine Docker tags
id: docker_tags
run: |
if [[ -f new_tag.txt ]]; then
TAG=$(cat new_tag.txt)
echo "tags=ghcr.io/oudyworks/browserless:$TAG,ghcr.io/oudyworks/browserless:latest" >> $GITHUB_OUTPUT
else
echo "tags=ghcr.io/oudyworks/browserless:latest" >> $GITHUB_OUTPUT
fi
- name: Publish the latest Multi image
uses: docker/build-push-action@v5
with:
build-args: |
VERSION=latest
FROM=ghcr.io/browserless/multi:latest
builder: ${{ steps.buildx.outputs.name }}
# Use the Dockerfile from the temporary location
file: /tmp/docker-build/Dockerfile
tags: ${{ steps.docker_tags.outputs.tags }}
# The context is still the clean project root
context: .
push: true
platforms: |
linux/amd64
linux/arm64
provenance: false
sbom: false
# Enable build cache for faster builds and better layer reuse
cache-from: type=registry,ref=ghcr.io/oudyworks/browserless:buildcache
cache-to: type=registry,ref=ghcr.io/oudyworks/browserless:buildcache,mode=max
# - uses: actions/delete-package-versions@v5
# with:
# package-name: 'browserless'
# package-type: 'container'
# delete-only-untagged-versions: 'true'