-
Notifications
You must be signed in to change notification settings - Fork 1
141 lines (123 loc) · 4.17 KB
/
docker-build.yml
File metadata and controls
141 lines (123 loc) · 4.17 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
name: Build and Push Multi-Platform Java Images
on:
workflow_dispatch:
inputs:
push:
description: 'Push images to Docker Hub'
required: false
default: false
type: boolean
java_versions:
description: 'Java versions to build (space-separated, default: 8 11 17 21 25)'
required: false
default: '8 11 17 21 25'
type: string
env:
REGISTRY: docker.io
REPO_NAME: infotechsoft/java
jobs:
setup:
runs-on: ubuntu-latest
outputs:
java_versions: ${{ steps.parse.outputs.java_versions }}
steps:
- name: Parse Java versions
id: parse
run: |
VERSIONS="${{ inputs.java_versions || '8 11 17 21 25' }}"
JSON_ARRAY=$(echo "$VERSIONS" | tr ' ' '\n' | jq -R . | jq -s . | tr -d '\n')
echo "java_versions=$JSON_ARRAY" >> $GITHUB_OUTPUT
build:
needs: setup
runs-on: ubuntu-latest
strategy:
matrix:
java_version: ${{ fromJson(needs.setup.outputs.java_versions) }}
java_dist: [jdk, jre]
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64
- name: Login to Docker Hub
if: inputs.push
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Determine tags
id: tags
run: |
MAJOR_VERSION=${{ matrix.java_version }}
JAVA_DIST=${{ matrix.java_dist }}
if [ "$JAVA_DIST" = "jdk" ]; then
TAGS="${REPO_NAME}:${MAJOR_VERSION},${REPO_NAME}:${MAJOR_VERSION}-jdk,${REPO_NAME}:zulu-${MAJOR_VERSION}-jdk"
else
TAGS="${REPO_NAME}:${MAJOR_VERSION}-jre,${REPO_NAME}:zulu-${MAJOR_VERSION}-jre"
fi
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "base_tag=${REPO_NAME}:${MAJOR_VERSION}" >> $GITHUB_OUTPUT
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ inputs.push }}
tags: ${{ steps.tags.outputs.tags }}
build-args: |
MAJOR_VERSION=${{ matrix.java_version }}
JAVA_VERSION=
JAVA_DIST=${{ matrix.java_dist }}
provenance: true
sbom: true
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Generate CVE report
id: scout
if: inputs.push && matrix.java_dist == 'jdk'
uses: docker/scout-action@v1
with:
command: cves
image: ${{ steps.tags.outputs.base_tag }}
- name: Update CVE reports
if: inputs.push && matrix.java_dist == 'jdk'
run: |
echo "${{ steps.scout.outputs.cves }}" > reports/java-${{ matrix.java_version }}-cves.md
- name: Upload CVE report artifact
if: inputs.push && matrix.java_dist == 'jdk'
uses: actions/upload-artifact@v6
with:
name: cve-reports-java-${{ matrix.java_version }}
path: reports/java-${{ matrix.java_version }}-cves.md
retention-days: 1
commit-reports:
needs: build
runs-on: ubuntu-latest
if: inputs.push
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Download all CVE report artifacts
uses: actions/download-artifact@v7
with:
path: reports
pattern: cve-reports-java-*
merge-multiple: true
- name: Commit all CVE reports
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore: Update CVE reports for all Java versions"
file_pattern: 'reports/*.md'