1+ name : CICD
2+
3+ env :
4+ # 🖊️ EDIT your repository secrets to log into your OpenShift cluster and set up the context.
5+ # See https://github.com/redhat-actions/oc-login#readme for how to retrieve these values.
6+ # To get a permanent token, refer to https://github.com/redhat-actions/oc-login/wiki/Using-a-Service-Account-for-GitHub-Actions
7+ OPENSHIFT_SERVER : ${{ secrets.OPENSHIFT_SERVER }}
8+ OPENSHIFT_TOKEN : ${{ secrets.OPENSHIFT_TOKEN }}
9+ # 🖊️ EDIT to set the kube context's namespace after login. Leave blank to use your user's default namespace.
10+ OPENSHIFT_NAMESPACE : exhort
11+ # 🖊️ EDIT to set the deployemnt resource data for image update.
12+ OPENSHIFT_DEPLOYMENT_NAME : exhort-dev
13+ OPENSHIFT_CONTAINER_NAME : exhort
14+ # 🖊️ EDIT to change the image registry settings.
15+ # Registries such as GHCR, Quay.io, and Docker Hub are supported.
16+ IMAGE_REGISTRY : quay.io/ecosystem-appeng
17+ IMAGE_NAME : exhort
18+ IMAGE_TAGS : latest
19+ IMAGE_REGISTRY_USER : ${{ secrets.REGISTRY_USER }}
20+ IMAGE_REGISTRY_PASSWORD : ${{ secrets.REGISTRY_PASSWORD }}
21+ # 🖊️ EDIT to change Dockerfile.
22+ DOCKERFILE_PATH : ./src/main/docker/Dockerfile.native-micro
23+
24+ on :
25+ push :
26+ branches :
27+ - main
28+ tags :
29+ - ' *'
30+
31+ jobs :
32+ build_and_push_image :
33+ runs-on : ubuntu-latest
34+
35+ if : github.repository == 'RHEcosystemAppEng/exhort'
36+
37+ outputs :
38+ digest : ${{ steps.push-to-registry.outputs.digest }}
39+
40+ steps :
41+ - name : Checkout Repository
42+ uses : actions/checkout@v3
43+
44+ - name : Setup JDK
45+ uses : actions/setup-java@v3
46+ with :
47+ distribution : ' temurin'
48+ java-version : ' 17'
49+ cache : ' maven'
50+
51+ - name : Build Package with Maven
52+ run : mvn package -Pnative
53+
54+ - name : Build Image With buildah
55+ id : build-image
56+ uses : redhat-actions/buildah-build@v2
57+ with :
58+ image : ${{ env.IMAGE_NAME }}
59+ tags : ${{ env.IMAGE_TAGS }}
60+ dockerfiles : |
61+ ${{ env.DOCKERFILE_PATH }}
62+
63+ - name : Push Image To Registry
64+ id : push-to-registry
65+ uses : redhat-actions/push-to-registry@v2
66+ with :
67+ image : ${{ steps.build-image.outputs.image }}
68+ tags : ${{ steps.build-image.outputs.tags }}
69+ registry : ${{ env.IMAGE_REGISTRY }}
70+ username : ${{ env.IMAGE_REGISTRY_USER }}
71+ password : ${{ env.IMAGE_REGISTRY_PASSWORD }}
72+
73+ deploy_to_openshift :
74+ needs : build_and_push_image
75+ runs-on : ubuntu-latest
76+
77+ steps :
78+ - name : Install oc
79+ uses : redhat-actions/openshift-tools-installer@v1
80+ with :
81+ oc : 4
82+
83+ - name : Log In To OpenShift
84+ uses : redhat-actions/oc-login@v1
85+ with :
86+ openshift_server_url : ${{ env.OPENSHIFT_SERVER }}
87+ openshift_token : ${{ env.OPENSHIFT_TOKEN }}
88+ insecure_skip_tls_verify : true
89+ namespace : ${{ env.OPENSHIFT_NAMESPACE }}
90+
91+ - name : Patch Image
92+ run : |
93+ DEPLOYMENT_PATCH=$(printf '{"spec": {"template": {"spec": {"containers": [{"name": "%s", "image": "%s/%s@%s"}]}}}}' ${{ env.OPENSHIFT_CONTAINER_NAME }} ${{ env.IMAGE_REGISTRY }} ${{ env.IMAGE_NAME }} ${{ needs.build_and_push_image.outputs.digest }})
94+ oc patch deployment ${{ env.OPENSHIFT_DEPLOYMENT_NAME }} -p "${DEPLOYMENT_PATCH}"
0 commit comments