-
Notifications
You must be signed in to change notification settings - Fork 0
244 lines (213 loc) · 7.91 KB
/
ci_pipeline.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
name: Test tekst-workflows
on:
push
jobs:
build_maven_pipeline:
- name: Tekst workflow
uses: NationalLibraryOfNorway/tekst-workflows/.github/workflows/build_maven_pipeline@main
with:
ENVIRONMENT: stage
JDK_VERSION: 17
MAVEN_VERSION: 3.9.6
USE_MAVEN_PROXY_SETTINGS: true
secrets:
VAULT_URL: ${{ secrets.VAULT_URL }}
VAULT_SECRET_PATH: kv/team/text/data
VAULT_ROLE_ID: ${{ secrets.VAULT_ROLE_ID }}
VAULT_SECRET_ID: ${{ secrets.VAULT_SECRET_ID }}
#name: CI/CD Pipeline
#
#on:
# push:
# branches:
# - "**"
# tags:
# - "v*.*.*"
# pull_request:
# branches:
# - "main"
#
#env:
# MAVEN_INFO: "--batch-mode -Dmaven.repo.local=.m2/repository -Dbuild.tag=$GITHUB_REF_NAME -Dbuild.commit-id-short=$GITHUB_SHA -Dbuild.commit-id-long=$GITHUB_SHA -Dbuild.pipeline-id=$GITHUB_RUN_ID"
#
#jobs:
# build-and-test:
# name: Build and Test
# runs-on: [self-hosted-linux]
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
#
# - name: Set up JDK 17
# uses: actions/setup-java@v4
# with:
# java-version: '17'
# distribution: 'temurin'
#
# - name: Cache Maven packages
# uses: actions/cache@v4
# with:
# path: ~/.m2
# key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
# restore-keys: ${{ runner.os }}-m2
#
# - name: Install Maven
# run: |
# sudo apt-get update -y
# sudo apt-get install wget -y
# wget https://downloads.apache.org/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz
# tar xzf apache-maven-3.9.6-bin.tar.gz
# sudo mv apache-maven-3.9.6 /opt/
# sudo ln -s /opt/apache-maven-3.9.6/bin/mvn /usr/local/bin/mvn
# echo "PATH=/opt/apache-maven-3.9.6/bin:$PATH" >> $GITHUB_ENV
# mvn -v
#
# - name: Build and Test
# run: |
# sed -i "s/https_proxy_host/${{ secrets.HTTP_PROXY }}/g" .m2/settings.xml
# sed -i "s/https_proxy_port/${{ secrets.HTTP_PROXY_PORT }}/g" .m2/settings.xml
# sed -i "s/http_proxy_host/${{ secrets.HTTP_PROXY }}/g" .m2/settings.xml
# sed -i "s/http_proxy_port/${{ secrets.HTTP_PROXY_PORT }}/g" .m2/settings.xml
# mvn -e -s .m2/settings.xml ${{ env.MAVEN_INFO }} verify
#
# - name: Upload artifact
# uses: actions/upload-artifact@v4
# with:
# name: bikube.jar
# path: target/bikube.jar
#
# - name: Cache .m2/repository
# uses: actions/cache@v4
# with:
# path: ~/.m2/repository
# key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
# restore-keys: ${{ runner.os }}-m2
#
# build-and-publish-docker-image:
# needs: build-and-test
# if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
# name: Create and push Docker image
# outputs:
# image_version: ${{ steps.meta.outputs.version }}
# runs-on: [self-hosted-linux]
# steps:
# - name: Check out the repo
# uses: actions/checkout@v4
#
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
# with:
# driver: docker
#
# - name: Log in to Harbor
# uses: docker/login-action@v3
# with:
# registry: ${{ secrets.HARBOR_URL }}
# username: ${{ secrets.HARBOR_USERNAME }}
# password: ${{ secrets.HARBOR_PASSWORD }}
#
# - name: Extract metadata (tags, labels) for Docker
# id: meta
# uses: docker/metadata-action@v5
# with:
# images: harbor.nb.no/tekst/bikube
# tags: |
# type=semver,pattern={{version}}
# type=ref,event=branch
# type=ref,event=pr
#
# - name: Download artifact
# uses: actions/download-artifact@v4
# with:
# name: bikube.jar
#
# - name: Build image
# uses: docker/build-push-action@v5
# with:
# push: true
# context: .
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
#
# deploy-to-k8s-stage:
# name: Deploy to kubernetes stage environment
# needs: build-and-publish-docker-image
# if: github.ref == 'refs/heads/main'
# runs-on: [self-hosted-linux]
# environment: stage
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
#
# - name: Import secrets
# id: import-secrets
# uses: hashicorp/vault-action@v3
# with:
# url: ${{ secrets.VAULT_URL }}
# method: approle
# roleId: ${{ secrets.VAULT_ROLE_ID }}
# secretId: ${{ secrets.VAULT_SECRET_ID }}
# secrets: |
# kv/team/text/data/k8s-text-stage *
#
# - name: Setup Kubectl
# uses: azure/setup-kubectl@v4
# with:
# version: 'v1.26.5'
#
# - name: Deploy to stage cluster
# run: |
# echo "Deploying to stage version ${{ needs.build-and-publish-docker-image.outputs.image_version }}"
# sed -i "s/<version>/${{ needs.build-and-publish-docker-image.outputs.image_version }}/g" k8s/stage/bikube.yml
# sed -i "s/<host_url>/${{ steps.import-secrets.outputs.K8S_HOST_URL }}/g" k8s/stage/bikube.yml
# kubectl config set-cluster stagecl --server=${{ steps.import-secrets.outputs.K8S_STAGE_SERVER }}
# kubectl config set clusters.stagecl.certificate-authority-data ${{ steps.import-secrets.outputs.K8S_STAGE_NB_NO_CA }}
# kubectl config set-credentials ${{ steps.import-secrets.outputs.K8S_STAGE_USER }} --token=${{ steps.import-secrets.outputs.K8S_STAGE_NB_NO_TOKEN }}
# kubectl config set-context tekst --cluster=stagecl --user=${{ steps.import-secrets.outputs.K8S_STAGE_USER }} --namespace=tekst-stage
# kubectl config use-context tekst
# kubectl config view
# kubectl version
# kubectl apply -f k8s/stage/bikube.yml
# kubectl rollout restart deploy/bikube
#
# deploy-to-k8s-prod:
# name: Deploy to kubernetes prod environment
# needs: build-and-publish-docker-image
# if: startsWith(github.event.ref, 'refs/tags/v')
# runs-on: [self-hosted-linux]
# environment: prod
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
#
# - name: Import secrets
# id: import-secrets
# uses: hashicorp/vault-action@v3
# with:
# url: ${{ secrets.VAULT_URL }}
# method: approle
# roleId: ${{ secrets.VAULT_ROLE_ID }}
# secretId: ${{ secrets.VAULT_SECRET_ID }}
# secrets: |
# kv/team/text/data/k8s-text-prod *
#
# - name: Setup Kubectl
# uses: azure/setup-kubectl@v4
# with:
# version: 'v1.26.5'
#
# - name: Deploy to prod cluster
# run: |
# echo "Deploying to production version ${{ needs.build-and-publish-docker-image.outputs.image_version }}"
# sed -i "s/<version>/${{ needs.build-and-publish-docker-image.outputs.image_version }}/g" k8s/prod/bikube.yml
# sed -i "s/<host_url>/${{ steps.import-secrets.outputs.K8S_HOST_URL }}/g" k8s/prod/bikube.yml
# sed -i "s/<alt_host_url>/${{ steps.import-secrets.outputs.ALT_HOST_URL }}/g" k8s/prod/bikube.yml
# kubectl config set-cluster prodcl --server=${{ steps.import-secrets.outputs.K8S_PROD_SERVER }}
# kubectl config set clusters.prodcl.certificate-authority-data ${{ steps.import-secrets.outputs.K8S_PROD_NB_NO_CA }}
# kubectl config set-credentials ${{ steps.import-secrets.outputs.K8S_PROD_USER }} --token=${{ steps.import-secrets.outputs.K8S_PROD_NB_NO_TOKEN }}
# kubectl config set-context tekst --cluster=prodcl --user=${{ steps.import-secrets.outputs.K8S_PROD_USER }} --namespace=tekst-prod
# kubectl config use-context tekst
# kubectl config view
# kubectl version
# kubectl apply -f k8s/prod/bikube.yml
# kubectl rollout restart deploy/bikube