Skip to content

Commit 930b611

Browse files
authored
fix: Only delete untagged images over 2 years old in AWS ECR and GHCR (#297)
1 parent 25a2b8d commit 930b611

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

.github/workflows/image-cleanup.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ jobs:
2828
.github/workflows/scripts/delete-untagged-amazon-public-ecr-images.sh
2929
3030
- name: Delete untagged NGINX Unprivileged Docker images on the GitHub Container Registry
31-
uses: stumpylog/image-cleaner-action/untagged@48f1aa2111ae929cea4a0e056045f7de0e1b2618 # v0.10.0
31+
uses: dataaxiom/ghcr-cleanup-action@cd0cdb900b5dbf3a6f2cc869f0dbb0b8211f50c4 # v1.0.16
3232
with:
33-
is_org: true
34-
owner: nginxinc
35-
package_name: nginx-unprivileged
36-
do_delete: true
33+
package: nginx-unprivileged
34+
delete-ghost-images: true
35+
delete-untagged: true
36+
delete-partial-images: true
37+
delete-orphaned-images: true
38+
older-than: 2 years
3739
token: ${{ secrets.GITHUB_TOKEN }}
40+
validate: true

.github/workflows/scripts/delete-untagged-amazon-public-ecr-images.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
set -eu
66

77
REPOSITORY_NAME=nginx-unprivileged
8-
BATCH_DELETE_SIZE=100 # The max delete size allowed by the 'batch-delete-image' aws CLI command is 100
8+
BATCH_DELETE_SIZE=100 # The max delete size allowed by the 'batch-delete-image' AWS CLI command is 100
9+
CUTOFF_DATE=$(date -d '2 years ago' +%Y-%m-%d)
910

1011
function batch_delete {
1112
while read -r batch; do
@@ -23,16 +24,15 @@ function batch_delete {
2324
# otherwise any referenced untagged images can not be deleted.
2425
IMAGE_DIGESTS=$(aws ecr-public describe-images \
2526
--repository-name "${REPOSITORY_NAME}" \
26-
--query 'imageDetails[?!imageTags && (contains(imageManifestMediaType, `manifest.list.v2`) || contains(imageManifestMediaType, `image.index.v1`))].{imageDigest: join(`=`, [`imageDigest`, imageDigest])}' \
27+
--query 'imageDetails[?!imageTags && (contains(imageManifestMediaType, `manifest.list.v2`) || contains(imageManifestMediaType, `image.index.v1`)) && imagePushedAt < `'$CUTOFF_DATE'`].{imageDigest: join(`=`, [`imageDigest`, imageDigest])}' \
2728
--output text)
2829

2930
batch_delete "${IMAGE_DIGESTS}"
3031

3132
# Find untagged images and delete them.
3233
IMAGE_DIGESTS=$(aws ecr-public describe-images \
3334
--repository-name "${REPOSITORY_NAME}" \
34-
--query 'imageDetails[?!imageTags].{imageDigest: join(`=`, [`imageDigest`, imageDigest])}' \
35+
--query 'imageDetails[?!imageTags && imagePushedAt < `'$CUTOFF_DATE'` ].{imageDigest: join(`=`, [`imageDigest`, imageDigest])}' \
3536
--output text)
3637

3738
batch_delete "${IMAGE_DIGESTS}"
38-

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ This repo contains a series of Dockerfiles to create an NGINX Docker image that
1414
- The default NGINX PID has been moved from `/var/run/nginx.pid` to `/tmp/nginx.pid`
1515
- Change `*_temp_path` variables to `/tmp/*`
1616

17-
New images are built and pushed to on a weekly basis (every Monday night).
18-
1917
Check out the [docs](https://hub.docker.com/_/nginx) for the upstream Docker NGINX image for a detailed explanation on how to use this image.
2018

2119
## Supported Image Registries and Platforms
@@ -29,6 +27,16 @@ You can find pre-built images in each of the following registries:
2927
- GitHub Container Registry - <https://github.com/nginxinc/docker-nginx-unprivileged/pkgs/container/nginx-unprivileged>
3028
- Quay - <https://quay.io/repository/nginx/nginx-unprivileged>
3129

30+
### Image Builds and Retention Policy
31+
32+
#### Image Builds
33+
34+
New images are built whenever there is a new NGINX release or a critical CVE is found and fixed (check the [`security documentation`](/SECURITY.md) for more details). New images are also built and pushed to on a weekly basis (every Monday night). Whenever a new image is built, the current NGINX mainline and stable tags get switched to the latest build, and the image that gets replaced will become untagged. If you wish to point your builds to a specific image over time, use the specific image digest instead of the tag.
35+
36+
#### Image Retention Policy
37+
38+
Untagged images on Amazon ECR and the GitHub Container Registry are cleaned up on a two year basis. Untagged images on Docker Hub are not cleaned up at this time (this might change with the incoming storage changes). Untagged images on Quay are continuously removed due to its built in garbage collector. The last built tag of every release is kept indefinitely in every of the aforementioned registries.
39+
3240
### Architectures
3341

3442
Most images are built for the `amd64`, `arm32v5` (for Debian), `arm32v6` (for Alpine), `arm32v7`, `arm64v8`, `i386`, `mips64le` (for Debian), `ppc64le` and `s390x` architectures.
@@ -60,7 +68,7 @@ Most images are built for the `amd64`, `arm32v5` (for Debian), `arm32v6` (for Al
6068
6169
Whilst issues and PRs are welcome, please do note that:
6270
63-
1. Issues related to security vulnerabilities will be promptly closed unless they are accompanied by a solid reasoning as to why the vulnerability poses a real security threat to this image. Check out the [`SECURITY`](https://github.com/nginxinc/docker-nginx-unprivileged/blob/main/SECURITY.md) doc for more details.
71+
1. Issues related to security vulnerabilities will be promptly closed unless they are accompanied by a solid reasoning as to why the vulnerability poses a real security threat to this image. Check out the [`security documentation`](/SECURITY.md) for more details.
6472
2. These images are unprivileged ports of the upstream [Docker NGINX](https://github.com/nginxinc/docker-nginx) images. Any changes that do not specifically involve the changes made to run NGINX on an unprivileged system should be reported in the [Docker NGINX](https://github.com/nginxinc/docker-nginx) upstream repo. They will not get addressed here.
6573
3. Following from 2., base images (e.g. Alpine x.x or Debian x) in the [Docker NGINX](https://github.com/nginxinc/docker-nginx) upstream repo get updated when a new version of NGINX is released, never within the same release version. Similarly, new NGINX releases usually make their way to the [Docker NGINX](https://github.com/nginxinc/docker-nginx) image a couple days after their standard release. Please refrain from opening an issue or PR here if the upstream repo hasn't been updated -- it will be closed.
6674

0 commit comments

Comments
 (0)