Skip to content

Commit 8f40c05

Browse files
committed
Fix multiarch build;
improves the Docker build process, GitHub Actions workflow, and plugin dependencies for the Headlamp Kubernetes plugins repository. Signed-off-by: Kirill <[email protected]>
1 parent 639608f commit 8f40c05

File tree

6 files changed

+4936
-4158
lines changed

6 files changed

+4936
-4158
lines changed

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
.git
3+
*.md
4+
tests/
5+
coverage/
6+
.env
7+
*.log

.github/workflows/build-and-publish-image.yml

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,72 @@ name: Build and publish plugin container image
33
on:
44
workflow_dispatch:
55
inputs:
6-
plugin:
7-
description: 'The plugin name (e.g., flux)'
6+
plugins:
7+
description: 'Comma-separated list of plugin names to build (e.g., flux,cert-manager)'
88
required: true
99
type: string
1010
version:
1111
description: 'The plugin version (without a v prefix e.g., 0.1.0) - if not provided, will use version from package.json'
1212
required: false
1313
type: string
14+
architectures:
15+
description: 'Target architectures to build for'
16+
required: true
17+
type: choice
18+
options:
19+
- linux/amd64,linux/arm64
20+
- linux/amd64
21+
- linux/arm64
22+
default: 'linux/amd64,linux/arm64'
1423

1524
env:
1625
REGISTRY: ghcr.io
17-
ORG: headlamp-k8s
18-
PLUGIN: ${{ github.event.inputs.plugin }}
19-
IMAGE_NAME: headlamp-plugin-${{ github.event.inputs.plugin }}
26+
ORG: ${{ github.repository_owner }}
27+
ARCHITECTURES: ${{ github.event.inputs.architectures }}
28+
NODE_VERSION: '20'
29+
ALPINE_VERSION: '3.22.0'
30+
2031
jobs:
32+
setup_matrix:
33+
runs-on: ubuntu-latest
34+
outputs:
35+
matrix: ${{ steps.setup_matrix.outputs.matrix_output }}
36+
steps:
37+
- id: setup_matrix
38+
run: |
39+
echo "Setting up matrix for plugins: ${{ github.event.inputs.plugins }}"
40+
# Convert comma-separated list to JSON array
41+
PLUGINS_ARRAY=$(jq -cR 'split(",")' <<< "${{ github.event.inputs.plugins }}")
42+
echo "Matrix input: $PLUGINS_ARRAY"
43+
echo "matrix_output=$PLUGINS_ARRAY" >> $GITHUB_OUTPUT
44+
2145
build-and-publish:
46+
needs: setup_matrix
2247
runs-on: ubuntu-latest
2348
permissions:
2449
packages: write # needed for publishing the container image
50+
strategy:
51+
matrix:
52+
plugin: ${{ fromJson(needs.setup_matrix.outputs.matrix) }}
2553
steps:
2654
- name: Checkout code
27-
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # 4.1.7
55+
uses: actions/checkout@v4
2856

2957
- name: Verify plugin exists
3058
run: |
31-
if [ ! -d "${{ env.PLUGIN }}" ]; then
32-
echo "::error::Plugin directory '${{ env.PLUGIN }}' does not exist"
59+
if [ ! -d "${{ matrix.plugin }}" ]; then
60+
echo "::error::Plugin directory '${{ matrix.plugin }}' does not exist"
3361
exit 1
3462
fi
35-
echo "Plugin directory '${{ env.PLUGIN }}' verified"
36-
37-
- name: Setup Node.js
38-
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
39-
with:
40-
node-version: '20'
63+
echo "Plugin directory '${{ matrix.plugin }}' verified"
4164
4265
- name: Determine version
4366
id: determine_version
4467
run: |
4568
VERSION="${{ github.event.inputs.version }}"
4669
if [ -z "$VERSION" ]; then
4770
echo "Version not provided, extracting from package.json"
48-
VERSION=$(node -p "require('./${{ env.PLUGIN }}/package.json').version")
71+
VERSION=$(node -p "require('./${{ matrix.plugin }}/package.json').version")
4972
echo "Extracted version: $VERSION"
5073
fi
5174
# Remove leading 'v' if present
@@ -54,37 +77,46 @@ jobs:
5477
IMAGE_TAG_VERSION="v${VERSION}"
5578
echo "VERSION=$VERSION" >> $GITHUB_ENV
5679
echo "IMAGE_TAG_VERSION=$IMAGE_TAG_VERSION" >> $GITHUB_ENV
57-
echo "FULL_IMAGE_NAME=${{ env.REGISTRY }}/${{ env.ORG }}/${{ env.IMAGE_NAME }}" >> $GITHUB_ENV
80+
echo "FULL_IMAGE_NAME=${{ env.REGISTRY }}/${{ env.ORG }}/headlamp-plugin-${{ matrix.plugin }}" >> $GITHUB_ENV
5881
5982
- name: Setup Docker Buildx
60-
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1
83+
uses: docker/setup-buildx-action@v3
84+
85+
- name: Set up QEMU
86+
uses: docker/setup-qemu-action@v3
87+
with:
88+
platforms: ${{ env.ARCHITECTURES }}
6189

