Skip to content

Commit ffaadbf

Browse files
committed
Use a GH action to deploy to an OpenShift cluster
1 parent 59d018e commit ffaadbf

File tree

4 files changed

+151
-74
lines changed

4 files changed

+151
-74
lines changed

.github/workflows/deploy.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
paths-ignore:
8+
- '.gitignore'
9+
- 'CODEOWNERS'
10+
- 'LICENSE'
11+
- '*.md'
12+
- '*.adoc'
13+
- '*.txt'
14+
- '.all-contributorsrc'
15+
16+
concurrency:
17+
group: deployment
18+
cancel-in-progress: false
19+
20+
jobs:
21+
deploy:
22+
23+
if: github.repository == 'hibernate/hibernate-github-bot'
24+
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
30+
- name: Set up JDK 21
31+
uses: actions/setup-java@v4
32+
with:
33+
distribution: temurin
34+
java-version: 21
35+
36+
- name: Build
37+
run: ./mvnw -B clean verify
38+
39+
- name: Set up Helm
40+
uses: azure/[email protected]
41+
with:
42+
version: 'v3.13.3'
43+
44+
- name: Log in to OpenShift
45+
uses: redhat-actions/oc-login@v1
46+
with:
47+
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_INFRA_PROD }}
48+
openshift_token: ${{ secrets.OPENSHIFT_TOKEN_INFRA_PROD }}
49+
namespace: ${{ secrets.OPENSHIFT_NAMESPACE_INFRA_PROD }}
50+
51+
- name: Create ImageStream
52+
run: |
53+
oc create imagestream hibernate-github-bot || true
54+
# https://docs.openshift.com/container-platform/4.14/openshift_images/using-imagestreams-with-kube-resources.html
55+
oc set image-lookup hibernate-github-bot
56+
57+
- name: Retrieve OpenShift Container Registry URL
58+
id: oc-registry
59+
run: |
60+
echo -n "OC_REGISTRY_URL=" >> "$GITHUB_OUTPUT"
61+
oc get imagestream -o json | jq -r '.items[0].status.publicDockerImageRepository' | awk -F"[/]" '{print $1}' >> "$GITHUB_OUTPUT"
62+
63+
- name: Log in to OpenShift Container Registry
64+
uses: docker/login-action@v3
65+
with:
66+
registry: ${{ steps.oc-registry.outputs.OC_REGISTRY_URL }}
67+
username: ignored
68+
password: ${{ secrets.OPENSHIFT_TOKEN_INFRA_PROD }}
69+
# Helm in particular needs semantic versions
70+
# See https://github.com/helm/helm/issues/9342#issuecomment-775269042
71+
# See the parts about pre-release versions in https://semver.org/#semantic-versioning-specification-semver
72+
# Ideally we should use a "+" before the SHA, but that won't work with Quarkus
73+
# See https://github.com/quarkusio/quarkus/blob/da1a782e04b01b2e165d65474163050d497340c1/extensions/container-image/spi/src/main/java/io/quarkus/container/spi/ImageReference.java#L60
74+
- name: Generate app version
75+
id: app-version
76+
run: |
77+
echo "VALUE=1.0.0-$(date -u '+%Y%m%d%H%M%S')-${{ github.sha }}" >> $GITHUB_OUTPUT
78+
79+
- name: Build and push app container image
80+
run: |
81+
./mvnw clean package -DskipTests \
82+
-Drevision="${{ steps.app-version.outputs.value }}" \
83+
-Dquarkus.container-image.build=true \
84+
-Dquarkus.container-image.push=true \
85+
-Dquarkus.container-image.registry="$(oc get imagestream -o json | jq -r '.items[0].status.publicDockerImageRepository' | awk -F"[/]" '{print $1}')" \
86+
-Dquarkus.container-image.group="$(oc project --short)" \
87+
-Dquarkus.container-image.additional-tags=latest
88+
89+
- name: Deploy Helm charts
90+
run: |
91+
helm upgrade --install hibernate-github-bot ./target/helm/openshift/hibernate-github-bot

Jenkinsfile

Lines changed: 0 additions & 67 deletions
This file was deleted.

