Skip to content

DC: Delete Registry Images (Bulk) #5

DC: Delete Registry Images (Bulk)

DC: Delete Registry Images (Bulk) #5

name: 'DC: Delete Registry Images (Bulk)'
on:
workflow_dispatch:
inputs:
delete_since_days:
required: false
type: string
description: "Delete older than (days)"
default: ''
app_name:
required: false
type: string
description: "Application Name"
default: ''
force_delete_repo:
required: false
type: boolean
description: "Force Delete"
default: false
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
jobs:
dc-generate-matrix:
name: 'Docker Compose: Get Images to Bulk Delete'
runs-on: ubuntu-latest
environment: dev
env:
ENVIRONMENT_NAME: dev
DEV_CONTAINER_REGISTRY: ${{ vars.DEV_CONTAINER_REGISTRY }}
DEV_LOGIN_USERNAME: ${{ secrets.DEV_LOGIN_USERNAME }}
DEV_LOGIN_PASSWORD: ${{ secrets.DEV_LOGIN_PASSWORD }}
outputs:
app_name: ${{ steps.generate-matrix.outputs.app_name }}
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout cicd-deployment-scripts
uses: actions/checkout@v4
with:
repository: 'code-kern-ai/cicd-deployment-scripts'
- name: Validate Input
run: |
if [ "${{ github.event.inputs.force_delete_repo }}" = true ] && [ -z "${{ inputs.app_name }}" ]; then
echo "::error::Application Name is required when force deleting repository"
exit 1
fi
- name: Generate Matrix
id: generate-matrix
run: |
if [ "${{ github.event.inputs.force_delete_repo }}" = false ]; then
app_names=$(curl -s -u "${{ env.DEV_LOGIN_USERNAME }}:${{ env.DEV_LOGIN_PASSWORD }}" \
https://${{ env.DEV_CONTAINER_REGISTRY }}/v2/_catalog \
| jq -c '[.repositories[] | split("/") | .[1]]')
else
app_names='["${{ inputs.app_name}}"]'
fi
echo "app_name=$app_names" >> $GITHUB_OUTPUT
dc-registry-delete-bulk:
name: 'Docker Compose: Bulk Delete Registry Images'
runs-on: ubuntu-latest
needs: dc-generate-matrix
environment: dev
env:
ENVIRONMENT_NAME: dev
DEV_CONTAINER_REGISTRY: ${{ vars.DEV_CONTAINER_REGISTRY }}
DEV_LOGIN_USERNAME: ${{ secrets.DEV_LOGIN_USERNAME }}
DEV_LOGIN_PASSWORD: ${{ secrets.DEV_LOGIN_PASSWORD }}
SSH_PRIVATE_KEY: ${{ secrets.DEV_SERVER_SSH_PRIVATE_KEY }}
SSH_USER: ${{ secrets.DEV_SERVER_SSH_USERNAME }}
SSH_HOST: ${{ secrets.DEV_SERVER_SSH_HOST }}
strategy:
matrix:
app_name: ${{ fromJson(needs.dc-generate-matrix.outputs.app_name) }}
continue-on-error: true
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout cicd-deployment-scripts
uses: actions/checkout@v4
with:
repository: 'code-kern-ai/cicd-deployment-scripts'
- name: Perform Registry Image Deletion
shell: bash
run: |
bash ./dc/registry_delete.sh \
-e ${{ env.ENVIRONMENT_NAME }} \
-g ${{ github.repository_owner }} \
-r ${{ env.DEV_CONTAINER_REGISTRY }} \
-a ${{ matrix.app_name }} \
-t "" \
-u "${{ env.DEV_LOGIN_USERNAME }}:${{ env.DEV_LOGIN_PASSWORD }}" \
-d "${{ inputs.delete_since_days }}" \
-p "${{ env.SSH_PRIVATE_KEY }}" \
-s "${{ env.SSH_USER }}" \
-h "${{ env.SSH_HOST }}" \
-f "${{ github.event.inputs.force_delete_repo }}"