Second invocation should delete nothing #23
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
name: test pruner | |
on: | |
push: | |
paths: | |
- 'experimental/**' | |
- '.github/**' | |
workflow_dispatch: | |
defaults: | |
run: | |
shell: 'bash -Eeuo pipefail -x {0}' | |
permissions: | |
contents: read | |
jobs: | |
build_and_prune: | |
runs-on: "ubuntu-latest" | |
services: | |
registry: | |
image: registry:2 | |
ports: | |
- 5000:5000 | |
env: | |
REGISTRY_STORAGE: "s3" | |
REGISTRY_STORAGE_S3_REGIONENDPOINT: "http://s3mock:9090" | |
REGISTRY_STORAGE_S3_BUCKET: "mockbucket" | |
REGISTRY_STORAGE_S3_V4AUTH: "false" | |
REGISTRY_STORAGE_S3_REGION: "generic" | |
REGISTRY_STORAGE_S3_SECURE: "false" | |
REGISTRY_STORAGE_S3_ACCESSKEY: "123" | |
REGISTRY_STORAGE_S3_SECRETKEY: "123" | |
REGISTRY_STORAGE_DELETE_ENABLED: "true" | |
REGISTRY_STORAGE_REDIRECT_DISABLE: "true" | |
credentials: | |
username: oxpa | |
password: ${{ secrets.DOCKERHUB_PASS }} | |
s3mock: | |
image: adobe/s3mock | |
ports: | |
- 9090:9090 | |
env: | |
initialBuckets: mockbucket | |
debug: true | |
credentials: | |
username: oxpa | |
password: ${{ secrets.DOCKERHUB_PASS }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Build code | |
run: | | |
cd cmds/docker-distribution-pruner/ | |
go get | |
go build | |
mv docker-distribution-pruner ../../ | |
cd - | |
- name: Add bucket hostname | |
run: echo "127.0.0.1 mockbucket.s3mock s3mock" | sudo tee -a /etc/hosts | |
- name: Login to Dockerhub | |
uses: docker/login-action@v3 | |
with: | |
username: oxpa | |
password: ${{ secrets.DOCKERHUB_PASS }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: arm64v8, amd64 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
driver-opts: network=host | |
- name: Build A as latest image | |
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 | |
env: | |
SOURCE_DATE_EPOCH: 123 | |
with: | |
file: "examples/fixtures/Dockerfile" | |
context: "examples/fixtures/" | |
platforms: "amd64,arm64" | |
tags: "localhost:5000/image:latest" | |
outputs: type=registry,push=true,rewrite-timestamp=true | |
target: "A" | |
- name: Build B as latest image | |
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 | |
env: | |
SOURCE_DATE_EPOCH: 123 | |
with: | |
file: "examples/fixtures/Dockerfile" | |
context: "examples/fixtures/" | |
platforms: "amd64,arm64" | |
tags: "localhost:5000/image:latest" | |
outputs: type=registry,push=true,rewrite-timestamp=true | |
target: "B" | |
- name: Build AB as latest image | |
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 | |
env: | |
SOURCE_DATE_EPOCH: 123 | |
with: | |
file: "examples/fixtures/Dockerfile" | |
context: "examples/fixtures/" | |
platforms: "amd64,arm64" | |
tags: "localhost:5000/image:latest,localhost:5000/image:AB" | |
outputs: type=registry,push=true,rewrite-timestamp=true | |
target: "AB" | |
- name: Build A as latest and A | |
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 | |
env: | |
SOURCE_DATE_EPOCH: 123 | |
with: | |
file: "examples/fixtures/Dockerfile" | |
context: "examples/fixtures/" | |
platforms: "amd64,arm64" | |
tags: "localhost:5000/image:A,localhost:5000/image:latest" | |
outputs: type=registry,push=true,rewrite-timestamp=true | |
target: "A" | |
- name: Build AB for latest | |
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 | |
env: | |
SOURCE_DATE_EPOCH: 123 | |
with: | |
file: "examples/fixtures/Dockerfile" | |
context: "examples/fixtures/" | |
platforms: "amd64,arm64" | |
tags: "localhost:5000/image:latest" | |
outputs: type=registry,push=true,rewrite-timestamp=true | |
target: "AB" | |
- name: Install regctl | |
uses: iarekylew00t/regctl-installer@v2 | |
- name: Test images can be downloaded | |
run: | | |
regctl --host reg=localhost:5000,tls=disabled tag list localhost:5000/image | |
for i in A AB latest; do | |
regctl --host reg=localhost:5000,tls=disabled image manifest localhost:5000/image:$i | |
regctl --host reg=localhost:5000,tls=disabled image export localhost:5000/image:$i > /dev/null | |
done | |
- name: Prune registry | |
run: | | |
EXPERIMENTAL=true ./docker-distribution-pruner -config examples/registry/s3config.yml -delete -trace | |
if EXPERIMENTAL=true ./docker-distribution-pruner -config examples/registry/s3config.yml -delete -trace | grep 'DELETE '; then | |
exit 1 | |
fi | |
- name: Test images can be downloaded after pruning | |
run: | | |
regctl --host reg=localhost:5000,tls=disabled tag list localhost:5000/image | |
for i in A AB latest; do | |
regctl --host reg=localhost:5000,tls=disabled image manifest localhost:5000/image:$i | |
regctl --host reg=localhost:5000,tls=disabled image export localhost:5000/image:$i > /dev/null | |
done | |
- name: Delete tag | |
run: | | |
regctl --host reg=localhost:5000,tls=disabled tag list localhost:5000/image | |
regctl --host reg=localhost:5000,tls=disabled tag delete localhost:5000/image:latest | |
for i in A AB; do | |
regctl --host reg=localhost:5000,tls=disabled image manifest localhost:5000/image:$i | |
regctl --host reg=localhost:5000,tls=disabled image export localhost:5000/image:$i > /dev/null | |
done | |
if regctl --host reg=localhost:5000,tls=disabled image manifest localhost:5000/image:latest; then | |
echo "Something went wrong!" | |
exit 1 | |
fi | |
- name: Prune registry again | |
run: | | |
EXPERIMENTAL=true ./docker-distribution-pruner -config examples/registry/s3config.yml -delete -trace | |
if EXPERIMENTAL=true ./docker-distribution-pruner -config examples/registry/s3config.yml -delete -trace | grep 'DELETE '; then | |
exit 1 | |
fi | |
- name: Test images can be downloaded after pruning a tag | |
run: | | |
regctl --host reg=localhost:5000,tls=disabled tag list localhost:5000/image | |
for i in A AB; do | |
regctl --host reg=localhost:5000,tls=disabled image manifest localhost:5000/image:$i | |
regctl --host reg=localhost:5000,tls=disabled image export localhost:5000/image:$i > /dev/null | |
done |