[CI] Deploy preview environments #4
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "[UI] Handle previews on PR" | |
on: | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
- reopened | |
- closed | |
paths: | |
- "opendata.swiss/ui/**" # Only trigger if files in the ui directory change | |
- ".github/workflows/previews-ods-ui.yaml" # Trigger also if this workflow file is changed | |
- ".github/workflows/docker-ods-ui.yaml" # Trigger also if the docker workflow file is changed | |
jobs: | |
preview: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v5 | |
- name: Set up kubectl | |
uses: azure/setup-kubectl@v4 | |
with: | |
version: v1.33.0 | |
- name: Set up Kustomize | |
uses: imranismail/setup-kustomize@v2 | |
- name: Configure some variables | |
id: vars | |
run: | | |
echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}" >> $GITHUB_OUTPUT | |
- name: Configure cluster context | |
run: | | |
kubectl config set-cluster default "--server=${K8S_API_URL}" --insecure-skip-tls-verify=true | |
kubectl config set-credentials default "--token=${K8S_TOKEN}" | |
kubectl config set-context default --cluster=default --namespace=piveau-previews --user=default | |
kubectl config use-context default | |
env: | |
K8S_API_URL: ${{ secrets.K8S_API_URL }} | |
K8S_TOKEN: ${{ secrets.K8S_TOKEN }} | |
- name: Generate manifests | |
working-directory: ./opendata.swiss/ui/k8s | |
run: | | |
kustomize edit set nameprefix "${{ steps.vars.outputs.branch }}-" | |
kustomize edit add patch \ | |
--group networking.k8s.io \ | |
--version v1 \ | |
--kind Ingress \ | |
--name piveau-ui \ | |
--patch '[ | |
{"op": "replace", "path": "/spec/tls/0/secretName", "value": "${{ steps.vars.outputs.branch }}-prev-tls"}, | |
{"op": "replace", "path": "/spec/tls/0/hosts/0", "value": "${{ steps.vars.outputs.branch }}.piveau-ln-preview.zazukoians.org"}, | |
{"op": "replace", "path": "/spec/rules/0/host", "value": "${{ steps.vars.outputs.branch }}.piveau-ln-preview.zazukoians.org"} | |
]' | |
kustomize edit set image "ghcr.io/opendata-swiss/ods-ui=ghcr.io/opendata-swiss/ods-ui:sha-${{ steps.vars.outputs.short_sha }}" | |
kustomize edit set label "app.kubernetes.io/instance:${{ steps.vars.outputs.branch }}" | |
kustomize build | tee manifest.yaml | |
- name: Apply manifests | |
working-directory: ./opendata.swiss/ui/k8s | |
if: github.event.action != 'closed' | |
run: | | |
kubectl apply -f manifest.yaml | |
- name: Delete manifests | |
working-directory: ./opendata.swiss/ui/k8s | |
if: github.event.action == 'closed' | |
continue-on-error: true | |
run: | | |
kubectl delete -f manifest.yaml |