From 81ba73785bb8207a451a0de928aa6a3c57d6fd77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Lilleb=C3=B8=20Gundersen?= Date: Wed, 2 Feb 2022 00:34:37 +0100 Subject: [PATCH 1/3] Update test workflow (#24) --- .github/workflows/clean_packages.yml | 69 ++++++++++++++++++---------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/.github/workflows/clean_packages.yml b/.github/workflows/clean_packages.yml index f333b40..548444c 100644 --- a/.github/workflows/clean_packages.yml +++ b/.github/workflows/clean_packages.yml @@ -6,56 +6,77 @@ jobs: build-containers: name: Build a few images runs-on: ubuntu-latest + env: + IMAGE: ghcr.io/sondrelg/ghcr-retention-policy-test steps: - - name: Check out repository - uses: actions/checkout@v2 - - name: Setup Docker Buildx - uses: docker/setup-buildx-action@v1 - - name: Login to GHCR - run: docker login ghcr.io -u sondrelg --password-stdin <<< ${{ secrets.PAT }} + - uses: actions/checkout@v2 + - uses: docker/setup-buildx-action@v1 + - run: docker login ghcr.io -u sondrelg --password-stdin <<< ${{ secrets.PAT }} + # Each build should be different because of the $RANDOM addition - name: Build latest - run: echo $'FROM scratch\nCMD ["$RANDOM"]' > Dockerfile.test && docker buildx build . -f Dockerfile.test -t "ghcr.io/sondrelg/ghcr-retention-policy-test:latest" --cache-to=type=inline --cache-from="ghcr.io/sondrelg/ghcr-retention-policy-test:latest" --push + run: | + randomString=$(LC_ALL=C tr -dc A-Za-z Dockerfile.test + cat Dockerfile.test + docker buildx build . -f Dockerfile.test -t "${{ env.IMAGE }}:latest" --cache-to=type=inline --cache-from="ghcr.io/sondrelg/ghcr-retention-policy-test:latest" --push - name: Build latest - run: echo $'FROM scratch\nCMD ["$RANDOM"]' > Dockerfile.test && docker buildx build . -f Dockerfile.test -t "ghcr.io/sondrelg/ghcr-retention-policy-test:latest" --cache-to=type=inline --cache-from="ghcr.io/sondrelg/ghcr-retention-policy-test:latest" --push + run: | + randomString=$(LC_ALL=C tr -dc A-Za-z Dockerfile.test + cat Dockerfile.test + docker buildx build . -f Dockerfile.test -t "${{ env.IMAGE }}:latest" --cache-to=type=inline --cache-from="ghcr.io/sondrelg/ghcr-retention-policy-test:latest" --push - name: Build latest - run: echo $'FROM scratch\nCMD ["$RANDOM"]' > Dockerfile.test && docker buildx build . -f Dockerfile.test -t "ghcr.io/sondrelg/ghcr-retention-policy-test:latest" --cache-to=type=inline --cache-from="ghcr.io/sondrelg/ghcr-retention-policy-test:latest" --push + run: | + randomString=$(LC_ALL=C tr -dc A-Za-z Dockerfile.test + cat Dockerfile.test + docker buildx build . -f Dockerfile.test -t "${{ env.IMAGE }}:latest" --cache-to=type=inline --cache-from="ghcr.io/sondrelg/ghcr-retention-policy-test:latest" --push - name: Build latest - run: echo $'FROM scratch\nCMD ["$RANDOM"]' > Dockerfile.test && docker buildx build . -f Dockerfile.test -t "ghcr.io/sondrelg/ghcr-retention-policy-test:latest" --cache-to=type=inline --cache-from="ghcr.io/sondrelg/ghcr-retention-policy-test:latest" --push + run: | + randomString=$(LC_ALL=C tr -dc A-Za-z Dockerfile.test + cat Dockerfile.test + docker buildx build . -f Dockerfile.test -t "${{ env.IMAGE }}:latest" --cache-to=type=inline --cache-from="ghcr.io/sondrelg/ghcr-retention-policy-test:latest" --push - name: Build latest - run: echo $'FROM scratch\nCMD ["$RANDOM"]' > Dockerfile.test && docker buildx build . -f Dockerfile.test -t "ghcr.io/sondrelg/ghcr-retention-policy-test:latest" --cache-to=type=inline --cache-from="ghcr.io/sondrelg/ghcr-retention-policy-test:latest" --push + run: | + clean-ghcr: needs: build-containers name: Then delete them runs-on: ubuntu-latest steps: - - name: Cache(d) image versions to skip + - name: Cache image versions to skip uses: actions/cache@v2 + id: cache with: path: skip-image-versions.txt - key: image-versions-to-skip + # key will always *not* match for a new commit, but + # restore-key will match if there's a previously stored + # file; so cache will *both be loaded and stored*. + key: image-versions-to-skip-${{ github.sha }} + restore-keys: image-versions-to-skip - name: Create file if it doesn't exist run: touch skip-image-versions.txt - if: steps.cache-venv.outputs.cache-hit != 'true' + if: steps.cache.outputs.cache-hit != 'true' - - name: Output file content - run: cat skip-image-versions.txt + - name: Set image-versions output + id: image-version + run: | + images="$(cat skip-image-versions.txt)" + echo $images + echo "::set-output name=image-versions::$images" - name: Delete images more than 2 seconds old - uses: sondrelg/container-retention-policy@main + uses: sondrelg/container-retention-policy@sondrelg/experiment id: delete-images with: image-names: ghcr-retention-policy-test cut-off: 2 seconds ago UTC+2 account-type: personal token: ${{ secrets.PAT }} + skip-tags: ${{ steps.image-version.outputs.image-versions }} - name: Write skipped tags to cache run: | - echo "${{ steps.delete-images.outputs.needs-github-assistance }}" - echo "${{ steps.delete-images.outputs.failed }}" - echo "${{ steps.delete-images.outputs.deleted }}" - echo "${{ steps.delete-images.outputs.needs-github-assistance }}" > skip-image-versions.txt - - - name: Output file content - run: cat skip-image-versions.txt + echo "${{ steps.delete-images.outputs.failed }}" > skip-image-versions.txt From b18164447ea799e1947d6c6b30729e2294dae0b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Lilleb=C3=B8=20Gundersen?= Date: Wed, 16 Mar 2022 22:26:33 +0100 Subject: [PATCH 2/3] fix: Install pinned regex version The latest regex release installed by dateparser breaks the action. --- Dockerfile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d74f158..0d59576 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,14 @@ FROM python:3.10.2-alpine RUN apk add build-base -RUN pip install httpx dateparser pydantic +RUN pip install \ + # Added after new regex release broke \ + # dateparser. See https://stackoverflow.com/questions/71496687/dateparser-throws-regex-regex-core-error/71501074#71501074 \ + # and https://github.com/snok/container-retention-policy/issues/26 + regex==2022.3.2 \ + httpx \ + dateparser \ + pydantic COPY main.py /main.py From 2b03b70aae6f0aaa3d897f3832a4ff2bd664c0c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Lilleb=C3=B8=20Gundersen?= Date: Wed, 16 Mar 2022 22:26:54 +0100 Subject: [PATCH 3/3] chore: Add build workflow --- .github/workflows/build.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..f2f4882 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,18 @@ +name: build-dockerfile + +on: + push: + +jobs: + buildx: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Build dockerfile + run: docker build .