-
Notifications
You must be signed in to change notification settings - Fork 1
117 lines (103 loc) · 3.52 KB
/
container-build.yml
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
name: Build & Publish Container
on:
push:
branches:
- 'main'
tags:
- 'v*.*.*'
paths-ignore:
- 'README.md'
pull_request:
branches:
- 'main'
schedule:
- cron: '31 22 * * *'
workflow_dispatch:
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
# BUILDKIT_PROGRESS: plain
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Validate Dockerfile
if: ${{ false }}
uses: ghe-actions/dockerfile-validator@v5
with:
dockerfile: 'Dockerfile'
lint: 'hadolint'
# Add support for more platforms with QEMU (optional)
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v3
- name: Setup Docker buildx
id: buildx
uses: docker/setup-buildx-action@v3
# with:
# driver-opts: |
# image=moby/buildkit:v0.11.0
- name: Available Platforms
run: echo "::notice title=Available platforms::${{ steps.buildx.outputs.platforms }}"
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push OpenJDK App image
id: openjdk-build
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
build-args: APP_USER=app
target: openjdk
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:openjdk-latest
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push GraalVM native-image
id: native-image-build
uses: docker/build-push-action@v6
with:
build-args: APP_USER=app
target: graalvm-static
push: ${{ github.event_name != 'pull_request' }}
# platforms: linux/amd64,linux/arm64
# push: ${{ startsWith(github.ref, 'refs/tags/') }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nativeimage-latest
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Install cosign
if: startsWith(github.ref, 'refs/tags/')
uses: sigstore/cosign-installer@main
with:
cosign-release: 'v1.13.1'
- name: Sign the published Docker image
if: startsWith(github.ref, 'refs/tags/')
env:
COSIGN_EXPERIMENTAL: "true"
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: |
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:openjdk-latest" | xargs -I {} cosign sign {}@${{ steps.openjdk-build.outputs.digest }}
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nativeimage-latest" | xargs -I {} cosign sign {}@${{ steps.native-image-build.outputs.digest }}