Skip to content

Build Node.js

Build Node.js #6

Workflow file for this run

name: Build Node.js
on:
workflow_dispatch:
schedule:
- cron: "0 0 1 * *"
push:
branches:
- main
- develop
paths:
- 'nodejs/**'
- '.github/workflows/nodejs.yml'
release:
types: [published]
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
jobs:
build:
name: "nodejs:${{ matrix.version }}"
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
version:
- "20"
- "22"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set lowercase repository owner
id: owner
run: |
echo "value=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
- name: Check if Dockerfile exists
id: check
run: |
if [ -f "./nodejs/${{ matrix.version }}/Dockerfile" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Set up QEMU
if: steps.check.outputs.exists == 'true'
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: steps.check.outputs.exists == 'true'
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
if: steps.check.outputs.exists == 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate tags
if: steps.check.outputs.exists == 'true'
id: tags
run: |
OWNER="${{ steps.owner.outputs.value }}"
VERSION="${{ matrix.version }}"
TAGS="${{ env.REGISTRY }}/$OWNER/nodejs:nodejs_$VERSION"
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
TAGS="$TAGS,${{ env.REGISTRY }}/$OWNER/nodejs:latest"
elif [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then
TAGS="$TAGS,${{ env.REGISTRY }}/$OWNER/nodejs:nodejs_$VERSION-dev"
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
REL_TAG="${{ github.ref_name }}"
TAGS="$TAGS,${{ env.REGISTRY }}/$OWNER/nodejs:nodejs_$VERSION-$REL_TAG"
fi
echo "tags=$TAGS" >> $GITHUB_OUTPUT
- name: Build and push
if: steps.check.outputs.exists == 'true'
uses: docker/build-push-action@v6
with:
context: ./nodejs
file: ./nodejs/${{ matrix.version }}/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.tags.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max