-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(preview): add branch preview cleanup workflow (#1023)
* build(preview): cleanup kubernetes resources on preview branch closure * build(preview): remove preview active label
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Cleanup branch preview | ||
on: | ||
pull_request: | ||
types: [closed] | ||
|
||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
ECR_NAME: ${{ secrets.ECR_NAME }} | ||
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }} | ||
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }} | ||
|
||
jobs: | ||
cleanup-preview: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
contents: read | ||
pull-requests: write | ||
if: contains(github.event.pull_request.labels.*.name, 'preview:active') | ||
steps: | ||
- run: | | ||
echo "${KUBE_CERT}" > ca.crt | ||
kubectl config set-cluster ${KUBE_CLUSTER} --certificate-authority=./ca.crt --server=https://${KUBE_CLUSTER} | ||
kubectl config set-credentials deploy-user --token=${KUBE_TOKEN} | ||
kubectl config set-context ${KUBE_CLUSTER} --cluster=${KUBE_CLUSTER} --user=deploy-user --namespace=${KUBE_NAMESPACE} | ||
kubectl config use-context ${KUBE_CLUSTER} | ||
kubectl delete deployment moj-frontend-${{ github.head_ref }} -n ${KUBE_NAMESPACE} | ||
kubectl delete service moj-frontend-service-${{ github.head_ref }} -n ${KUBE_NAMESPACE} | ||
kubectl delete ingress moj-frontend-ingress-${{ github.head_ref }} -n ${KUBE_NAMESPACE} | ||
env: | ||
KUBE_CERT: ${{ secrets.KUBE_CERT }} | ||
KUBE_TOKEN: ${{ secrets.KUBE_TOKEN }} | ||
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }} | ||
- name: Remove preview:active label | ||
run: | | ||
gh pr edit $PRNUM --remove-label "preview:active" | ||
env: | ||
PRNUM: ${{ github.event.number }} |