pom.xml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
4444
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
4545
<glob.version>0.9.0</glob.version>
46+
<quarkus-helm.version>1.2.5</quarkus-helm.version>
4647
<surefire-plugin.version>3.5.1</surefire-plugin.version>
4748
<assertj.version>3.26.0</assertj.version>
4849
</properties>
@@ -78,10 +79,6 @@
7879
<version>${assertj.version}</version>
7980
<scope>test</scope>
8081
</dependency>
81-
<dependency>
82-
<groupId>io.quarkus</groupId>
83-
<artifactId>quarkus-container-image-jib</artifactId>
84-
</dependency>
8582
<dependency>
8683
<groupId>io.quarkus</groupId>
8784
<artifactId>quarkus-info</artifactId>
@@ -112,6 +109,21 @@
112109
<artifactId>glob</artifactId>
113110
<version>${glob.version}</version>
114111
</dependency>
112+
<!-- Deployment: -->
113+
<dependency>
114+
<groupId>io.quarkus</groupId>
115+
<artifactId>quarkus-openshift</artifactId>
116+
</dependency>
117+
<dependency>
118+
<groupId>io.quarkus</groupId>
119+
<artifactId>quarkus-container-image-jib</artifactId>
120+
</dependency>
121+
<dependency>
122+
<groupId>io.quarkiverse.helm</groupId>
123+
<artifactId>quarkus-helm</artifactId>
124+
<version>${quarkus-helm.version}</version>
125+
</dependency>
126+
115127
<dependency>
116128
<groupId>io.quarkiverse.githubapp</groupId>
117129
<artifactId>quarkus-github-app-testing</artifactId>

src/main/resources/application.properties

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ quarkus.qute.content-types."md"=text/markdown
88

99
quarkus.cache.caffeine."glob-cache".maximum-size=200
1010

11-
quarkus.container-image.group=hibernate
12-
quarkus.container-image.registry=quay.io
13-
1411
hibernate-github-bot.jenkins.github-app-id=347853
1512
hibernate-github-bot.develocity.uri=https://ge.hibernate.org/
1613

@@ -25,3 +22,47 @@ quarkus.openapi-generator.gradle_enterprise_2023_4_api_yaml.auth.DevelocityAcces
2522

2623
%dev,test.hibernate-github-bot.dry-run=false
2724
%dev,test.hibernate-github-bot.develocity.access-key=foo
25+
26+
##############
27+
# Deployment configuration:
28+
#
29+
quarkus.container-image.builder=jib
30+
quarkus.openshift.part-of=hibernate-github-bot
31+
# Renew the SSL certificate automatically
32+
# This requires an additional controller to run on the OpenShift cluster (in our case it does).
33+
# See https://github.com/tnozicka/openshift-acme/#enabling-acme-certificates-for-your-object
34+
quarkus.openshift.annotations."kubernetes.io/tls-acme"=true
35+
quarkus.openshift.env.configmaps=hibernate-github-bot-config
36+
quarkus.openshift.env.secrets=hibernate-github-bot-secrets
37+
# Resource requirements
38+
quarkus.openshift.resources.limits.cpu=600m
39+
quarkus.openshift.resources.requests.cpu=400m
40+
quarkus.openshift.resources.limits.memory=300Mi
41+
quarkus.openshift.resources.requests.memory=150Mi
42+
# Add routes:
43+
quarkus.openshift.route.expose=true
44+
quarkus.openshift.route.target-port=http
45+
## Route TLS configuration:
46+
quarkus.openshift.route.tls.termination=edge
47+
quarkus.openshift.route.tls.insecure-edge-termination-policy=Redirect
48+
# Don't use the version in (service) selectors,
49+
# otherwise a rollback to an earlier version (due to failing startup) makes the service unavailable
50+
quarkus.openshift.add-version-to-label-selectors=false
51+
quarkus.helm.values."resources.limits.cpu".paths=(kind == Deployment).spec.template.spec.containers.resources.limits.cpu
52+
quarkus.helm.values."resources.requests.cpu".paths=(kind == Deployment).spec.template.spec.containers.resources.requests.cpu
53+
quarkus.helm.values."resources.limits.memory".paths=(kind == Deployment).spec.template.spec.containers.resources.limits.memory
54+
quarkus.helm.values."resources.requests.memory".paths=(kind == Deployment).spec.template.spec.containers.resources.requests.memory
55+
#
56+
# General Helm config
57+
#
58+
# Don't just add any random system property mentioned in application.properties to values.yaml...
59+
# We don't need it but more importantly it doesn't work (leads to marshalling errors)
60+
# for strings that look like numbers (e.g. 2.11)
61+
quarkus.helm.map-system-properties=false
62+
# Set common k8s labels everywhere:
63+
quarkus.helm.values."version".paths=metadata.labels.'app.kubernetes.io/version',spec.template.metadata.labels.'app.kubernetes.io/version'
64+
quarkus.helm.values."version".property=@.app.version
65+
quarkus.helm.values."version".value=${maven.revision}
66+
quarkus.helm.values."part-of".paths=metadata.labels.'app.kubernetes.io/part-of',spec.template.metadata.labels.'app.kubernetes.io/part-of'
67+
quarkus.helm.values."part-of".property=@.app.name
68+
quarkus.helm.values."part-of".value=hibernate-github-bot

0 commit comments

Comments
 (0)