-
Notifications
You must be signed in to change notification settings - Fork 90
93 lines (83 loc) · 3.35 KB
/
build-and-publish-image.yml
File metadata and controls
93 lines (83 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: Build and publish plugin container image
on:
workflow_dispatch:
inputs:
plugin:
description: 'The plugin name (e.g., flux)'
required: true
type: string
version:
description: 'The plugin version (without a v prefix e.g., 0.1.0) - if not provided, will use version from package.json'
required: false
type: string
permissions:
contents: read
env:
REGISTRY: ghcr.io
ORG: headlamp-k8s
PLUGIN: ${{ github.event.inputs.plugin }}
IMAGE_NAME: headlamp-plugin-${{ github.event.inputs.plugin }}
jobs:
build-and-publish:
runs-on: ubuntu-latest
permissions:
packages: write # needed for publishing the container image
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # 4.1.7
- name: Verify plugin exists
run: |
if [ ! -d "${{ env.PLUGIN }}" ]; then
echo "::error::Plugin directory '${{ env.PLUGIN }}' does not exist"
exit 1
fi
echo "Plugin directory '${{ env.PLUGIN }}' verified"
- name: Setup Node.js
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
with:
node-version: '20'
- name: Determine version
id: determine_version
run: |
VERSION="${{ github.event.inputs.version }}"
if [ -z "$VERSION" ]; then
echo "Version not provided, extracting from package.json"
VERSION=$(node -p "require('./${{ env.PLUGIN }}/package.json').version")
echo "Extracted version: $VERSION"
fi
# Remove leading 'v' if present
VERSION="${VERSION#v}"
# Create v-prefixed version for image tags
IMAGE_TAG_VERSION="v${VERSION}"
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "IMAGE_TAG_VERSION=$IMAGE_TAG_VERSION" >> $GITHUB_ENV
echo "FULL_IMAGE_NAME=${{ env.REGISTRY }}/${{ env.ORG }}/${{ env.IMAGE_NAME }}" >> $GITHUB_ENV
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1
- name: Log in to the Container registry
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Build and push Docker image
uses: docker/build-push-action@0a97817b6ade9f46837855d676c4cca3a2471fc9 # v4.2.1
with:
context: .
push: true
pull: true
platforms: linux/amd64,linux/arm64
tags: ${{ env.FULL_IMAGE_NAME }}:${{ env.IMAGE_TAG_VERSION }},${{ env.FULL_IMAGE_NAME }}:latest
labels: |
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.licenses=Apache-2.0
provenance: true
build-args: PLUGIN=${{ env.PLUGIN }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Summary
run: |
echo "## Container Image Published" >> $GITHUB_STEP_SUMMARY
echo "Plugin: ${{ env.PLUGIN }}" >> $GITHUB_STEP_SUMMARY
echo "Version: ${{ env.VERSION }}" >> $GITHUB_STEP_SUMMARY
echo "Image: ${{ env.FULL_IMAGE_NAME }}:${{ env.IMAGE_TAG_VERSION }}" >> $GITHUB_STEP_SUMMARY