From 65aca1985c6edb7f8aa50c2255b97195a5803e39 Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Mon, 26 Aug 2024 15:20:34 +0300 Subject: [PATCH 1/9] feat: set review apps as stale after 5 days --- .controlplane/controlplane.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.controlplane/controlplane.yml b/.controlplane/controlplane.yml index af198fba..9b2987c6 100644 --- a/.controlplane/controlplane.yml +++ b/.controlplane/controlplane.yml @@ -71,3 +71,4 @@ apps: - rails # match_if_app_name_starts_with is used to identify these "qa" apps. match_if_app_name_starts_with: true + stale_app_image_deployed_days: 5 # If the app is older than 5 days, the nightly automations will clean stale apps. From cbb9400607bdb5f1b5d209cd622f298f5657197e Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Mon, 26 Aug 2024 15:37:13 +0300 Subject: [PATCH 2/9] refactor: move common env setup to a different file --- .../actions/common-ruby-cpl-setup/action.yml | 25 +++++++++++++++++++ .../deploy-to-control-plane/action.yml | 19 ++------------ 2 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 .github/actions/common-ruby-cpl-setup/action.yml diff --git a/.github/actions/common-ruby-cpl-setup/action.yml b/.github/actions/common-ruby-cpl-setup/action.yml new file mode 100644 index 00000000..48a5d269 --- /dev/null +++ b/.github/actions/common-ruby-cpl-setup/action.yml @@ -0,0 +1,25 @@ +# Control Plane GitHub Action + +name: 'Setup Environment' +description: 'Sets up Ruby, installs Control Plane CLI, cpflow gem, and sets up the default profile' + +runs: + using: 'composite' + steps: + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.3.3' + + - name: Install Control Plane CLI and cpflow gem + shell: bash + run: | + sudo npm install -g @controlplane/cli@3.1.0 + cpln --version + gem install cpflow -v 4.0.0 + cpflow --version + + - name: cpln profile + shell: bash + run: | + cpln profile update default diff --git a/.github/actions/deploy-to-control-plane/action.yml b/.github/actions/deploy-to-control-plane/action.yml index 7105204c..43a9eb97 100644 --- a/.github/actions/deploy-to-control-plane/action.yml +++ b/.github/actions/deploy-to-control-plane/action.yml @@ -16,29 +16,14 @@ inputs: runs: using: 'composite' steps: - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.3.3' # Specify your Ruby version here - - - name: Install Control Plane CLI - shell: bash - run: | - sudo npm install -g @controlplane/cli@3.1.0 - cpln --version - gem install cpflow -v 4.0.0 - cpflow --version + - name: Setup Environment + uses: ./.github/actions/setup-environment - name: Set Short SHA id: vars shell: bash run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" - - name: cpln profile - shell: bash - run: | - cpln profile update default - # Caching step - uses: actions/cache@v2 with: From 6069e93d38bc65090e6c3a586d621f5e423552fe Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Mon, 26 Aug 2024 15:38:02 +0300 Subject: [PATCH 3/9] feat: nightly github action to remove stale apps and images --- .../nightly-remove-stale-review-apps.yml | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/nightly-remove-stale-review-apps.yml diff --git a/.github/workflows/nightly-remove-stale-review-apps.yml b/.github/workflows/nightly-remove-stale-review-apps.yml new file mode 100644 index 00000000..d80d21f4 --- /dev/null +++ b/.github/workflows/nightly-remove-stale-review-apps.yml @@ -0,0 +1,24 @@ +name: Nightly Remove Stale Review Apps and Images + +on: + schedule: + - cron: '0 0 * * *' + +jobs: + remove-stale-review-apps: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Environment + uses: ./.github/actions/setup-environment + + - name: Run cleanup-stale-apps script + run: | + cpflow cleanup-stale-apps -a qa-react-webpack-rails-tutorial -y + + - name: Run cleanup-images script + run: | + cpflow cleanup-images -a qa-react-webpack-rails-tutorial -y From b2008f8cddf0f3c935f12cbfd532d787b9a30215 Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Mon, 26 Aug 2024 15:41:09 +0300 Subject: [PATCH 4/9] fix: rename folder --- .../{common-ruby-cpl-setup => setup-environment}/action.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/actions/{common-ruby-cpl-setup => setup-environment}/action.yml (100%) diff --git a/.github/actions/common-ruby-cpl-setup/action.yml b/.github/actions/setup-environment/action.yml similarity index 100% rename from .github/actions/common-ruby-cpl-setup/action.yml rename to .github/actions/setup-environment/action.yml From 8ffe6a7aa771d3342fd519193d3bd8259447b3fe Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Wed, 2 Oct 2024 14:27:15 +0300 Subject: [PATCH 5/9] feat: allow manual triggers of removing stale review apps --- .github/workflows/nightly-remove-stale-review-apps.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/nightly-remove-stale-review-apps.yml b/.github/workflows/nightly-remove-stale-review-apps.yml index d80d21f4..24b4c178 100644 --- a/.github/workflows/nightly-remove-stale-review-apps.yml +++ b/.github/workflows/nightly-remove-stale-review-apps.yml @@ -1,6 +1,8 @@ name: Nightly Remove Stale Review Apps and Images on: + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: schedule: - cron: '0 0 * * *' From c84fc121fa8e13dfa2b32a4061d25edd2724354d Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Wed, 2 Oct 2024 14:27:34 +0300 Subject: [PATCH 6/9] feat: temporarily allow running workflow on pull requests events to debug --- .github/workflows/nightly-remove-stale-review-apps.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/nightly-remove-stale-review-apps.yml b/.github/workflows/nightly-remove-stale-review-apps.yml index 24b4c178..bf54e440 100644 --- a/.github/workflows/nightly-remove-stale-review-apps.yml +++ b/.github/workflows/nightly-remove-stale-review-apps.yml @@ -3,6 +3,9 @@ name: Nightly Remove Stale Review Apps and Images on: # Allows you to run this workflow manually from the Actions tab workflow_dispatch: + pull_request: + branches: + - master schedule: - cron: '0 0 * * *' From 759ea386e55d3a80302800ef0008cd53679aeb75 Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Wed, 2 Oct 2024 14:30:19 +0300 Subject: [PATCH 7/9] feat: add CPLN_TOKEN, CPLN_ORG --- .github/workflows/nightly-remove-stale-review-apps.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/nightly-remove-stale-review-apps.yml b/.github/workflows/nightly-remove-stale-review-apps.yml index bf54e440..45fc95d0 100644 --- a/.github/workflows/nightly-remove-stale-review-apps.yml +++ b/.github/workflows/nightly-remove-stale-review-apps.yml @@ -9,6 +9,10 @@ on: schedule: - cron: '0 0 * * *' +env: + CPLN_ORG: ${{secrets.CPLN_ORG_STAGING}} + CPLN_TOKEN: ${{secrets.CPLN_TOKEN_STAGING}} + jobs: remove-stale-review-apps: runs-on: ubuntu-latest From 141eda8133b1cecbca8dcec2a84cb43d337bffcb Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Wed, 2 Oct 2024 14:32:40 +0300 Subject: [PATCH 8/9] feat: add image_retention_days: 5 --- .controlplane/controlplane.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.controlplane/controlplane.yml b/.controlplane/controlplane.yml index 9b2987c6..53f68730 100644 --- a/.controlplane/controlplane.yml +++ b/.controlplane/controlplane.yml @@ -71,4 +71,5 @@ apps: - rails # match_if_app_name_starts_with is used to identify these "qa" apps. match_if_app_name_starts_with: true + image_retention_days: 5 stale_app_image_deployed_days: 5 # If the app is older than 5 days, the nightly automations will clean stale apps. From 72f245e6d4b7e89a3a1d1f93c21fa5b0df97dc5e Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Wed, 2 Oct 2024 14:35:06 +0300 Subject: [PATCH 9/9] feat: remove triggering stale-apps removal on PR events --- .github/workflows/nightly-remove-stale-review-apps.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/nightly-remove-stale-review-apps.yml b/.github/workflows/nightly-remove-stale-review-apps.yml index 45fc95d0..9f3985ba 100644 --- a/.github/workflows/nightly-remove-stale-review-apps.yml +++ b/.github/workflows/nightly-remove-stale-review-apps.yml @@ -3,9 +3,6 @@ name: Nightly Remove Stale Review Apps and Images on: # Allows you to run this workflow manually from the Actions tab workflow_dispatch: - pull_request: - branches: - - master schedule: - cron: '0 0 * * *'