Skip to content

Commit

Permalink
Use dockerimage workflow for testing PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
chorrell committed Jun 17, 2024
1 parent 2d4bc0c commit f9c6d2e
Showing 1 changed file with 8 additions and 85 deletions.
93 changes: 8 additions & 85 deletions .github/workflows/dockerimage.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
name: Docker Image CI
name: Docker Image Testing

on:
push:
branches:
- main
pull_request:
paths:
- "Dockerfile"
- "build.sh"
- ".github/workflows/dockerimage.yml"

pull_request:

env:
IMAGE_NAME: node-minimal
NODE_VERSION: "21.6.2"

jobs:
build:
Expand All @@ -26,19 +21,16 @@ jobs:
- name: ccache
uses: hendrikmuhs/[email protected]

- name: Set MAJOR_VERSION
run: echo "MAJOR_VERSION=$(echo $NODE_VERSION | cut -d'.' -f 1)" >> $GITHUB_ENV

- name: Show MAJOR_VERSION
run: echo $MAJOR_VERSION
- name: Get latest node version
run: echo "LATEST_VERSION=$(curl -fsSLo- --compressed https://nodejs.org/dist/index.json | jq '.[].version' | tr -d '"' | tr -d 'v' | head -1)" >> $GITHUB_ENV

- name: Build Node
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
which gcc
./build.sh -n $NODE_VERSION
./build.sh -n $LATEST_VERSION
ccache -s
cp node-v$NODE_VERSION/out/Release/node node
cp node-v$LATEST_VERSION/out/Release/node node
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -51,76 +43,7 @@ jobs:
with:
context: .
load: true
tags: ${{ env.IMAGE_NAME }}-${{ env.NODE_VERSION }}
tags: ${{ env.IMAGE_NAME }}-${{ env.LATEST_VERSION }}

- name: Test Image
run: docker run --rm ${{ env.IMAGE_NAME }}-${{ env.NODE_VERSION }} -e "console.log('Hello from Node.js ' + process.version)"

- name: Upload Node
uses: actions/upload-artifact@v4
with:
name: ${{ env.IMAGE_NAME }}-${{ env.NODE_VERSION }}
path: node

push:
# Ensure test job passes before pushing image.
needs: build

runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set MAJOR_VERSION
run: echo "MAJOR_VERSION=$(echo $NODE_VERSION | cut -d'.' -f 1)" >> $GITHUB_ENV

- name: Show MAJOR_VERSION
run: echo $MAJOR_VERSION

- name: Download built node
uses: actions/download-artifact@v4
with:
name: ${{ env.IMAGE_NAME }}-${{ env.NODE_VERSION }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
flavor: latest=true
images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}, ghcr.io/chorrell/${{ env.IMAGE_NAME }}
tags: |
${{ env.NODE_VERSION }}
${{ env.MAJOR_VERSION }}
current
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push Image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64
push: true
provenance: mode=max
sbom: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
run: docker run --rm ${{ env.IMAGE_NAME }}-${{ env.LATEST_VERSION }} -e "console.log('Hello from Node.js ' + process.version)"

0 comments on commit f9c6d2e

Please sign in to comment.