-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable ghcr.io containers retention policies (#1454)
- Loading branch information
Showing
4 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Cleanup GHCR docker packages on closed pull request | ||
|
||
on: | ||
pull_request_target: | ||
types: | ||
- closed | ||
|
||
jobs: | ||
cleanup-package: | ||
name: Cleanup closed PR package | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Cleanup web package | ||
uses: snok/container-retention-policy@v2 | ||
with: | ||
image-names: ${{ github.event.repository.name }}-web | ||
cut-off: now UTC | ||
timestamp-to-use: created_at | ||
account-type: org | ||
org-name: ${{ github.repository_owner }} | ||
keep-at-least: 0 | ||
filter-tags: pr-${{github.event.pull_request.number}} | ||
token: ${{ secrets.PAT }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Deploy web docker image to GHCR registry on push to master | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }}-web | ||
|
||
jobs: | ||
deploy-web: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/[email protected] | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.WORKER_IMAGE_NAME }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
provenance: false | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }}, ${{ steps.meta.outputs.tags }}-${{github.run_number}} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
build-args: | | ||
BUILDKIT_CONTEXT_KEEP_GIT_DIR=true | ||
DEPLOYMENT=dev |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,11 +55,15 @@ jobs: | |
uses: docker/[email protected] | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
# Need to override the tag with pr-{issue_number} to make the retention working properly | ||
tags: | | ||
type=raw,value=pr-${{ github.event.issue.number }} | ||
# see https://github.com/docker/build-push-action/issues/513#issuecomment-987951050 | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
provenance: false | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Retention policy for web GHCR docker packages | ||
|
||
on: | ||
schedule: | ||
- cron: '30 4 * * MON' # Running every Monday at 04:30 AM | ||
workflow_dispatch: | ||
|
||
jobs: | ||
cleanup-packages: | ||
name: Cleanup old GHCR docker packages | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Cleanup web outdated PR packages | ||
uses: snok/container-retention-policy@v2 | ||
with: | ||
image-names: ${{ github.event.repository.name }}-web | ||
cut-off: 2 weeks ago UTC | ||
timestamp-to-use: created_at | ||
account-type: org | ||
org-name: ${{ github.repository_owner }} | ||
keep-at-least: 0 | ||
untagged-only: true | ||
token: ${{ secrets.PAT }} | ||
- name: Cleanup web latest but old PR packages | ||
uses: snok/container-retention-policy@v2 | ||
with: | ||
image-names: ${{ github.event.repository.name }}-web | ||
cut-off: 2 months ago UTC | ||
timestamp-to-use: created_at | ||
account-type: org | ||
org-name: ${{ github.repository_owner }} | ||
keep-at-least: 0 | ||
filter-include-untagged: false | ||
filter-tags: pr-* | ||
token: ${{ secrets.PAT }} | ||
- name: Cleanup web outdated master packages | ||
uses: snok/container-retention-policy@v2 | ||
with: | ||
image-names: ${{ github.event.repository.name }}-web | ||
cut-off: 1 month ago UTC | ||
timestamp-to-use: created_at | ||
account-type: org | ||
org-name: ${{ github.repository_owner }} | ||
keep-at-least: 0 | ||
filter-include-untagged: false | ||
filter-tags: master-* | ||
skip-tags: master # Don't remove the newest master image | ||
token: ${{ secrets.PAT }} |