Skip to content

Commit bcc100e

Browse files
authored
Feat/environment agnostic custom images references (#623)
* fix documentation error for codebuild custom inage * environment agnostic custom codebuild image configuration * ecr policies for codebuild * applying suggested changes in the review * Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_constructs/adf_codebuild.py * Add updated CodeBuild ECR Provider docs --------- Co-authored-by: Abhijit Co-authored-by: Simon Kok Co-authored-by: AndyEfaa
1 parent 95b92ff commit bcc100e

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

docs/providers-guide.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,23 +254,40 @@ Provider type: `codebuild`.
254254

255255
#### Properties
256256

257-
- *image* *(String)* - default: `STANDARD_7_0`.
257+
- *image* *(String|Object)* - default: `STANDARD_7_0`.
258258
- The Image that the AWS CodeBuild will use. Images can be found
259259
[here](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-codebuild.LinuxBuildImage.html).
260-
- Image can also take an object that contains a property key of
261-
`repository_arn` which is the repository ARN of an ECR repository on the
262-
deployment account within the main deployment region. This allows your
263-
pipeline to consume a custom image if required.
264-
- Along with `repository_arn`, we also support a `tag` key which can be used
265-
to define which image should be used (defaults to `latest`). An example of
266-
this setup is provided [here](user-guide.md#custom-build-images).
267260
- Image can also take an object that contains a reference to a public docker
268261
hub image with a prefix of `docker-hub://`, such as
269262
`docker-hub://bitnami/mongodb`. This allows your pipeline to consume a
270263
public docker hub image if required. Along with the docker hub image name,
271264
we also support using a tag which can be provided after the docker hub image
272265
name such as `docker-hub://bitnami/mongodb:3.6.23` in order to define which
273266
image should be used (defaults to `latest`).
267+
- For images hosted in Amazon ECR, you can define the repository and image to
268+
use by specifying an image object.
269+
This allows your pipeline to consume a custom image if required.
270+
For example, to configure a specific repository ARN, configure it as:
271+
272+
```yaml
273+
image:
274+
repository_arn: 'arn:${partition}:ecr:${region}:${source_account_id}:repository/your-repo-name'
275+
tag: 'latest' # Optional, defaults to latest
276+
```
277+
278+
Alternatively, you can set the `repository_name` if the ECR is hosted in
279+
the deployment account in the main deployment region.
280+
281+
```yaml
282+
image:
283+
repository_name: 'your-repo-name'
284+
tag: 'latest' # Optional, defaults to latest
285+
```
286+
287+
Along with `repository_arn` or `repository_name`, we also support a `tag`
288+
key. This can be used to define which image should be used
289+
(defaults to `latest`). An example of this setup is provided
290+
[here](user-guide.md#custom-build-images).
274291
- *size* *(String)* **(small|medium|large)** - default: `small`.
275292
- The Compute type to use for the build, types can be found
276293
[here](https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-compute-types.html).

src/lambda_codebase/initial_commit/bootstrap_repository/adf-bootstrap/deployment/global.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ Resources:
358358
- "ecr:CompleteLayerUpload"
359359
- "ecr:BatchCheckLayerAvailability"
360360
- "ecr:PutImage"
361+
- "ecr:BatchGetImage"
362+
- "ecr:GetDownloadUrlForLayer"
361363
Resource:
362364
- "*"
363365
- Effect: Allow

src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_constructs/adf_codebuild.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,30 @@ def determine_build_image(codebuild_id, scope, target, map_params):
375375
.get('image')
376376
)
377377
if isinstance(specific_image, dict):
378-
repo_arn = _ecr.Repository.from_repository_arn(
378+
repository_name = specific_image.get('repository_name', '')
379+
repository_arn = specific_image.get('repository_arn', '')
380+
if not repository_arn and not repository_name:
381+
raise ValueError("The repository arn or name needs to be specified")
382+
383+
if repository_arn and repository_name:
384+
raise AssertionError("Specify the arn or the name of the repository, not both.")
385+
386+
if repository_name:
387+
repository_arn = (
388+
f"arn:aws:ecr:{ADF_DEPLOYMENT_REGION}:"
389+
f"{ADF_DEPLOYMENT_ACCOUNT_ID}:{repository_name}"
390+
)
391+
392+
ecr_repo = _ecr.Repository.from_repository_arn(
379393
scope,
380394
f'custom_repo_{codebuild_id}',
381-
specific_image.get('repository_arn', ''),
395+
repository_arn,
382396
)
383397
return _codebuild.LinuxBuildImage.from_ecr_repository(
384-
repo_arn,
398+
ecr_repo,
385399
specific_image.get('tag', 'latest'),
386400
)
401+
387402
return CodeBuild.get_image_by_name(specific_image)
388403

389404
@staticmethod

src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python/schema_validation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@
117117

118118
# CodeBuild
119119
CODEBUILD_IMAGE_PROPS = {
120-
"repository_arn": str, # arn:aws:ecr:region:111111111111:repository/test
120+
Optional("repository_arn"): str, # arn:aws:ecr:region:111111111111:repository/test
121+
Optional("repository_name"): str, # hello-world
121122
Optional("tag"): str, # defaults to latest
122123
}
123124
CODEBUILD_PROPS = {

0 commit comments

Comments
 (0)