-
-
Notifications
You must be signed in to change notification settings - Fork 300
139 lines (126 loc) · 4.1 KB
/
docker-cd.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: Continuous Delivery
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
IMAGE_NAME: ${{ github.repository }}
REGISTRY: ghcr.io
jobs:
build-maven:
runs-on: ubuntu-latest
container:
image: ubuntu:22.04
steps:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y git
- uses: actions/checkout@v4
- name: Setup .git folder
run: |
git config --global --add safe.directory "$(pwd)"
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Build with Maven
working-directory: .
run: mvn -B package -DargLine="--add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED"
build-docker:
runs-on: ubuntu-latest
container:
image: ubuntu:22.04
env:
IMAGE_NAME: ${{ github.repository }}
REGISTRY: ghcr.io
strategy:
fail-fast: false
matrix:
include:
- alias: jre-17
dockerfile: packaging/docker/unix/eclipse-temurin-17-jre/Dockerfile
tags: test
- alias: jre-17-alpine
dockerfile: packaging/docker/unix/eclipse-temurin-17-jre-alpine/Dockerfile
tags: test-alpine
name: "Build Docker image: ${{ matrix.alias }}"
steps:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y git
- uses: actions/checkout@v4
- name: Setup .git folder
run: |
git config --global --add safe.directory "$(pwd)"
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build Docker image
uses: docker/[email protected]
with:
push: false
file: ${{ matrix.dockerfile }}
tags: ${{ matrix.tags }}
labels: ${{ steps.meta.outputs.labels }}
deploy:
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
container:
image: ubuntu:22.04
strategy:
fail-fast: false
matrix:
include:
- alias: jre-17
dockerfile: packaging/docker/unix/eclipse-temurin-17-jre/Dockerfile
tag-prefix: eclipse-temurin-17-jre-
tag-latest: true
extra-tags: ", ghcr.io/${{ github.repository }}:jre-17"
- alias: jre-17-alpine
dockerfile: packaging/docker/unix/eclipse-temurin-17-jre-alpine/Dockerfile
tag-prefix: eclipse-temurin-17-jre-alpine-
tag-latest: false
extra-tags: ", ghcr.io/${{ github.repository }}:alpine, ghcr.io/${{ github.repository }}:jre-17-alpine"
needs:
- build-maven
- build-docker
permissions:
contents: read
packages: write
name: "Deploy Docker Image: ${{ matrix.alias }}"
#TODO: There is slight double build overhead, but we prevent permissions from being exposed too widely
steps:
- uses: actions/checkout@v2
- name: Log in to the Container registry
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=${{ matrix.tag-latest }}
prefix=${{ matrix.tag-prefix }}
suffix=
- name: Build and Deploy Docker image
uses: docker/[email protected]
with:
context: .
file: ${{ matrix.dockerfile }}
push: true
tags: ${{ steps.meta.outputs.tags }} ${{ matrix.extra-tags }}
labels: ${{ steps.meta.outputs.labels }}