Skip to content

Commit 65e877c

Browse files
authored
cleaner: decrease project lifetime (#444)
1 parent 082d1f2 commit 65e877c

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

.github/actions/cleanup/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ inputs:
1111
description: "Terminate clusters. Actions accept only strings. Please choose 'true'/'false'"
1212
default: "false"
1313
required: false
14+
MAX_PROJECT_LIFETIME:
15+
description: "If CLEAN_ALL is false: Project will be deleted only if it older then MAX_PROJECT_LIFETIME. Recommended more than 2h because of tests"
16+
default: "3"
17+
required: false
1418
runs:
1519
using: 'docker'
1620
image: 'Dockerfile'

.github/actions/cleanup/entrypoint.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#!/bin/bash
22

3-
# For Deleting empty(!) PROJECTs which live more then (9) hours
3+
# For Deleting empty(!) PROJECTs which live more then (3) hours
44
# It deletes all if INPUT_CLEAN_ALL is true
55

6-
MAX_PROJECT_LIFETIME=9 # in hours
76
mongocli config set skip_update_check true
87

98
delete_endpoints_for_project() {
@@ -52,7 +51,7 @@ delete_clusters() {
5251

5352
# delete only old projects (older than 9 hours)
5453
delete_old_project() {
55-
if [[ -z "${count:-}" ]] || [[ ${count:-} == "null" ]] && [[ "$existance_hours" -gt $MAX_PROJECT_LIFETIME ]]; then
54+
if [[ -z "${count:-}" ]] || [[ ${count:-} == "null" ]] && [[ "$existance_hours" -gt $MAX_PROJECT_LIFETIME_INPUT ]]; then
5655
echo "====== Cleaning Project: $id"
5756
delete_endpoints_for_project "$id" "aws"
5857
delete_endpoints_for_project "$id" "azure"

.github/workflows/cleanup-all.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Clean Atlas organization
22
# local run sample:
3-
# echo '{"ref":"HEAD/ref/CLOUDP-smth", "ref_type":"branch", "action":"workflow_dispatch", "inputs": {"clean":"true"} }' > payload.json | act -j cleanup-all -e payload.json
3+
# echo '{"ref":"HEAD/ref/CLOUDP-smth", "ref_type":"branch", "action":"workflow_dispatch", "inputs": {"clean":"true", "timelife": "3"} }' > payload.json | act -j cleanup-all -e payload.json
44

55
on:
66
workflow_dispatch:
@@ -9,6 +9,10 @@ on:
99
description: "Clean all(true) or old empty projects(false)?"
1010
default: "false"
1111
required: true
12+
timelife:
13+
description: "Timelife of project in hours"
14+
default: "3"
15+
required: true
1216

1317
jobs:
1418
cleanup-all:
@@ -17,7 +21,7 @@ jobs:
1721
steps:
1822
- uses: actions/[email protected]
1923

20-
- name: CleanUp empty AtlasProjects older than one day
24+
- name: CleanUp Atlas organization
2125
uses: ./.github/actions/cleanup
2226
env:
2327
MCLI_PUBLIC_API_KEY: ${{ secrets.ATLAS_PUBLIC_KEY }}
@@ -26,3 +30,4 @@ jobs:
2630
MCLI_OPS_MANAGER_URL: "https://cloud-qa.mongodb.com/"
2731
with:
2832
CLEAN_ALL: ${{ github.event.inputs.clean }}
33+
MAX_PROJECT_LIFETIME: ${{ github.event.inputs.timelife }}

0 commit comments

Comments
 (0)