Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build-and-push #216

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)"
44 changes: 34 additions & 10 deletions .github/workflows/update-current-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ jobs:
ccache -s
cp node-v$NODE_VERSION/out/Release/node node

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

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

- name: Build
uses: docker/build-push-action@v5
with:
context: .
load: true
tags: ${{ env.IMAGE_NAME }}-${{ needs.check_version.outputs.NODE_VERSION }}

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

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
Expand All @@ -64,18 +80,26 @@ jobs:
${{ env.MAJOR_VERSION }}
current

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

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

- name: Build Image
- name: Build and push Image
uses: docker/build-push-action@v5
with:
context: .
load: true
tags: ${{ env.IMAGE_NAME }}-${{ needs.check_version.outputs.NODE_VERSION }}

- name: Test Image
run: docker run --rm ${{ env.IMAGE_NAME }}-${{ needs.check_version.outputs.NODE_VERSION }} -e "console.log('Hello from Node.js ' + process.version)"
platforms: linux/amd64
push: true
provenance: mode=max
sbom: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}