-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Push image after successful build and test * Use dockerimage workflow for testing PRs
- Loading branch information
Showing
2 changed files
with
42 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
|
@@ -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 | ||
|
@@ -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)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters