|
| 1 | +name: 'DC: Bulk Delete Registry Images' |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + delete_since_days: |
| 7 | + required: false |
| 8 | + type: string |
| 9 | + description: "Delete images older than the specified number of days and exit gracefully" |
| 10 | + default: '' |
| 11 | + |
| 12 | +env: |
| 13 | + GH_TOKEN: ${{ secrets.GH_TOKEN }} |
| 14 | + |
| 15 | +jobs: |
| 16 | + dc-generate-matrix: |
| 17 | + name: 'Docker Compose: Get Images to Bulk Delete' |
| 18 | + runs-on: ubuntu-latest |
| 19 | + environment: dev |
| 20 | + env: |
| 21 | + ENVIRONMENT_NAME: dev |
| 22 | + DEV_CONTAINER_REGISTRY: ${{ vars.DEV_CONTAINER_REGISTRY }} |
| 23 | + DEV_LOGIN_USERNAME: ${{ secrets.DEV_LOGIN_USERNAME }} |
| 24 | + DEV_LOGIN_PASSWORD: ${{ secrets.DEV_LOGIN_PASSWORD }} |
| 25 | + outputs: |
| 26 | + app_name: ${{ steps.generate-matrix.outputs.app_name }} |
| 27 | + steps: |
| 28 | + # Checkout the repository to the GitHub Actions runner |
| 29 | + - name: Checkout cicd-deployment-scripts |
| 30 | + uses: actions/checkout@v4 |
| 31 | + with: |
| 32 | + repository: 'code-kern-ai/cicd-deployment-scripts' |
| 33 | + |
| 34 | + - name: Generate Matrix |
| 35 | + id: generate-matrix |
| 36 | + run: | |
| 37 | + app_names=$(curl -s -u "${{ env.DEV_LOGIN_USERNAME }}:${{ env.DEV_LOGIN_PASSWORD }}" \ |
| 38 | + https://${{ env.DEV_CONTAINER_REGISTRY }}/v2/_catalog \ |
| 39 | + | jq -c '[.repositories[] | split("/") | .[1]]') |
| 40 | + echo "app_name=$app_names" >> $GITHUB_OUTPUT |
| 41 | +
|
| 42 | + dc-registry-delete-bulk: |
| 43 | + name: 'Docker Compose: Bulk Delete Registry Images' |
| 44 | + runs-on: ubuntu-latest |
| 45 | + needs: dc-generate-matrix |
| 46 | + environment: dev |
| 47 | + env: |
| 48 | + ENVIRONMENT_NAME: dev |
| 49 | + DEV_CONTAINER_REGISTRY: ${{ vars.DEV_CONTAINER_REGISTRY }} |
| 50 | + DEV_LOGIN_USERNAME: ${{ secrets.DEV_LOGIN_USERNAME }} |
| 51 | + DEV_LOGIN_PASSWORD: ${{ secrets.DEV_LOGIN_PASSWORD }} |
| 52 | + strategy: |
| 53 | + matrix: |
| 54 | + app_name: ${{ fromJson(needs.dc-generate-matrix.outputs.app_name) }} |
| 55 | + steps: |
| 56 | + # Checkout the repository to the GitHub Actions runner |
| 57 | + - name: Checkout cicd-deployment-scripts |
| 58 | + uses: actions/checkout@v4 |
| 59 | + with: |
| 60 | + repository: 'code-kern-ai/cicd-deployment-scripts' |
| 61 | + |
| 62 | + - name: Perform Registry Image Deletion |
| 63 | + shell: bash |
| 64 | + run: | |
| 65 | + bash ./dc/registry_delete.sh \ |
| 66 | + -e ${{ env.ENVIRONMENT_NAME }} \ |
| 67 | + -g ${{ github.repository_owner }} \ |
| 68 | + -r ${{ env.DEV_CONTAINER_REGISTRY }} \ |
| 69 | + -a ${{ matrix.app_name }} \ |
| 70 | + -t "" \ |
| 71 | + -u "${{ env.DEV_LOGIN_USERNAME }}:${{ env.DEV_LOGIN_PASSWORD }}" \ |
| 72 | + -d "${{ inputs.delete_since_days }}" |
0 commit comments