-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (78 loc) · 3.29 KB
/
destroy-preview.yaml
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
name: Undeploy
on:
pull_request:
types:
- closed
env:
ENVIRONMENT: preview
OPENSHIFT_API: https://api.cloudscale-lpg-2.appuio.cloud:6443
HELM_RELEASE_NAME: portal-pr-${{ github.event.number }}
IMG_TAG: pr-${{ github.event.number }}
NAMESPACE: appuio-control-api-preview
IMAGE_NAME: cloud-portal
jobs:
uninstall:
runs-on: ubuntu-latest
if: ${{ !startsWith(github.head_ref, 'renovate/') }}
environment: preview
steps:
- uses: actions/checkout@v3
- name: Setup helmfile
uses: mamezou-tech/[email protected]
with:
helm-version: v3.11.2
helmfile-version: v0.152.0
install-kubectl: false
additional-helm-plugins: https://github.com/aslafy-z/helm-git --version 0.15.1
- name: Install CLI tools from OpenShift Mirror
uses: redhat-actions/openshift-tools-installer@v1
with:
oc: "4"
- name: Authenticate and set context
uses: redhat-actions/oc-login@v1
with:
openshift_server_url: ${{ env.OPENSHIFT_API }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
namespace: ${{ env.NAMESPACE }}
# We don't have a LE cert yet
insecure_skip_tls_verify: true
- name: Gather deployment status
id: deployment_info
run: |
echo route_host="$(oc -n ${{ env.NAMESPACE }} get route ${{ env.HELM_RELEASE_NAME }} -o jsonpath='{.spec.host}')" >> $GITHUB_OUTPUT
- name: Uninstall app
run: helmfile --namespace ${{ env.NAMESPACE }} --file deployment/helmfile.yaml -e ${{ env.ENVIRONMENT }} destroy --args --wait
env:
HELM_RELEASE_NAME: ${{ env.HELM_RELEASE_NAME }}
IMG_TAG: none
- name: Delete image in registry
run: oc -n ${{ env.NAMESPACE }} delete imagestreamtags ${{ env.IMAGE_NAME }}:${{ env.IMG_TAG }} --ignore-not-found
- name: Remove route URL from Keycloak client
run: .github/keycloak-redirect-url.sh "${{ secrets.KEYCLOAK_USER }}" "${{ secrets.KEYCLOAK_PASSWORD }}" "https://${{ steps.deployment_info.outputs.route_host }}/*" remove
- name: Notify on success
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.number }}
body: |
## ✔️ Preview deployment uninstalled
| | |
|-|-|
**Helm release** | ${{ env.NAMESPACE }}/${{ env.HELM_RELEASE_NAME }}
**Cluster** | ${{ env.OPENSHIFT_API }}
- name: Notify on failure
uses: peter-evans/create-or-update-comment@v3
if: ${{ failure() }}
with:
issue-number: ${{ github.event.number }}
body: |
## ❌ Failed to remove preview deployment
| | |
|-|-|
**Helm release** | ${{ env.NAMESPACE }}/${{ env.HELM_RELEASE_NAME }}
**Cluster** | ${{ env.OPENSHIFT_API }}
Please investigate what went wrong in the GitHub actions logs.
Maintainers can manually remove the deployment by running
```bash
helmfile -n ${{ env.NAMESPACE }} -f deployment/helmfile.yaml -e ${{ env.ENVIRONMENT }} destroy
oc -n ${{ env.NAMESPACE }} delete imagestreamtags ${{ env.IMAGE_NAME }}:${{ env.IMG_TAG }} --ignore-not-found
```