Pruning all but the most recent tags prior to what is deployed in #24
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
name: Prune Images | |
run-name: Pruning all but the most recent ${{ inputs.minTags }} tags prior to what is deployed in ${{ inputs.environment }} | |
on: | |
workflow_dispatch: | |
inputs: | |
environment: | |
type: choice | |
description: "Environment" | |
required: true | |
options: | |
- dev | |
- test | |
- prod | |
default: "test" | |
applications: | |
description: "Comma seperated list of application Image Streams to prune" | |
required: true | |
default: "web-sims, api-sims, queue-consumers-sims, workers-sims" | |
ocjobs: | |
description: "Comma seperated list of job Image Streams to prune" | |
required: true | |
default: "db.migrations" | |
prefix: | |
description: "Branch prefix to restrict pruning to" | |
required: false | |
default: "main" | |
minTags: | |
description: "Minimum number of Tags to keep" | |
required: false | |
default: "10" | |
schedule: | |
- cron: "0 14 * * *" # Runs at 6 AM Pacific every day | |
jobs: | |
prune-images: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set default inputs when triggered via schedule | |
run: | | |
echo "ENVIRONMENT=${{ inputs.environment || 'test' }}" >> $GITHUB_ENV | |
echo "APPLICATIONS=${{ inputs.applications || 'web-sims, api-sims, queue-consumers-sims, workers-sims' }}" >> $GITHUB_ENV | |
echo "OCJOBS=${{ inputs.ocjobs || 'db.migrations' }}" >> $GITHUB_ENV | |
echo "PREFIX=${{ inputs.prefix || 'main' }}" >> $GITHUB_ENV | |
echo "MIN_TAGS=${{ inputs.minTags || '10' }}" >> $GITHUB_ENV | |
- name: Print env | |
run: | | |
echo "Environment: ${ENVIRONMENT}" | |
echo "Applications: ${APPLICATIONS}" | |
echo "Jobs: ${OCJOBS}" | |
echo "Prefix: ${PREFIX}" | |
echo "Minimum Tags: ${MIN_TAGS}" | |
- name: Checkout source code | |
uses: actions/checkout@v4 | |
- name: Login to OpenShift | |
run: | | |
oc login --token=${{ secrets.SA_TOKEN }} --server=${{ vars.OPENSHIFT_CLUSTER_URL }} | |
- name: Prune DC Images | |
run: | | |
pushd devops/scripts | |
./pruneImages.sh \ | |
--license_plate=${{ vars.OPENSHIFT_LICENSE_PLATE }} \ | |
--env=${ENVIRONMENT} \ | |
--apps="${APPLICATIONS}" \ | |
--prefix=${PREFIX} \ | |
--min_tags=${MIN_TAGS} | |
popd | |
- name: Prune Job Images | |
run: | | |
pushd devops/scripts | |
./pruneImages.sh \ | |
--license_plate=${{ vars.OPENSHIFT_LICENSE_PLATE }} \ | |
--env=${ENVIRONMENT} \ | |
--apps="${OCJOBS}" \ | |
--prefix=${PREFIX} \ | |
--min_tags=${MIN_TAGS} \ | |
--type=JOB | |
popd |