-
Notifications
You must be signed in to change notification settings - Fork 2
170 lines (167 loc) · 5.75 KB
/
ci_workflow.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: From Monolith to K8s (Github Actions)
on: [ push ]
env:
OWNER: salaboy
GH_PAGES_BRANCH_NAME: gh-pages
permissions:
packages: write
jobs:
setup:
runs-on: ubuntu-20.04
steps:
- name: Info
run: echo "Building ${{ github.repository }} application, branch/tag ${{ github.ref_name}}"
- name: From Monolith to K8S CI
id: fmtok8s_ci
uses: salaboy/fmtok8s-ci@main
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_branch: main
- name: Set up Docker Meta
id: docker_meta
uses: docker/metadata-action@v3
with:
images: |
ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr,
type=semver,pattern={{raw}}
- name: Docker Meta Output
run: echo "Docker meta tags ${{ steps.docker_meta.outputs.tags }}"
outputs:
docker_tags: ${{ steps.docker_meta.outputs.tags }}
docker_labels: ${{ steps.docker_meta.outputs.labels }}
execute_helm_publish: ${{ steps.fmtok8s_ci.outputs.execute_helm_publish }}
execute_docker_publish: ${{ steps.fmtok8s_ci.outputs.execute_docker_publish }}
execute_native_publish: ${{ steps.fmtok8s_ci.outputs.execute_native_publish }}
version_to_use: ${{ steps.fmtok8s_ci.outputs.version_to_use }}
build:
needs: [ setup ]
runs-on: ubuntu-20.04
services:
# Label used to access the service container
postgresql:
# Docker Hub image
image: postgres
# Set health checks to wait until redis has started
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps port 5432 on service container to the host
- 5432:5432
steps:
- name: Checkout and Set up JDK 17 Temurin
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: 17
distribution: temurin
cache: 'maven'
- name: Build application
run: mvn package
env:
SPRING_R2DBC_URL: "r2dbc:postgresql://localhost:5432/postgres"
SPRING_R2DBC_PASSWORD: "postgres"
- name: Upload app.jar
uses: actions/upload-artifact@v3
with:
name: app-jar
path: target/app.jar
labels: ${{ needs.setup.outputs.docker_labels }}
publish:
needs: [ setup, build ]
runs-on: ubuntu-20.04
if: ${{ needs.setup.outputs.execute_docker_publish == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download app.jar from build job
uses: actions/download-artifact@v3
with:
name: app-jar
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Set up app.jar
run: mkdir target && mv app.jar target/app.jar
- name: Login to Github Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ env.OWNER }}
password: ${{ secrets.PACKAGE_TOKEN }}
- name: Build and Push Docker Image
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ghcr.io/${{ github.repository }}:${{ needs.setup.outputs.version_to_use }}
labels: ${{ needs.setup.outputs.docker_labels }}
build_publish_native:
runs-on: ubuntu-20.04
needs: [ setup, build ]
if: ${{ needs.setup.outputs.execute_native_publish == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up GraalVM 22.1.0
uses: graalvm/setup-graalvm@v1
with:
version: '22.1.0'
java-version: '17'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build native image
run: |
mvn -DskipTests clean spring-boot:build-image \
-Dspring-boot.build-image.imageName=ghcr.io/${{ github.repository}}:${{ needs.setup.outputs.version_to_use }}-native
- name: Login to Github Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ env.OWNER }}
password: ${{ secrets.PACKAGE_TOKEN }}
- name: Publish native image
run: docker push ghcr.io/${{ github.repository}}:${{ needs.setup.outputs.version_to_use }}-native
publish_chart:
runs-on: ubuntu-20.04
needs: [ setup, build ]
if: ${{ needs.setup.outputs.execute_helm_publish == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Change Chart.yml
uses: fjogeleit/yaml-update-action@main
with:
valueFile: 'helm/fmtok8s-c4p-service/Chart.yaml'
propertyPath: 'version'
value: '${{ needs.setup.outputs.version_to_use }}'
commitChange: false
updateFile: true
- name: Change values.yml
uses: fjogeleit/yaml-update-action@main
with:
valueFile: 'helm/fmtok8s-c4p-service/values.yaml'
propertyPath: 'image.tag'
value: '${{ needs.setup.outputs.version_to_use }}-native'
commitChange: false
updateFile: true
- name: Release Helm Chart
uses: stefanprodan/helm-gh-pages@master
with:
charts_dir: helm
token: ${{ secrets.PACKAGE_TOKEN }}
repository: helm
branch: ${{ env.GH_PAGES_BRANCH_NAME }}
owner: ${{ env.OWNER }}