From 58a4c01359c71ac987486ce599e69bbffc283259 Mon Sep 17 00:00:00 2001 From: pmacius Date: Fri, 27 Sep 2024 17:35:42 +0200 Subject: [PATCH 01/20] OPSEXP-2784 Add cleanup workflow for pacakges --- .github/workflows/cleanup_images.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/cleanup_images.yml diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml new file mode 100644 index 00000000..73d88d2f --- /dev/null +++ b/.github/workflows/cleanup_images.yml @@ -0,0 +1,21 @@ +name: Cleanup Docker images on ghcr.io + +on: + pull_request: + branches: + - main + +jobs: + cleanup: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: List all packages + id: list-targets + uses: docker/bake-action/subaction/list-targets@a4d7f0b5b91c14a296d792d4ec53a9db17f02e67 # v5.5.0 + + - name: echo all packages + run: | + echo ${{ steps.list-targets.outputs.targets }} From b639e8d9910a227e9f718a953f88009370fec524 Mon Sep 17 00:00:00 2001 From: pmacius Date: Fri, 27 Sep 2024 17:46:37 +0200 Subject: [PATCH 02/20] test --- .github/workflows/cleanup_images.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml index 73d88d2f..485d248e 100644 --- a/.github/workflows/cleanup_images.yml +++ b/.github/workflows/cleanup_images.yml @@ -12,10 +12,12 @@ jobs: - name: Checkout uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - - name: List all packages - id: list-targets - uses: docker/bake-action/subaction/list-targets@a4d7f0b5b91c14a296d792d4ec53a9db17f02e67 # v5.5.0 + - name: Extract all image names from HCL + id: extract_image_names + run: | + image_names=$(grep 'tags' docker-bake.hcl | sed -n 's/.*\/\([^:]*\):.*/\1/p' | tr '\n' ',' | sed 's/,$//') + echo "IMAGE_NAMES=$image_names" >> $GITHUB_ENV - - name: echo all packages + - name: Display the list of image names run: | - echo ${{ steps.list-targets.outputs.targets }} + echo "Extracted image names are: ${{ env.IMAGE_NAMES }}" From 55b29515049895cb4f91cddea3ea1b89d0b5e0d3 Mon Sep 17 00:00:00 2001 From: pmacius Date: Mon, 30 Sep 2024 12:31:15 +0200 Subject: [PATCH 03/20] try dry run with temp token --- .github/workflows/cleanup_images.yml | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml index 485d248e..189d4a31 100644 --- a/.github/workflows/cleanup_images.yml +++ b/.github/workflows/cleanup_images.yml @@ -5,19 +5,17 @@ on: branches: - main +permissions: + packages: write + jobs: cleanup: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - - - name: Extract all image names from HCL - id: extract_image_names - run: | - image_names=$(grep 'tags' docker-bake.hcl | sed -n 's/.*\/\([^:]*\):.*/\1/p' | tr '\n' ',' | sed 's/,$//') - echo "IMAGE_NAMES=$image_names" >> $GITHUB_ENV - - - name: Display the list of image names - run: | - echo "Extracted image names are: ${{ env.IMAGE_NAMES }}" + - name: Remove tag ${{format('pr-{0}', github.event.pull_request.number)}} + uses: dataaxiom/ghcr-cleanup-action@98b4022383d6ddb70ccbf6a378b4d8c67a60f066 + with: + token: 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 + owner: Alfresco + repository: alfresco-dockerfiles-bakery + dry-run: true From 0683a9a1acb0df33388a3cb3c6948b70a41e9587 Mon Sep 17 00:00:00 2001 From: pmacius Date: Mon, 30 Sep 2024 12:36:02 +0200 Subject: [PATCH 04/20] test --- .github/workflows/cleanup_images.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml index 189d4a31..ad58caac 100644 --- a/.github/workflows/cleanup_images.yml +++ b/.github/workflows/cleanup_images.yml @@ -15,7 +15,7 @@ jobs: - name: Remove tag ${{format('pr-{0}', github.event.pull_request.number)}} uses: dataaxiom/ghcr-cleanup-action@98b4022383d6ddb70ccbf6a378b4d8c67a60f066 with: - token: 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 + token: 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 owner: Alfresco repository: alfresco-dockerfiles-bakery dry-run: true From 9ab8138be7fecf16114ea9af15f9c9f2f135deea Mon Sep 17 00:00:00 2001 From: pmacius Date: Mon, 30 Sep 2024 12:38:45 +0200 Subject: [PATCH 05/20] check packages --- .github/workflows/cleanup_images.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml index ad58caac..3297383f 100644 --- a/.github/workflows/cleanup_images.yml +++ b/.github/workflows/cleanup_images.yml @@ -18,4 +18,5 @@ jobs: token: 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 owner: Alfresco repository: alfresco-dockerfiles-bakery + packages: '*' dry-run: true From 1039efce93d79d1808a2e0234eab603d607ed151 Mon Sep 17 00:00:00 2001 From: pmacius Date: Mon, 30 Sep 2024 12:41:10 +0200 Subject: [PATCH 06/20] expand packages --- .github/workflows/cleanup_images.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml index 3297383f..97febba3 100644 --- a/.github/workflows/cleanup_images.yml +++ b/.github/workflows/cleanup_images.yml @@ -19,4 +19,5 @@ jobs: owner: Alfresco repository: alfresco-dockerfiles-bakery packages: '*' + expand-packages: true dry-run: true From 5e80580bc7dd4b99460e2382e645b25c3e104020 Mon Sep 17 00:00:00 2001 From: pmacius Date: Mon, 30 Sep 2024 14:56:40 +0200 Subject: [PATCH 07/20] test --- .github/workflows/cleanup_images.yml | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml index 97febba3..8b5ae564 100644 --- a/.github/workflows/cleanup_images.yml +++ b/.github/workflows/cleanup_images.yml @@ -8,6 +8,25 @@ on: permissions: packages: write +env: + PACKAGE_NAMES: | + alfresco-transform-router + alfresco-shared-file-store + alfresco-content-repository + alfresco-imagemagick + alfresco-misc + alfresco-libreoffice + alfresco-pdf-renderer + alfresco-tika + alfresco-elasticsearch-live-indexing-content + alfresco-elasticsearch-live-indexing-path + alfresco-elasticsearch-live-indexing-metadata + alfresco-transform-core-aio + alfresco-elasticsearch-live-indexing + alfresco-share + alfresco-ooi-service + alfresco-ms-teams-service + jobs: cleanup: runs-on: ubuntu-latest @@ -18,6 +37,6 @@ jobs: token: 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 owner: Alfresco repository: alfresco-dockerfiles-bakery - packages: '*' - expand-packages: true + packages: ${{ env.PACKAGE_NAMES }} + delete-tags: ${{format('pr-{0}', github.event.pull_request.number)}} dry-run: true From 0cdb2ca9f5db12d540b7aa58928b7937803be8ab Mon Sep 17 00:00:00 2001 From: pmacius Date: Mon, 30 Sep 2024 14:59:09 +0200 Subject: [PATCH 08/20] test --- .github/workflows/cleanup_images.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml index 8b5ae564..b7205b42 100644 --- a/.github/workflows/cleanup_images.yml +++ b/.github/workflows/cleanup_images.yml @@ -31,12 +31,15 @@ jobs: cleanup: runs-on: ubuntu-latest steps: + - name: Convert PACKAGE_NAMES to comma-separated list + run: echo "PACKAGES=$(echo ${{ env.PACKAGE_NAMES }} | tr '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV + - name: Remove tag ${{format('pr-{0}', github.event.pull_request.number)}} uses: dataaxiom/ghcr-cleanup-action@98b4022383d6ddb70ccbf6a378b4d8c67a60f066 with: token: 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 owner: Alfresco repository: alfresco-dockerfiles-bakery - packages: ${{ env.PACKAGE_NAMES }} + packages: ${{ env.PACKAGES }} delete-tags: ${{format('pr-{0}', github.event.pull_request.number)}} dry-run: true From 2e6f9884bbdde8687fc655e6b9131dc5d4c4e601 Mon Sep 17 00:00:00 2001 From: pmacius Date: Mon, 30 Sep 2024 15:01:25 +0200 Subject: [PATCH 09/20] test --- .github/workflows/cleanup_images.yml | 35 +++++++++++++--------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml index b7205b42..0f6a5b6f 100644 --- a/.github/workflows/cleanup_images.yml +++ b/.github/workflows/cleanup_images.yml @@ -10,36 +10,33 @@ permissions: env: PACKAGE_NAMES: | - alfresco-transform-router - alfresco-shared-file-store - alfresco-content-repository - alfresco-imagemagick - alfresco-misc - alfresco-libreoffice - alfresco-pdf-renderer - alfresco-tika - alfresco-elasticsearch-live-indexing-content - alfresco-elasticsearch-live-indexing-path - alfresco-elasticsearch-live-indexing-metadata - alfresco-transform-core-aio - alfresco-elasticsearch-live-indexing - alfresco-share - alfresco-ooi-service + alfresco-transform-router, + alfresco-shared-file-store, + alfresco-content-repository, + alfresco-imagemagick, + alfresco-misc, + alfresco-libreoffice, + alfresco-pdf-renderer, + alfresco-tika, + alfresco-elasticsearch-live-indexing-content, + alfresco-elasticsearch-live-indexing-path, + alfresco-elasticsearch-live-indexing-metadata, + alfresco-transform-core-aio, + alfresco-elasticsearch-live-indexing, + alfresco-share, + alfresco-ooi-service, alfresco-ms-teams-service jobs: cleanup: runs-on: ubuntu-latest steps: - - name: Convert PACKAGE_NAMES to comma-separated list - run: echo "PACKAGES=$(echo ${{ env.PACKAGE_NAMES }} | tr '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV - - name: Remove tag ${{format('pr-{0}', github.event.pull_request.number)}} uses: dataaxiom/ghcr-cleanup-action@98b4022383d6ddb70ccbf6a378b4d8c67a60f066 with: token: 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 owner: Alfresco repository: alfresco-dockerfiles-bakery - packages: ${{ env.PACKAGES }} + packages: ${{ env.PACKAGE_NAMES }} delete-tags: ${{format('pr-{0}', github.event.pull_request.number)}} dry-run: true From 216c5fcfe531831b0e2d107b670bd9811a00a6c0 Mon Sep 17 00:00:00 2001 From: pmacius Date: Mon, 30 Sep 2024 15:07:23 +0200 Subject: [PATCH 10/20] test with good token --- .github/workflows/cleanup_images.yml | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml index 0f6a5b6f..1eadd7d1 100644 --- a/.github/workflows/cleanup_images.yml +++ b/.github/workflows/cleanup_images.yml @@ -10,22 +10,7 @@ permissions: env: PACKAGE_NAMES: | - alfresco-transform-router, - alfresco-shared-file-store, - alfresco-content-repository, - alfresco-imagemagick, - alfresco-misc, - alfresco-libreoffice, - alfresco-pdf-renderer, - alfresco-tika, - alfresco-elasticsearch-live-indexing-content, - alfresco-elasticsearch-live-indexing-path, - alfresco-elasticsearch-live-indexing-metadata, - alfresco-transform-core-aio, - alfresco-elasticsearch-live-indexing, - alfresco-share, - alfresco-ooi-service, - alfresco-ms-teams-service + alfresco-transform-router jobs: cleanup: @@ -34,7 +19,7 @@ jobs: - name: Remove tag ${{format('pr-{0}', github.event.pull_request.number)}} uses: dataaxiom/ghcr-cleanup-action@98b4022383d6ddb70ccbf6a378b4d8c67a60f066 with: - token: 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 + token: ${{ secrets.BOT_GITHUB_TOKEN }} owner: Alfresco repository: alfresco-dockerfiles-bakery packages: ${{ env.PACKAGE_NAMES }} From b033ebc61db8df54752ad30c1b6b5ec0e4bd9e3b Mon Sep 17 00:00:00 2001 From: pmacius Date: Mon, 30 Sep 2024 15:11:37 +0200 Subject: [PATCH 11/20] test all --- .github/workflows/cleanup_images.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml index 1eadd7d1..0634078a 100644 --- a/.github/workflows/cleanup_images.yml +++ b/.github/workflows/cleanup_images.yml @@ -10,10 +10,25 @@ permissions: env: PACKAGE_NAMES: | - alfresco-transform-router + alfresco-transform-router, + alfresco-shared-file-store, + alfresco-content-repository, + alfresco-imagemagick, + alfresco-misc, + alfresco-libreoffice, + alfresco-pdf-renderer, + alfresco-tika, + alfresco-elasticsearch-live-indexing-content, + alfresco-elasticsearch-live-indexing-path, + alfresco-elasticsearch-live-indexing-metadata, + alfresco-transform-core-aio, + alfresco-elasticsearch-live-indexing, + alfresco-share, + alfresco-ooi-service, + alfresco-ms-teams-service jobs: - cleanup: + cleanup-pr: runs-on: ubuntu-latest steps: - name: Remove tag ${{format('pr-{0}', github.event.pull_request.number)}} From 331b95262334d6cd16a6bb5b4ff553ef8f2ed295 Mon Sep 17 00:00:00 2001 From: pmacius Date: Mon, 30 Sep 2024 15:49:44 +0200 Subject: [PATCH 12/20] try "" --- .github/workflows/cleanup_images.yml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml index 0634078a..d266ff6a 100644 --- a/.github/workflows/cleanup_images.yml +++ b/.github/workflows/cleanup_images.yml @@ -10,7 +10,7 @@ permissions: env: PACKAGE_NAMES: | - alfresco-transform-router, + "alfresco-transform-router, alfresco-shared-file-store, alfresco-content-repository, alfresco-imagemagick, @@ -25,18 +25,35 @@ env: alfresco-elasticsearch-live-indexing, alfresco-share, alfresco-ooi-service, - alfresco-ms-teams-service + alfresco-ms-teams-service" jobs: cleanup-pr: runs-on: ubuntu-latest steps: + # - name: Set package names + # run: | + # echo "PACKAGE_NAMES=alfresco-transform-router,\ + # alfresco-shared-file-store,\ + # alfresco-content-repository,\ + # alfresco-imagemagick,\ + # alfresco-misc,\ + # alfresco-libreoffice,\ + # alfresco-pdf-renderer,\ + # alfresco-tika,\ + # alfresco-elasticsearch-live-indexing-content,\ + # alfresco-elasticsearch-live-indexing-path,\ + # alfresco-elasticsearch-live-indexing-metadata,\ + # alfresco-transform-core-aio,\ + # alfresco-elasticsearch-live-indexing,\ + # alfresco-share,\ + # alfresco-ooi-service,alfresco-ms-teams-service" >> $GITHUB_ENV - name: Remove tag ${{format('pr-{0}', github.event.pull_request.number)}} uses: dataaxiom/ghcr-cleanup-action@98b4022383d6ddb70ccbf6a378b4d8c67a60f066 with: token: ${{ secrets.BOT_GITHUB_TOKEN }} owner: Alfresco - repository: alfresco-dockerfiles-bakery + repository: alfresco-docker-images packages: ${{ env.PACKAGE_NAMES }} delete-tags: ${{format('pr-{0}', github.event.pull_request.number)}} dry-run: true From 3a933ca7ecdab910020bc52244f59058b83ba402 Mon Sep 17 00:00:00 2001 From: pmacius Date: Mon, 30 Sep 2024 15:50:33 +0200 Subject: [PATCH 13/20] fix --- .github/workflows/cleanup_images.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml index d266ff6a..87509ac4 100644 --- a/.github/workflows/cleanup_images.yml +++ b/.github/workflows/cleanup_images.yml @@ -53,7 +53,7 @@ jobs: with: token: ${{ secrets.BOT_GITHUB_TOKEN }} owner: Alfresco - repository: alfresco-docker-images + repository: alfresco-dockerfiles-bakery packages: ${{ env.PACKAGE_NAMES }} delete-tags: ${{format('pr-{0}', github.event.pull_request.number)}} dry-run: true From 5f89e74e8b5ddc29d6abd3039f22640cf049f465 Mon Sep 17 00:00:00 2001 From: pmacius Date: Mon, 30 Sep 2024 15:52:04 +0200 Subject: [PATCH 14/20] fix --- .github/workflows/cleanup_images.yml | 32 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml index 87509ac4..49ae8eca 100644 --- a/.github/workflows/cleanup_images.yml +++ b/.github/workflows/cleanup_images.yml @@ -10,22 +10,22 @@ permissions: env: PACKAGE_NAMES: | - "alfresco-transform-router, - alfresco-shared-file-store, - alfresco-content-repository, - alfresco-imagemagick, - alfresco-misc, - alfresco-libreoffice, - alfresco-pdf-renderer, - alfresco-tika, - alfresco-elasticsearch-live-indexing-content, - alfresco-elasticsearch-live-indexing-path, - alfresco-elasticsearch-live-indexing-metadata, - alfresco-transform-core-aio, - alfresco-elasticsearch-live-indexing, - alfresco-share, - alfresco-ooi-service, - alfresco-ms-teams-service" + alfresco-transform-router,\n + alfresco-shared-file-store,\n + alfresco-content-repository,\n + alfresco-imagemagick,\n + alfresco-misc,\n + alfresco-libreoffice,\n + alfresco-pdf-renderer,\n + alfresco-tika,\n + alfresco-elasticsearch-live-indexing-content,\n + alfresco-elasticsearch-live-indexing-path,\n + alfresco-elasticsearch-live-indexing-metadata,\n + alfresco-transform-core-aio,\n + alfresco-elasticsearch-live-indexing,\n + alfresco-share,\n + alfresco-ooi-service,\n + alfresco-ms-teams-service jobs: cleanup-pr: From 5f340527d1f2c6443940125d6b99925b90255b58 Mon Sep 17 00:00:00 2001 From: pmacius Date: Mon, 30 Sep 2024 15:55:31 +0200 Subject: [PATCH 15/20] try different approach --- .github/workflows/cleanup_images.yml | 54 ++++++++++------------------ 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml index 49ae8eca..82715c0d 100644 --- a/.github/workflows/cleanup_images.yml +++ b/.github/workflows/cleanup_images.yml @@ -8,46 +8,28 @@ on: permissions: packages: write -env: - PACKAGE_NAMES: | - alfresco-transform-router,\n - alfresco-shared-file-store,\n - alfresco-content-repository,\n - alfresco-imagemagick,\n - alfresco-misc,\n - alfresco-libreoffice,\n - alfresco-pdf-renderer,\n - alfresco-tika,\n - alfresco-elasticsearch-live-indexing-content,\n - alfresco-elasticsearch-live-indexing-path,\n - alfresco-elasticsearch-live-indexing-metadata,\n - alfresco-transform-core-aio,\n - alfresco-elasticsearch-live-indexing,\n - alfresco-share,\n - alfresco-ooi-service,\n - alfresco-ms-teams-service - jobs: cleanup-pr: runs-on: ubuntu-latest steps: - # - name: Set package names - # run: | - # echo "PACKAGE_NAMES=alfresco-transform-router,\ - # alfresco-shared-file-store,\ - # alfresco-content-repository,\ - # alfresco-imagemagick,\ - # alfresco-misc,\ - # alfresco-libreoffice,\ - # alfresco-pdf-renderer,\ - # alfresco-tika,\ - # alfresco-elasticsearch-live-indexing-content,\ - # alfresco-elasticsearch-live-indexing-path,\ - # alfresco-elasticsearch-live-indexing-metadata,\ - # alfresco-transform-core-aio,\ - # alfresco-elasticsearch-live-indexing,\ - # alfresco-share,\ - # alfresco-ooi-service,alfresco-ms-teams-service" >> $GITHUB_ENV + - name: Set package names + run: | + echo "PACKAGE_NAMES=alfresco-transform-router,\ + alfresco-shared-file-store,\ + alfresco-content-repository,\ + alfresco-imagemagick,\ + alfresco-misc,\ + alfresco-libreoffice,\ + alfresco-pdf-renderer,\ + alfresco-tika,\ + alfresco-elasticsearch-live-indexing-content,\ + alfresco-elasticsearch-live-indexing-path,\ + alfresco-elasticsearch-live-indexing-metadata,\ + alfresco-transform-core-aio,\ + alfresco-elasticsearch-live-indexing,\ + alfresco-share,\ + alfresco-ooi-service,\ + alfresco-ms-teams-service" >> $GITHUB_ENV - name: Remove tag ${{format('pr-{0}', github.event.pull_request.number)}} uses: dataaxiom/ghcr-cleanup-action@98b4022383d6ddb70ccbf6a378b4d8c67a60f066 with: From e36494476bf47762062bf6037e9c391d29443109 Mon Sep 17 00:00:00 2001 From: pmacius Date: Mon, 30 Sep 2024 16:16:06 +0200 Subject: [PATCH 16/20] test scheduled action --- .github/workflows/cleanup_images.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml index 82715c0d..d3ea81ee 100644 --- a/.github/workflows/cleanup_images.yml +++ b/.github/workflows/cleanup_images.yml @@ -4,10 +4,15 @@ on: pull_request: branches: - main + schedule: + - cron: '0 0 */14 * *' # Every 2 weeks permissions: packages: write +env: + KEEP_AMOUNT: 5 # Amount of latest images to keep after scheduled cleanup + jobs: cleanup-pr: runs-on: ubuntu-latest @@ -30,8 +35,9 @@ jobs: alfresco-share,\ alfresco-ooi-service,\ alfresco-ms-teams-service" >> $GITHUB_ENV - - name: Remove tag ${{format('pr-{0}', github.event.pull_request.number)}} + - name: Remove tag ${{format('pr-{0}', github.event.pull_request.number)}} after PR is closed uses: dataaxiom/ghcr-cleanup-action@98b4022383d6ddb70ccbf6a378b4d8c67a60f066 + if: github.event.pull_request == 'closed' with: token: ${{ secrets.BOT_GITHUB_TOKEN }} owner: Alfresco @@ -39,3 +45,13 @@ jobs: packages: ${{ env.PACKAGE_NAMES }} delete-tags: ${{format('pr-{0}', github.event.pull_request.number)}} dry-run: true + - name: Remove untaged images and keep latest ${{ env.KEEP_AMOUNT }} images + uses: dataaxiom/ghcr-cleanup-action@98b4022383d6ddb70ccbf6a378b4d8c67a60f066 + with: + token: ${{ secrets.BOT_GITHUB_TOKEN }} + owner: Alfresco + repository: alfresco-dockerfiles-bakery + packages: ${{ env.PACKAGE_NAMES }} + keep-n-tagged: ${{ env.KEEP_AMOUNT }} + delete-untagged: true + dry-run: true From 3aeb30e3c3b39517e4c1a783bdb6a5b1b5e3359b Mon Sep 17 00:00:00 2001 From: pmacius Date: Mon, 30 Sep 2024 16:34:19 +0200 Subject: [PATCH 17/20] prepare --- .github/workflows/cleanup_images.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml index d3ea81ee..368e8ede 100644 --- a/.github/workflows/cleanup_images.yml +++ b/.github/workflows/cleanup_images.yml @@ -2,8 +2,7 @@ name: Cleanup Docker images on ghcr.io on: pull_request: - branches: - - main + types: [closed] schedule: - cron: '0 0 */14 * *' # Every 2 weeks @@ -12,6 +11,8 @@ permissions: env: KEEP_AMOUNT: 5 # Amount of latest images to keep after scheduled cleanup + ORG: Alfresco + REPO: alfresco-dockerfiles-bakery jobs: cleanup-pr: @@ -40,17 +41,18 @@ jobs: if: github.event.pull_request == 'closed' with: token: ${{ secrets.BOT_GITHUB_TOKEN }} - owner: Alfresco - repository: alfresco-dockerfiles-bakery + owner: ${{ env.ORG }} + repository: ${{ env.REPO }} packages: ${{ env.PACKAGE_NAMES }} delete-tags: ${{format('pr-{0}', github.event.pull_request.number)}} dry-run: true - name: Remove untaged images and keep latest ${{ env.KEEP_AMOUNT }} images uses: dataaxiom/ghcr-cleanup-action@98b4022383d6ddb70ccbf6a378b4d8c67a60f066 + if: github.event_name == 'schedule' with: token: ${{ secrets.BOT_GITHUB_TOKEN }} - owner: Alfresco - repository: alfresco-dockerfiles-bakery + owner: ${{ env.ORG }} + repository: ${{ env.REPO }} packages: ${{ env.PACKAGE_NAMES }} keep-n-tagged: ${{ env.KEEP_AMOUNT }} delete-untagged: true From e7720e2f1ba0e67298ef6c7112ed3436e49729b6 Mon Sep 17 00:00:00 2001 From: pmacius Date: Mon, 30 Sep 2024 17:45:52 +0200 Subject: [PATCH 18/20] review --- .github/workflows/cleanup_images.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml index 368e8ede..58595874 100644 --- a/.github/workflows/cleanup_images.yml +++ b/.github/workflows/cleanup_images.yml @@ -5,12 +5,12 @@ on: types: [closed] schedule: - cron: '0 0 */14 * *' # Every 2 weeks + workflow_dispatch: permissions: packages: write env: - KEEP_AMOUNT: 5 # Amount of latest images to keep after scheduled cleanup ORG: Alfresco REPO: alfresco-dockerfiles-bakery @@ -38,7 +38,7 @@ jobs: alfresco-ms-teams-service" >> $GITHUB_ENV - name: Remove tag ${{format('pr-{0}', github.event.pull_request.number)}} after PR is closed uses: dataaxiom/ghcr-cleanup-action@98b4022383d6ddb70ccbf6a378b4d8c67a60f066 - if: github.event.pull_request == 'closed' + if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' with: token: ${{ secrets.BOT_GITHUB_TOKEN }} owner: ${{ env.ORG }} @@ -46,14 +46,13 @@ jobs: packages: ${{ env.PACKAGE_NAMES }} delete-tags: ${{format('pr-{0}', github.event.pull_request.number)}} dry-run: true - - name: Remove untaged images and keep latest ${{ env.KEEP_AMOUNT }} images + - name: Remove untaged images uses: dataaxiom/ghcr-cleanup-action@98b4022383d6ddb70ccbf6a378b4d8c67a60f066 - if: github.event_name == 'schedule' + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' with: token: ${{ secrets.BOT_GITHUB_TOKEN }} owner: ${{ env.ORG }} repository: ${{ env.REPO }} packages: ${{ env.PACKAGE_NAMES }} - keep-n-tagged: ${{ env.KEEP_AMOUNT }} delete-untagged: true dry-run: true From 905c1f781aa52f7ed6aa8f2516f258f534debd82 Mon Sep 17 00:00:00 2001 From: pmacius Date: Mon, 30 Sep 2024 18:19:49 +0200 Subject: [PATCH 19/20] add option to run with workflow dispatch, use dry run input to test, keep the dry run for other triggers for now --- .github/workflows/build_and_test.yml | 2 +- .github/workflows/cleanup_images.yml | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 2ca93bb3..e5e9e236 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -23,7 +23,7 @@ env: ARTIFACT_NAME: alfresco-docker-images REGISTRY: ghcr.io REGISTRY_NAMESPACE: alfresco - TAG: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.sha }} + TAG: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.ref_name }} concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name || github.run_id }} diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml index 58595874..4b3a59d2 100644 --- a/.github/workflows/cleanup_images.yml +++ b/.github/workflows/cleanup_images.yml @@ -6,11 +6,17 @@ on: schedule: - cron: '0 0 */14 * *' # Every 2 weeks workflow_dispatch: + inputs: + dry-run: + description: 'If set to false, images will be deleted' + required: false + default: 'true' permissions: packages: write env: + KEEP_AMOUNT: 1 # onetime cleanup ORG: Alfresco REPO: alfresco-dockerfiles-bakery @@ -45,8 +51,8 @@ jobs: repository: ${{ env.REPO }} packages: ${{ env.PACKAGE_NAMES }} delete-tags: ${{format('pr-{0}', github.event.pull_request.number)}} - dry-run: true - - name: Remove untaged images + dry-run: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run || 'true' }} + - name: Remove untaged images and keep latest ${{ env.KEEP_AMOUNT }} images uses: dataaxiom/ghcr-cleanup-action@98b4022383d6ddb70ccbf6a378b4d8c67a60f066 if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' with: @@ -54,5 +60,6 @@ jobs: owner: ${{ env.ORG }} repository: ${{ env.REPO }} packages: ${{ env.PACKAGE_NAMES }} + keep-n-tagged: ${{ env.KEEP_AMOUNT }} # onetime cleanup delete-untagged: true - dry-run: true + dry-run: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run || 'true' }} From d48ec420c647ad4000ef73743794946ab8f59cbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Maciusiak?= <158472457+pmacius@users.noreply.github.com> Date: Tue, 1 Oct 2024 11:08:43 +0200 Subject: [PATCH 20/20] Update .github/workflows/cleanup_images.yml Co-authored-by: Giovanni Toraldo <71768+gionn@users.noreply.github.com> --- .github/workflows/cleanup_images.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cleanup_images.yml b/.github/workflows/cleanup_images.yml index 4b3a59d2..a2b1bb60 100644 --- a/.github/workflows/cleanup_images.yml +++ b/.github/workflows/cleanup_images.yml @@ -10,7 +10,8 @@ on: dry-run: description: 'If set to false, images will be deleted' required: false - default: 'true' + type: boolean + default: true permissions: packages: write