-
Notifications
You must be signed in to change notification settings - Fork 1
190 lines (180 loc) · 6.05 KB
/
build-and-publish.yaml
File metadata and controls
190 lines (180 loc) · 6.05 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
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
name: Backstage Techlab Puzzle Build and Publish
permissions:
contents: read
packages: write
id-token: write
pull-requests: write
on:
pull_request:
workflow_dispatch:
push:
branches:
- main
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
HELM_NAME: backstage-techlab-puzzle
TRAINING_VERSION: ${{ github.sha }}
BUILD_VERSION: ${{ github.ref == 'refs/heads/main' && 'latest' || format('pr-{0}', github.event.pull_request.number) }}
DEPLOY_SECRET_VARIABLE_NAME: ${{ github.ref == 'refs/heads/main' && 'KUBECONFIG_PROD_AV2' || 'KUBECONFIG_TEST_AV2' }}
NAMESPACE_NAME: ${{ github.ref == 'refs/heads/main' && 'pitc-cicd-backstage-techlab-prod' || 'pitc-cicd-backstage-techlab-test' }}
PR_ENV_URL: https://backstage-techlab-pr-${{ github.event.pull_request.number }}.ocp.cloudscale.puzzle.ch
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up npm for linting
uses: actions/setup-node@v6
with:
node-version: '23.x'
- name: Cache npm dependencies
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Cache node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-modules-
- name: Lint Markdown
run: npm ci && npm run mdlint
build_push_image:
runs-on: ubuntu-latest
needs: lint
outputs:
digest: ${{ steps.build-push.outputs.digest }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push Docker image
id: build-push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
sbom: true
push: true
provenance: mode=min
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BUILD_VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max
sign_image:
runs-on: ubuntu-latest
needs: build_push_image
outputs:
digest: ${{ needs.build_push_image.outputs.digest }}
steps:
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install cosign
uses: sigstore/cosign-installer@v3.8.2
with:
cosign-release: 'v2.2.4'
- name: Sign Docker image with cosign
env:
TAG: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BUILD_VERSION }}
DIGEST: ${{ needs.build_push_image.outputs.digest }}
run: |
COSIGN_EXPERIMENTAL=1 cosign sign --yes ${TAG}@${DIGEST}
verify_image:
runs-on: ubuntu-latest
needs: sign_image
outputs:
digest: ${{ needs.sign_image.outputs.digest }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
sparse-checkout: |
scripts
sparse-checkout-cone-mode: false
fetch-depth: 0
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install cosign
uses: sigstore/cosign-installer@v3.8.2
with:
cosign-release: 'v2.2.4'
- name: Verify Docker image with cosign
env:
TAG: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BUILD_VERSION }}
DIGEST: ${{ needs.sign_image.outputs.digest }}
run: bash ./scripts/verify_cosign.sh
# deploy:
# runs-on: ubuntu-latest
# needs: verify_image
# env:
# KUBE_CONFIG_PATH: '$HOME/.kube'
# KUBE_CONFIG_FILENAME: 'config'
# steps:
# - name: Checkout Repository
# uses: actions/checkout@v4
# with:
# sparse-checkout: |
# helm-chart
# scripts
# sparse-checkout-cone-mode: false
# fetch-depth: 0
# - name: 'Install Helm'
# uses: azure/setup-helm@v4
# with:
# version: 'latest'
# - name: Install Kubectl
# uses: azure/setup-kubectl@v4
# with:
# version: 'latest'
# - name: Create KUBECONFIG
# env:
# KUBE_CONFIG: ${{ secrets[env.DEPLOY_SECRET_VARIABLE_NAME] }}
# run: bash ./scripts/create_kubeconfig.sh
# - name: Deploy Helm Release
# env:
# HELM_RELEASE: ${{ env.BUILD_VERSION }}
# NAMESPACE: ${{ env.NAMESPACE_NAME }}
# run: bash ./scripts/deploy_helm_release.sh
# - name: Redeploy Deployments
# env:
# HELM_RELEASE: ${{ env.BUILD_VERSION }}
# NAMESPACE: ${{ env.NAMESPACE_NAME }}
# run: bash ./scripts/redeploy_deployment.sh
# comment:
# if: github.ref != 'refs/heads/main'
# runs-on: ubuntu-latest
# needs: verify_image
# steps:
# - name: Comment PR Environments in PR
# uses: marocchino/sticky-pull-request-comment@v2
# with:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# message: |
# 🚀 PR Environment: [Open Deployment](${{ env.PR_ENV_URL }})
# 🏷️ Image Tag: `${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BUILD_VERSION }}`
# 🖋️ Image Digest: `${{ needs.verify_image.outputs.digest }}`