-
Notifications
You must be signed in to change notification settings - Fork 3
147 lines (143 loc) · 6.07 KB
/
Copy pathdeploy-docker.yml
File metadata and controls
147 lines (143 loc) · 6.07 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
name: Deploy Docker Images
on:
push:
branches:
# Build Snapshots From Main
- main
- release/*
tags:
# Build Releases From Tags
- v*.*.*
permissions:
contents: read
jobs:
get-version:
environment: deploy
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-version.outputs.version }}
deploy: ${{ steps.determine-deploy.outputs.deploy }}
release: ${{ steps.determine-deploy.outputs.release }}
java-version: ${{ steps.set-constants.outputs.java-version }}
java-distribution: ${{ steps.set-constants.outputs.java-distribution }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Set Constants
id: set-constants
run: |
echo "java-version=17" >> $GITHUB_OUTPUT
echo "java-distribution=temurin" >> $GITHUB_OUTPUT
- name: Set up JDK
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4
with:
java-version: ${{ steps.set-constants.outputs.java-version }}
distribution: ${{ steps.set-constants.outputs.java-distribution }}
cache: maven
- name: Extract Maven project version
run: echo "version=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)" >> $GITHUB_OUTPUT
id: get-version
- name: Determine if Deploy
id: determine-deploy
# We want to build releases from tags matching the correct pattern and matching the pom version.
# We want to build snapshot releases from any push to main.
uses: actions/github-script@00f12e3e20659f42342b1c0226afda7f7c042325 # v6
env:
VERSION: ${{ steps.get-version.outputs.version }}
REF: ${{ github.ref }}
with:
script: |
const versionPattern = /[0-9]+\.[0-9]+\.[0-9]/;
const snapshotPattern = /[0-9]+\.[0-9]+\.[0-9]-SNAPSHOT/;
const REF = process.env.REF;
const VERSION = process.env.VERSION;
if (`refs/tags/v${VERSION}` === REF && versionPattern.test(VERSION)) {
core.setOutput('deploy', true);
core.setOutput('release', true);
} else if (snapshotPattern.test(VERSION)) {
core.setOutput('deploy', true);
core.setOutput('release', false);
} else {
core.setOutput('deploy', false);
core.setOutput('release', false);
}
build-jar:
environment: deploy
runs-on: ubuntu-latest
needs: get-version
outputs:
jar-path: ${{ steps.build.outputs.jar-path }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Set up JDK
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4
with:
java-version: ${{ needs.get-version.outputs.java-version }}
distribution: ${{ needs.get-version.outputs.java-distribution }}
cache: maven
- name: Build JAR for Docker
id: build
run: |
mvn --batch-mode --fail-fast -P assembly package
echo "jar-path=target/zoom-data-fence-jar-with-dependencies.jar" >> $GITHUB_OUTPUT
- name: Upload JAR artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: zoom-data-fence-jar
path: target/zoom-data-fence-jar-with-dependencies.jar
retention-days: 1
deploy-docker:
environment: deploy
runs-on: ubuntu-latest
needs: [get-version, build-jar]
permissions:
contents: read
strategy:
matrix:
variant: [standard, aws-cli]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Download JAR artifact
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
name: zoom-data-fence-jar
path: target/
- name: Docker meta
id: meta
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
with:
images: |
zoomvideo/zoom-data-fence
tags: |
type=raw,value=latest,enable=${{ needs.get-version.outputs.release == 'true' && matrix.variant == 'standard' }}
type=raw,value=v${{ needs.get-version.outputs.version }},enable=${{ matrix.variant == 'standard' }}
type=raw,value=v${{ needs.get-version.outputs.version }}-${{ matrix.variant }},enable=${{ matrix.variant == 'aws-cli' }}
type=raw,value=${{ matrix.variant }},enable=${{ matrix.variant == 'aws-cli' && needs.get-version.outputs.release == 'true' }}
- name: Login to Docker Hub
if: ${{ fromJSON(needs.get-version.outputs.deploy) }}
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3
- name: Build and push
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6
with:
context: .
push: ${{ fromJSON(needs.get-version.outputs.deploy) }}
provenance: mode=max
sbom: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
build-args: |
INSTALL_AWS_CLI=${{ matrix.variant == 'aws-cli' }}
JAR_PATH=target/zoom-data-fence-jar-with-dependencies.jar
- name: Update repo description
uses: peter-evans/dockerhub-description@432a30c9e07499fd01da9f8a49f0faf9e0ca5b77 # v4.0.2
if: ${{ fromJSON(needs.get-version.outputs.deploy) && matrix.variant == 'standard' }}
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: zoomvideo/zoom-data-fence
short-description: ${{ github.event.repository.description }}