6290
- name: Log in to the Container registry
63-
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
91+
uses: docker/login-action@v3
6492
with:
6593
registry: ${{ env.REGISTRY }}
6694
username: ${{ github.actor }}
6795
password: ${{ github.token }}
6896

6997
- name: Build and push Docker image
70-
uses: docker/build-push-action@0a97817b6ade9f46837855d676c4cca3a2471fc9 # v4.2.1
98+
uses: docker/build-push-action@v6
7199
with:
72100
context: .
73101
push: true
74102
pull: true
75-
platforms: linux/amd64,linux/arm64
103+
platforms: ${{ env.ARCHITECTURES }}
76104
tags: ${{ env.FULL_IMAGE_NAME }}:${{ env.IMAGE_TAG_VERSION }},${{ env.FULL_IMAGE_NAME }}:latest
77105
labels: |
78106
org.opencontainers.image.source=${{ github.event.repository.html_url }}
79107
org.opencontainers.image.licenses=Apache-2.0
108+
build-args: |
109+
PLUGIN=${{ matrix.plugin }}
110+
BASE_IMAGE_VERSION=${{ env.NODE_VERSION }}
111+
FINAL_IMAGE_VERSION=${{ env.ALPINE_VERSION }}
80112
provenance: true
81-
build-args: PLUGIN=${{ env.PLUGIN }}
82113
cache-from: type=gha
83114
cache-to: type=gha,mode=max
84115

85116
- name: Summary
86117
run: |
87118
echo "## Container Image Published" >> $GITHUB_STEP_SUMMARY
88-
echo "Plugin: ${{ env.PLUGIN }}" >> $GITHUB_STEP_SUMMARY
119+
echo "Plugin: ${{ matrix.plugin }}" >> $GITHUB_STEP_SUMMARY
89120
echo "Version: ${{ env.VERSION }}" >> $GITHUB_STEP_SUMMARY
90121
echo "Image: ${{ env.FULL_IMAGE_NAME }}:${{ env.IMAGE_TAG_VERSION }}" >> $GITHUB_STEP_SUMMARY
122+
echo "Architectures: ${{ env.ARCHITECTURES }}" >> $GITHUB_STEP_SUMMARY

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# OS
2+
.DS_Store
3+
Thumbnails
4+
5+
# IDE
6+
.vscode/
7+
.idea
8+
*.xml
9+
*.iml
10+
11+
# Node
12+
node_modules/

Dockerfile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# Use the official Node.js 18 image as the base image for building the plugins
2-
FROM node:18@sha256:d0bbfdbad0bff8253e6159dcbee42141db4fc309365d5b8bcfce46ed71569078 AS builder
1+
ARG BASE_IMAGE_VERSION=18
2+
ARG FINAL_IMAGE_VERSION=3.20.3
3+
ARG ENVIRONMENT=production
4+
FROM node:${BASE_IMAGE_VERSION} AS builder
35

46
# Set the working directory inside the container
57
WORKDIR /headlamp-plugins
@@ -22,7 +24,12 @@ COPY ${PLUGIN} /headlamp-plugins/${PLUGIN}
2224
# Install dependencies for the specified plugin
2325
RUN echo "Installing deps for plugin $PLUGIN..."; \
2426
cd /headlamp-plugins/$PLUGIN; \
25-
npm ci
27+
echo "Installing $ENVIRONMENT dependencies..."; \
28+
if [ "$ENVIRONMENT" = "production" ]; then \
29+
npm ci --omit=dev; \
30+
else \
31+
npm ci; \
32+
fi
2633

2734
# Build the specified plugin
2835
RUN echo "Building plugin $PLUGIN..."; \
@@ -34,7 +41,7 @@ RUN echo "Extracting plugin $PLUGIN..."; \
3441
cd /headlamp-plugins/$PLUGIN; \
3542
npx --no-install headlamp-plugin extract . /headlamp-plugins/build/${PLUGIN}
3643

37-
FROM alpine:3.20.3@sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d
44+
FROM alpine:${FINAL_IMAGE_VERSION} AS final
3845

3946
# Create a non-root user and group
4047
RUN addgroup -S headlamp && adduser -S headlamp -G headlamp

0 commit comments

Comments
 (0)