Skip to content

Commit

Permalink
[FEATURE]: Nightly clean review apps and images (#603)
Browse files Browse the repository at this point in the history
* feat: set review apps as stale after 5 days

* refactor: move common env setup to a different file

* feat: nightly github action to remove stale apps and images

* fix: rename folder

* feat: allow manual triggers of removing stale review apps

* feat: temporarily allow running workflow on pull requests events to debug

* feat: add CPLN_TOKEN, CPLN_ORG

* feat: add image_retention_days: 5

* feat: remove triggering stale-apps removal on PR events
  • Loading branch information
rameziophobia authored Oct 2, 2024
1 parent d8b1e93 commit b751afe
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .controlplane/controlplane.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +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.
19 changes: 2 additions & 17 deletions .github/actions/deploy-to-control-plane/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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:
Expand Down
25 changes: 25 additions & 0 deletions .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
cpln --version
gem install cpflow -v 4.0.0
cpflow --version
- name: cpln profile
shell: bash
run: |
cpln profile update default
30 changes: 30 additions & 0 deletions .github/workflows/nightly-remove-stale-review-apps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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 * * *'

env:
CPLN_ORG: ${{secrets.CPLN_ORG_STAGING}}
CPLN_TOKEN: ${{secrets.CPLN_TOKEN_STAGING}}

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

0 comments on commit b751afe

Please sign in to comment.