Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ecr): configure immutable tags for ecr repo #11954

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/prlinter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
"@actions/github": "^2.1.0",
"prlint": "file:../../../tools/prlint"
}
}
}
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-ecr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,13 @@ is important here):
repository.addLifecycleRule({ tagPrefixList: ['prod'], maxImageCount: 9999 });
repository.addLifecycleRule({ maxImageAge: cdk.Duration.days(30) });
```

## Immutable tags

Repositories configured with immutable tags prevent image tags from being overwritten. By default, tags are mutable. To create a new repository with immutable tags, simply enable `imageScanOnPush` in the properties

```ts
const repository = new ecr.Repository(stack, 'Repo', {
imageTagImmutable: true
});
```
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-ecr/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,13 @@ export interface RepositoryProps {
* @default false
*/
readonly imageScanOnPush?: boolean;

/**
* Enable image tag references to be mutable
*
* @default true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default for this is actually false right? When you pass undefined to the L1, then the default value is MUTABLE as documented here

*/
readonly imageTagImmutable?: boolean;
}

export interface RepositoryAttributes {
Expand Down Expand Up @@ -422,6 +429,7 @@ export class Repository extends RepositoryBase {
imageScanningConfiguration: !props.imageScanOnPush ? undefined : {
scanOnPush: true,
},
imageTagMutability: props.imageTagImmutable ? 'IMMUTABLE' : undefined,
});

resource.applyRemovalPolicy(props.removalPolicy);
Expand Down
37 changes: 37 additions & 0 deletions packages/@aws-cdk/aws-ecr/test/test.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,43 @@ export = {
test.done();
},

'repository creation with tag immutablility is enabled'(test: Test) {
// GIVEN
const stack = new cdk.Stack();

// WHEN
new ecr.Repository(stack, 'Repo', { imageTagImmutable: true });

// THEN
expect(stack).to(haveResource('AWS::ECR::Repository', {
ImageTagMutability: 'IMMUTABLE',
}));

test.done();
},

'repository creation with tag immutablility is disabled'(test: Test) {
// GIVEN
const stack = new cdk.Stack();

// WHEN
new ecr.Repository(stack, 'Repo', { imageTagImmutable: false });

// THEN
// TODO: Is it possible to specify a field is absent instead of specifying the full json here?
expect(stack).toMatch({
Resources: {
Repo02AC86CF: {
Type: 'AWS::ECR::Repository',
DeletionPolicy: 'Retain',
UpdateReplacePolicy: 'Retain',
},
},
});

test.done();
},

'tag-based lifecycle policy'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down
2 changes: 1 addition & 1 deletion packages/cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
"engines": {
"node": ">= 8.10.0"
}
}
}
2 changes: 1 addition & 1 deletion packages/decdk/test/fixture/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
"url": "https://aws.amazon.com"
},
"license": "Apache-2.0"
}
}
12 changes: 6 additions & 6 deletions tools/yarn-cling/test/test-fixture/package1/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "package1",
"version": "1.1.1",
"dependencies": {
"registrydependency1": "^1.2.3",
"package2": "2.2.2"
}
"name": "package1",
"version": "1.1.1",
"dependencies": {
"registrydependency1": "^1.2.3",
"package2": "2.2.2"
}
}
4 changes: 2 additions & 2 deletions tools/yarn-cling/test/test-fixture/package2/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "package2",
"version": "2.2.2"
"name": "package2",
"version": "2.2.2"
}
102 changes: 99 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,11 @@ anymatch@^3.0.3:
normalize-path "^3.0.0"
picomatch "^2.0.4"

app-root-path@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/app-root-path/-/app-root-path-2.2.1.tgz#d0df4a682ee408273583d43f6f79e9892624bc9a"
integrity sha512-91IFKeKk7FjfmezPKkwtaRvSpnUc4gDwPAjA1YZ9Gn0q0PPeW+vbeUsZuyDwjI7+QTHhcLen2v25fi/AmhvbJA==

append-transform@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/append-transform/-/append-transform-1.0.0.tgz#046a52ae582a228bd72f58acfbe2967c678759ab"
Expand Down Expand Up @@ -2294,6 +2299,21 @@ aws-sdk-mock@^5.1.0:
sinon "^9.0.1"
traverse "^0.6.6"

aws-sdk@^2.596.0:
version "2.806.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.806.0.tgz#5bd3ac07425ee34f5dc9dc40a38d78c49066a88f"
integrity sha512-kCrGfZyzZiS56qblXEzznkTi64ZbzhQGlbyEjDI9cIUjX4dA9IyqvNWUdJvUQoZmiEnObbuXMVrv7blJzT8uhQ==
dependencies:
buffer "4.9.2"
events "1.1.1"
ieee754 "1.1.13"
jmespath "0.15.0"
querystring "0.2.0"
sax "1.2.1"
url "0.10.3"
uuid "3.3.2"
xml2js "0.4.19"

aws-sdk@^2.637.0, aws-sdk@^2.804.0:
version "2.804.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.804.0.tgz#ff7e6f91b86b4878ec69e3de895c10eb8203fc4b"
Expand Down Expand Up @@ -3737,6 +3757,16 @@ dot-prop@^5.1.0:
dependencies:
is-obj "^2.0.0"

dotenv-json@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/dotenv-json/-/dotenv-json-1.0.0.tgz#fc7f672aafea04bed33818733b9f94662332815c"
integrity sha512-jAssr+6r4nKhKRudQ0HOzMskOFFi9+ubXWwmrSGJFgTvpjyPXCXsCsYbjif6mXp7uxA7xY3/LGaiTQukZzSbOQ==

dotenv@^8.0.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==

dotgitignore@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/dotgitignore/-/dotgitignore-2.1.0.tgz#a4b15a4e4ef3cf383598aaf1dfa4a04bcc089b7b"
Expand Down Expand Up @@ -3960,6 +3990,11 @@ escodegen@^1.14.1, escodegen@^1.8.1:
optionalDependencies:
source-map "~0.6.1"

eslint-config-standard@^14.1.1:
version "14.1.1"
resolved "https://registry.yarnpkg.com/eslint-config-standard/-/eslint-config-standard-14.1.1.tgz#830a8e44e7aef7de67464979ad06b406026c56ea"
integrity sha512-Z9B+VR+JIXRxz21udPTL9HpFMyoMUEeX1G251EQ6e05WD9aPVtVBn09XUmZ259wCMlCDmYDSZG62Hhm+ZTJcUg==

eslint-import-resolver-node@^0.3.4:
version "0.3.4"
resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.4.tgz#85ffa81942c25012d8231096ddf679c03042c717"
Expand Down Expand Up @@ -3987,6 +4022,14 @@ eslint-module-utils@^2.6.0:
debug "^2.6.9"
pkg-dir "^2.0.0"

eslint-plugin-es@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-es/-/eslint-plugin-es-3.0.1.tgz#75a7cdfdccddc0589934aeeb384175f221c57893"
integrity sha512-GUmAsJaN4Fc7Gbtl8uOBlayo2DqhwWvEzykMHSCZHU3XdJ+NSzzZcVhXh3VxX5icqQ+oQdIEawXX8xkR3mIFmQ==
dependencies:
eslint-utils "^2.0.0"
regexpp "^3.0.0"

eslint-plugin-import@^2.22.1:
version "2.22.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.22.1.tgz#0896c7e6a0cf44109a2d97b95903c2bb689d7702"
Expand All @@ -4006,11 +4049,33 @@ eslint-plugin-import@^2.22.1:
resolve "^1.17.0"
tsconfig-paths "^3.9.0"

eslint-plugin-node@^11.1.0:
version "11.1.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-11.1.0.tgz#c95544416ee4ada26740a30474eefc5402dc671d"
integrity sha512-oUwtPJ1W0SKD0Tr+wqu92c5xuCeQqB3hSCHasn/ZgjFdA9iDGNkNf2Zi9ztY7X+hNuMib23LNGRm6+uN+KLE3g==
dependencies:
eslint-plugin-es "^3.0.0"
eslint-utils "^2.0.0"
ignore "^5.1.1"
minimatch "^3.0.4"
resolve "^1.10.1"
semver "^6.1.0"

eslint-plugin-promise@^4.2.1:
version "4.2.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-4.2.1.tgz#845fd8b2260ad8f82564c1222fce44ad71d9418a"
integrity sha512-VoM09vT7bfA7D+upt+FjeBO5eHIJQBUWki1aPvB+vbNiHS3+oGIJGIeyBtKQTME6UPXXy3vV07OL1tHd3ANuDw==

eslint-plugin-rulesdir@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-rulesdir/-/eslint-plugin-rulesdir-0.1.0.tgz#ad144d7e98464fda82963eff3fab331aecb2bf08"
integrity sha1-rRRNfphGT9qClj7/P6szGuyyvwg=

eslint-plugin-standard@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-standard/-/eslint-plugin-standard-4.1.0.tgz#0c3bf3a67e853f8bbbc580fb4945fbf16f41b7c5"
integrity sha512-ZL7+QRixjTR6/528YNGyDotyffm5OQst/sGxKDwGb9Uqs4In5Egi4+jbobhqJoyoCM6/7v/1A5fhQ7ScMtDjaQ==

eslint-scope@^5.0.0, eslint-scope@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c"
Expand Down Expand Up @@ -5121,7 +5186,7 @@ ignore@^4.0.3, ignore@^4.0.6:
resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc"
integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==

ignore@^5.1.4, ignore@^5.1.8, ignore@~5.1.8:
ignore@^5.1.1, ignore@^5.1.4, ignore@^5.1.8, ignore@~5.1.8:
version "5.1.8"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.8.tgz#f150a8b50a34289b33e22f5889abd4d8016f0e57"
integrity sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==
Expand Down Expand Up @@ -5307,7 +5372,7 @@ is-ci@^2.0.0:
dependencies:
ci-info "^2.0.0"

is-core-module@^2.0.0:
is-core-module@^2.0.0, is-core-module@^2.1.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.2.0.tgz#97037ef3d52224d85163f5597b2b63d9afed981a"
integrity sha512-XRAfAdyyY5F5cOXn7hYQDqh2Xmii+DEfIcQGxK/uNwMHhIkPWO0g8msXcbzLe+MpGoR951MlqM/2iIlU4vKDdQ==
Expand Down Expand Up @@ -6392,6 +6457,24 @@ kleur@^3.0.3:
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==

lambda-leak@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/lambda-leak/-/lambda-leak-2.0.0.tgz#771985d3628487f6e885afae2b54510dcfb2cd7e"
integrity sha1-dxmF02KEh/boha+uK1RRDc+yzX4=

lambda-tester@^3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/lambda-tester/-/lambda-tester-3.6.0.tgz#ceb7d4f4f0da768487a05cff37dcd088508b5247"
integrity sha512-F2ZTGWCLyIR95o/jWK46V/WnOCFAEUG/m/V7/CLhPJ7PCM+pror1rZ6ujP3TkItSGxUfpJi0kqwidw+M/nEqWw==
dependencies:
app-root-path "^2.2.1"
dotenv "^8.0.0"
dotenv-json "^1.0.0"
lambda-leak "^2.0.0"
semver "^6.1.1"
uuid "^3.3.2"
vandium-utils "^1.1.1"

lazystream@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/lazystream/-/lazystream-1.0.0.tgz#f6995fe0f820392f61396be89462407bb77168e4"
Expand Down Expand Up @@ -8567,6 +8650,14 @@ resolve@^1.1.6, resolve@^1.10.0, resolve@^1.11.1, resolve@^1.13.1, resolve@^1.17
dependencies:
path-parse "^1.0.6"

resolve@^1.10.1:
version "1.19.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.19.0.tgz#1af5bf630409734a067cae29318aac7fa29a267c"
integrity sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==
dependencies:
is-core-module "^2.1.0"
path-parse "^1.0.6"

resolve@^1.18.1:
version "1.18.1"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.18.1.tgz#018fcb2c5b207d2a6424aee361c5a266da8f4130"
Expand Down Expand Up @@ -8724,7 +8815,7 @@ semver@7.x, semver@^7.1.1, semver@^7.2.1, semver@^7.3.2:
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938"
integrity sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==

semver@^6.0.0, semver@^6.2.0, semver@^6.3.0:
semver@^6.0.0, semver@^6.1.0, semver@^6.1.1, semver@^6.2.0, semver@^6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
Expand Down Expand Up @@ -10095,6 +10186,11 @@ validate-npm-package-name@^3.0.0:
dependencies:
builtins "^1.0.3"

vandium-utils@^1.1.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/vandium-utils/-/vandium-utils-1.2.0.tgz#44735de4b7641a05de59ebe945f174e582db4f59"
integrity sha1-RHNd5LdkGgXeWevpRfF05YLbT1k=

verror@1.10.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/verror/-/verror-1.10.0.tgz#3a105ca17053af55d6e270c1f8288682e18da400"
Expand Down