Skip to content

Commit 607dbe8

Browse files
committed
ci: listen to pull request events
1 parent defdba4 commit 607dbe8

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

.github/workflows/docker-ods-ui.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ on:
66
- "opendata.swiss/ui/**" # Only trigger if files in the ui directory change
77
- ".github/workflows/docker-ods-ui.yaml" # Trigger also if this workflow file is changed
88

9+
pull_request:
10+
paths:
11+
- "opendata.swiss/ui/**" # Only trigger if files in the ui directory change
12+
- ".github/workflows/docker-ods-ui.yaml" # Trigger also if this workflow file is changed
13+
914
jobs:
1015
docker:
1116
runs-on: ubuntu-latest
@@ -19,7 +24,18 @@ jobs:
1924
- name: Checkout
2025
uses: actions/checkout@v5
2126

27+
- name: Set up kubectl
28+
if: github.event_name == 'pull_request'
29+
uses: azure/setup-kubectl@v4
30+
with:
31+
version: v1.33.0
32+
33+
- name: Set up Kustomize
34+
if: github.event_name == 'pull_request'
35+
uses: imranismail/setup-kustomize@v2
36+
2237
- name: Install Cosign
38+
if: github.event_name != 'pull_request'
2339
uses: sigstore/cosign-installer@v3.9.2
2440

2541
- name: Set up QEMU
@@ -35,6 +51,12 @@ jobs:
3551
username: ${{ github.actor }}
3652
password: ${{ secrets.GITHUB_TOKEN }}
3753

54+
- name: Configure some variables
55+
id: vars
56+
run: |
57+
echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
58+
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}" >> $GITHUB_OUTPUT
59+
3860
- name: Docker meta
3961
id: docker_meta
4062
uses: docker/metadata-action@v5
@@ -60,6 +82,7 @@ jobs:
6082
linux/amd64
6183
6284
- name: Sign the images with GitHub OIDC Token
85+
if: github.event_name != 'pull_request'
6386
env:
6487
DIGEST: ${{ steps.docker_build.outputs.digest }}
6588
TAGS: ${{ steps.docker_meta.outputs.tags }}
@@ -69,3 +92,32 @@ jobs:
6992
images+="${tag}@${DIGEST} "
7093
done
7194
cosign sign --yes ${images}
95+
96+
- name: Configure cluster context
97+
if: github.event_name == 'pull_request'
98+
run: |
99+
kubectl config set-cluster default "--server=${K8S_API_URL}" --insecure-skip-tls-verify=true
100+
kubectl config set-credentials default "--token=${K8S_TOKEN}"
101+
kubectl config set-context default --cluster=default --namespace=piveau-previews --user=default
102+
kubectl config use-context default
103+
104+
- name: Generate manifests
105+
if: github.event_name == 'pull_request'
106+
working-directory: ./opendata.swiss/ui/k8s
107+
run: |
108+
kustomize edit set nameprefix "${{ steps.vars.outputs.branch }}-"
109+
kustomize edit add patch --patch "$(cat <<EOF
110+
apiVersion: networking.k8s.io/v1
111+
kind: Ingress
112+
metadata:
113+
name: piveau-ui
114+
spec:
115+
tls:
116+
- secretName: ${{ steps.vars.outputs.branch }}-prev-tls
117+
hosts:
118+
- ${{ steps.vars.outputs.branch }}.piveau-ln-preview.zazukoians.org
119+
EOF
120+
)"
121+
kustomize edit set image "ghcr.io/opendata-swiss/ods-ui=ghcr.io/opendata-swiss/ods-ui:sha-${{ steps.vars.outputs.short_sha }}"
122+
kustomize edit set label "app.kubernetes.io/instance:${{ steps.vars.outputs.branch }}"
123+
kustomize build | tee manifest.yaml

opendata.swiss/ui/k8s/deployment.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ metadata:
55
spec:
66
template:
77
spec:
8-
imagePullSecrets:
9-
- name: piveau-ui-pull-secret
108
containers:
119
- name: piveau-ui
12-
image: registry.zazuko.com/docker/lindas-next-piveau-js
10+
image: ghcr.io/opendata-swiss/ods-ui
1311
imagePullPolicy: IfNotPresent
1412
ports:
1513
- name: http

0 commit comments

Comments
 (0)