diff --git a/docs/providers-guide.md b/docs/providers-guide.md index dcab56f4e..2ba6210b4 100644 --- a/docs/providers-guide.md +++ b/docs/providers-guide.md @@ -231,6 +231,14 @@ Provider type: `codebuild`. > Along with `repository_arn`, we also support a `tag` key which can be used > to define which image should be used (defaults to `latest`). > An example of this setup is provided [here](https://github.com/awslabs/aws-deployment-framework/blob/master/docs/user-guide.md#custom-build-images). + > + > Image can also take an object that contains a reference to a + > public docker hub image with a prefix of `docker-hub://`, such as + > `docker-hub://bitnami/mongodb`. This allows your pipeline + > to consume a public docker hub image if required. + > Along with the docker hub image name, we also support using a tag which can + > be provided after the docker hub image name such as `docker-hub://bitnami/mongodb:3.6.23` + > in order to define which image should be used (defaults to `latest`). - *size* *(String)* **(small|medium|large)** - default: `small`. > The Compute type to use for the build, types can be found > [here](https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-compute-types.html). diff --git a/docs/user-guide.md b/docs/user-guide.md index 97337c452..0d238e646 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -319,6 +319,22 @@ pipelines: - ... ``` +Public images from docker hub can be defined in your deployment map like so: + +```yaml +pipelines: + - name: example-custom-image + default_providers: + source: + ... + build: + provider: codebuild + properties: + image: docker-hub://bitnami/mongodb + targets: + - ... +``` + ### CloudFormation Parameters and Tagging When you define CloudFormation templates as artifacts to push through a pipeline you might want to have a set of parameters associated with the templates. You can utilize the `params` folder in your repository to add in parameters as you see fit. To avoid having to create a parameter file for each of the stacks you wish to deploy to, you can create a parameter file called `global.yml` *(or .json)* any parameters defined in this file will be merged into the parameters for any specific account parameter file at build time. For example you might have a single parameter for a template called `CostCenter` the value of this will be the same across every deployment of your application however you might have another parameter called `InstanceType` that you want to be different per account. Using this example we can create a `global.yml` file that contains the following content: diff --git a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_constructs/adf_codebuild.py b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_constructs/adf_codebuild.py index 1729425c1..4c30b2a5b 100644 --- a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_constructs/adf_codebuild.py +++ b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_constructs/adf_codebuild.py @@ -160,6 +160,21 @@ def determine_build_spec(codebuild_id, default_props, target=None): ), ) + @staticmethod + def get_image_by_name(specific_image: str): + if hasattr(_codebuild.LinuxBuildImage, + (specific_image or DEFAULT_CODEBUILD_IMAGE).upper()): + return getattr(_codebuild.LinuxBuildImage, + (specific_image or DEFAULT_CODEBUILD_IMAGE).upper()) + if specific_image.startswith('docker-hub://'): + specific_image = specific_image.split('docker-hub://')[-1] + return _codebuild.LinuxBuildImage.from_docker_registry(specific_image) + raise Exception( + "The CodeBuild image {0} could not be found.".format( + specific_image + ), + ) + @staticmethod def determine_build_image(scope, target, map_params): specific_image = None @@ -184,10 +199,7 @@ def determine_build_image(scope, target, map_params): repo_arn, specific_image.get('tag', 'latest'), ) - return getattr( - _codebuild.LinuxBuildImage, - (specific_image or DEFAULT_CODEBUILD_IMAGE).upper(), - ) + return CodeBuild.get_image_by_name(specific_image) @staticmethod def generate_build_env_variables(codebuild, shared_modules_bucket, map_params, target=None):