Skip to content

Commit d37312a

Browse files
committed
Begin adding script to prune old ECR images
1 parent 1618173 commit d37312a

File tree

1 file changed

+44
-30
lines changed

1 file changed

+44
-30
lines changed

.github/workflows/ci.yml

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,37 @@ on:
99
- main
1010
workflow_dispatch: {}
1111

12+
# Deployment requirements:
13+
# - secrets.DOCKERHUB_TOKEN is a Personal Access Token for hub.docker.com with Read & Write access
14+
# - secrets.ECR_PUBLIC_AWS_ACCESS_KEY_ID & secrets.ECR_PUBLIC_AWS_SECRET_ACCESS_KEY are for an AWS IAM User with the policy:
15+
# {
16+
# "Version": "2012-10-17",
17+
# "Statement": [
18+
# {
19+
# "Effect": "Allow",
20+
# "Action": [
21+
# "ecr-public:InitiateLayerUpload",
22+
# "ecr-public:UploadLayerPart",
23+
# "ecr-public:PutImage",
24+
# "ecr-public:CompleteLayerUpload",
25+
# "ecr-public:BatchCheckLayerAvailability",
26+
# "ecr-public:DescribeImages",
27+
# "ecr-public:BatchDeleteImage"
28+
# ],
29+
# "Resource": "arn:aws:ecr-public::<aws-account-here>:repository/refacto"
30+
# },
31+
# {
32+
# "Effect": "Allow",
33+
# "Action": [
34+
# "sts:GetServiceBearerToken",
35+
# "ecr-public:GetAuthorizationToken"
36+
# ],
37+
# "Resource": "*"
38+
# }
39+
# ]
40+
# }
41+
# (DescribeImages & BatchDeleteImage are required for auto-pruning old images. The rest are needed by docker/build-push-action)
42+
1243
jobs:
1344
build_and_test:
1445
runs-on: ubuntu-latest
@@ -124,39 +155,16 @@ jobs:
124155
registry: docker.io
125156
username: refacto
126157
password: ${{ secrets.DOCKERHUB_TOKEN }}
127-
- name: Authenticate with Public ECR
158+
- name: Authenticate with AWS
159+
uses: aws-actions/configure-aws-credentials@v5
160+
with:
161+
aws-access-key-id: ${{ secrets.ECR_PUBLIC_AWS_ACCESS_KEY_ID }}
162+
aws-secret-access-key: ${{ secrets.ECR_PUBLIC_AWS_SECRET_ACCESS_KEY }}
163+
aws-region: us-east-1 # ECR public is only available via the N. Virginia region
164+
- name: Authenticate with ECR Public
128165
uses: docker/login-action@v3
129-
# this uses an access key for an IAM user with the policy:
130-
# {
131-
# "Version": "2012-10-17",
132-
# "Statement": [
133-
# {
134-
# "Effect": "Allow",
135-
# "Action": [
136-
# "ecr-public:InitiateLayerUpload",
137-
# "ecr-public:UploadLayerPart",
138-
# "ecr-public:PutImage",
139-
# "ecr-public:CompleteLayerUpload",
140-
# "ecr-public:BatchCheckLayerAvailability"
141-
# ],
142-
# "Resource": "arn:aws:ecr-public::<aws-account-here>:repository/refacto"
143-
# },
144-
# {
145-
# "Effect": "Allow",
146-
# "Action": [
147-
# "sts:GetServiceBearerToken",
148-
# "ecr-public:GetAuthorizationToken"
149-
# ],
150-
# "Resource": "*"
151-
# }
152-
# ]
153-
# }
154166
with:
155167
registry: public.ecr.aws
156-
username: ${{ secrets.ECR_PUBLIC_AWS_ACCESS_KEY_ID }}
157-
password: ${{ secrets.ECR_PUBLIC_AWS_SECRET_ACCESS_KEY }}
158-
env:
159-
AWS_REGION: us-east-1 # ECR public is only available via the N. Virginia region
160168
- name: Set up QEMU for Cross-Architecture Builds
161169
uses: docker/setup-qemu-action@v3
162170
with:
@@ -189,6 +197,12 @@ jobs:
189197
org.opencontainers.image.source=${{ github.repositoryUrl }}
190198
org.opencontainers.image.licenses=GPL-3.0-or-later
191199
org.opencontainers.image.base.name=docker.io/node:24-alpine
200+
- name: Prune old ECR images
201+
# work around lack of support for lifecycle policies in ECR Public (see https://github.com/aws/containers-roadmap/issues/1268)
202+
run: |
203+
set -e
204+
# temporary: for now, just print out the information from the repository
205+
aws ecr-public describe-images --repository-name refacto --output json
192206
193207
create_github_release:
194208
needs:

0 commit comments

Comments
 (0)