-
Notifications
You must be signed in to change notification settings - Fork 1.2k
78 lines (71 loc) · 2.81 KB
/
preview-env-gc.yml
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
name: "Preview environment garbage collection"
on:
workflow_dispatch:
schedule:
- cron: "0 */4 * * *"
jobs:
create-runner:
uses: gitpod-io/gce-github-runner/.github/workflows/create-vm.yml@main
secrets:
runner_token: ${{ secrets.SELF_HOSTED_GITHUB_RUNNER_TOKEN }}
gcp_credentials: ${{ secrets.SELF_HOSTED_GITHUB_RUNNER_GCP_CREDENTIALS }}
stale:
name: "Find stale preview environments"
runs-on: ${{ needs.create-runner.outputs.label }}
needs: [create-runner]
container:
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:aledbf-leeway-pigz-gha.18593
outputs:
names: ${{ steps.set-matrix.outputs.names }}
count: ${{ steps.set-matrix.outputs.count }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Compute matrix
id: set-matrix
shell: bash
env:
PREVIEW_ENV_DEV_SA_KEY: ${{ secrets.GCP_CREDENTIALS }}
run: |
set -euo pipefail
export LEEWAY_WORKSPACE_ROOT="$(pwd)"
export HOME="/home/gitpod"
export PREVIEW_ENV_DEV_SA_KEY_PATH="/home/gitpod/.config/gcloud/preview-environment-dev-sa.json"
# Used by 'previewctl list stale'
export GOOGLE_APPLICATION_CREDENTIALS="/home/gitpod/.config/gcloud/preview-environment-dev-sa.json"
echo "${PREVIEW_ENV_DEV_SA_KEY}" > "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
gcloud auth activate-service-account --key-file "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
leeway run dev/preview/previewctl:install
previewctl get-credentials --gcp-service-account "${PREVIEW_ENV_DEV_SA_KEY_PATH}"
previewctl list stale | jq --null-input --raw-input --compact-output '[inputs | select(length>0)]' > /tmp/stale-json
echo "names=$(cat /tmp/stale-json)" >> $GITHUB_OUTPUT
echo "count=$(jq '. | length' /tmp/stale-json)" >> $GITHUB_OUTPUT
delete:
name: "Delete preview environment"
needs: [stale, create-runner]
runs-on: ${{ needs.create-runner.outputs.label }}
if: ${{ needs.stale.outputs.count > 0 }}
strategy:
fail-fast: false
matrix:
name: ${{ fromJSON(needs.stale.outputs.names) }}
steps:
- uses: actions/checkout@v4
- name: Delete preview environment ${{ matrix.name }}
uses: ./.github/actions/delete-preview
with:
name: ${{ matrix.name }}
sa_key: ${{ secrets.GCP_CREDENTIALS }}
delete-runner:
if: always()
needs:
- create-runner
- stale
- delete
uses: gitpod-io/gce-github-runner/.github/workflows/delete-vm.yml@main
secrets:
gcp_credentials: ${{ secrets.SELF_HOSTED_GITHUB_RUNNER_GCP_CREDENTIALS }}
with:
runner-label: ${{ needs.create-runner.outputs.label }}
machine-zone: ${{ needs.create-runner.outputs.machine-zone }}