-
Notifications
You must be signed in to change notification settings - Fork 1
202 lines (168 loc) · 5.98 KB
/
build.yml
File metadata and controls
202 lines (168 loc) · 5.98 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
name: Build Node Images
on:
push:
branches:
- master
paths:
- 'Dockerfile'
- 'versions/**'
- '.github/workflows/build.yml'
workflow_dispatch:
inputs:
version:
description: 'Specific version to build (e.g., node22-jdk21), or "all"'
required: false
default: 'all'
env:
DOCKER_HUB_IMAGE: ringcentral/node
GHCR_IMAGE: ghcr.io/ringcentral-docker/node
BASE_OS: noble
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Generate build matrix
id: set-matrix
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.version }}" != "all" ]]; then
MATRIX=$(jq -c --arg v "${{ github.event.inputs.version }}" \
'{include: [.versions[] | select(.name == $v)]}' versions/versions.json)
else
MATRIX=$(jq -c '{include: .versions}' versions/versions.json)
fi
echo "matrix=${MATRIX}" >> $GITHUB_OUTPUT
build:
needs: prepare
runs-on: ubuntu-latest
permissions:
security-events: write
packages: write
strategy:
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Docker tags
id: meta
run: |
NODE_VER="${{ matrix.node_version }}"
NODE_MAJ="${{ matrix.node_major }}"
JDK_VER="${{ matrix.jdk_version }}"
IS_LATEST="${{ matrix.is_latest }}"
TAGS=""
for REGISTRY in "${{ env.DOCKER_HUB_IMAGE }}" "${{ env.GHCR_IMAGE }}"; do
# Always add version-specific tags
TAGS="${TAGS}${REGISTRY}:${NODE_VER}-jdk${JDK_VER},"
TAGS="${TAGS}${REGISTRY}:${NODE_MAJ}-jdk${JDK_VER},"
# Add simple tags for latest
if [[ "${IS_LATEST}" == "true" ]]; then
TAGS="${TAGS}${REGISTRY}:${NODE_VER},"
TAGS="${TAGS}${REGISTRY}:${NODE_MAJ},"
TAGS="${TAGS}${REGISTRY}:latest,"
fi
done
echo "tags=${TAGS%,}" >> $GITHUB_OUTPUT
- name: Build and push
id: build
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
build-args: |
NODE_VERSION=${{ matrix.node_version }}
MAVEN_TAG=${{ matrix.maven_tag }}
cache-from: type=gha,scope=${{ matrix.name }}
cache-to: type=gha,mode=max,scope=${{ matrix.name }}
- name: Run Trivy vulnerability scanner
if: steps.build.outcome == 'success'
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.DOCKER_HUB_IMAGE }}:${{ matrix.node_version }}-jdk${{ matrix.jdk_version }}
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v4
if: steps.build.outcome == 'success'
with:
sarif_file: 'trivy-results.sarif'
update-readme:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Generate README from versions.json
run: |
cat > README.md << 'HEADER'
# Node + Maven + JDK Docker Images
Multi-platform Node.js Docker images with Maven and JDK included.
## Supported Platforms
- linux/amd64
- linux/arm64
## Available Images
| Name | Node | JDK | Docker Hub | GitHub Package |
|------|------|-----|------------|----------------|
HEADER
jq -r --arg hub "${{ env.DOCKER_HUB_IMAGE }}" \
--arg ghcr "${{ env.GHCR_IMAGE }}" \
'.versions[] |
"| \(.name) | \(.node_version) | \(.jdk_version) | `\($hub):\(.node_version)-jdk\(.jdk_version)` | `\($ghcr):\(.node_version)-jdk\(.jdk_version)` |"
' versions/versions.json >> README.md
cat >> README.md << 'FOOTER'
## Usage
```bash
docker pull ringcentral/node:22-jdk21
docker run -it ringcentral/node:22-jdk21 node --version
```
## Build Locally
```bash
docker build \
--build-arg NODE_VERSION=22.22.2 \
--build-arg MAVEN_TAG=3.9.15-jdk21.0.10-noble \
-t my-node:22-jdk21 .
```
## License
MIT License
FOOTER
- name: Commit README
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add README.md
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "docs: update README with Docker image info"
git push
fi
- name: Update Docker Hub Description
uses: peter-evans/dockerhub-description@v4
continue-on-error: true
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
repository: ringcentral/node
readme-filepath: ./README.md