diff --git a/.github/workflows/cleanup_closed_pr_packages.yaml b/.github/workflows/cleanup_closed_pr_packages.yaml new file mode 100644 index 000000000..ac302b7a3 --- /dev/null +++ b/.github/workflows/cleanup_closed_pr_packages.yaml @@ -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 }} \ No newline at end of file diff --git a/.github/workflows/deploy_master.yaml b/.github/workflows/deploy_master.yaml new file mode 100644 index 000000000..dfc8ea4ea --- /dev/null +++ b/.github/workflows/deploy_master.yaml @@ -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/metadata-action@v5.0.0 + 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 diff --git a/.github/workflows/manual_deploy.yml b/.github/workflows/manual_deploy.yml index 1c41ad076..202db6a9d 100644 --- a/.github/workflows/manual_deploy.yml +++ b/.github/workflows/manual_deploy.yml @@ -55,11 +55,15 @@ jobs: uses: docker/metadata-action@v5.4.0 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 }} diff --git a/.github/workflows/packages_retention.yaml b/.github/workflows/packages_retention.yaml new file mode 100644 index 000000000..3fe47a2cb --- /dev/null +++ b/.github/workflows/packages_retention.yaml @@ -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 }}