Skip to content

Commit 9773b34

Browse files
committed
Add support for defining a custom build_context when devlab is building images
1 parent 44bb642 commit 9773b34

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ The structure looks like this:
240240
{
241241
"tag": ""|[],
242242
"docker_file": "",
243+
"build_context": "",
243244
"build_opts": [],
244245
"skip_pull": BOOL,
245246
"ordinal": {
@@ -253,7 +254,8 @@ All Keys that are in **bold** are required
253254
| Key | Type | Value Description |
254255
| --- | --- | --- |
255256
| **tag** | String or List of Strings | This is a tag that should be applied to the image. If a list is passed, the first tag becomes a primary identifier. |
256-
| **docker_file** | String | Path to the docker file, relative to the project's root to use when building the image. ***[NOTE]*** The build context will be the parent directory of the dockerfile's path |
257+
| **docker_file** | String | Path to the docker file, relative to the project's root to use when building the image. ***[NOTE]*** If `build_context` is NOT set then the build context will be the parent directory of the dockerfile's path |
258+
| build_context | String | Path (relative to the project) for the docker build command to run. This sets the docker build context, so will affect COPY commands in dockerfiles etc... Remember that this path and all files have to be copied/sent to the docker daemon, so be careful of the size of the directory you set here |
257259
| build_opts | List of Strings | Additional options to pass to the `docker build` command. Each CLI arg must be it's own element. For example: `[ '--build-arg', 'foo=bar' ]` would become `docker build --build-arg foo=bar PATH...` etc... |
258260
| skip_pull | Boolean | Whether or not a forced pull does anything. There are cases where an image is built locally used elsewhere, so a pull will fail since it isn't on docker hub. If this is `true`, then even when a build is requesting a `pull` it will skip it for this image |
259261
| ordinal | Hash | This is used indicate the order of the images to build. When parallel execution is supported, the `group` key indicates the image that can be built at the same time, `number` indicates the order inside the group to start up |

devlab_bench/actions/build.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ def action(images='*', clean=False, no_cache=False, pull=False, skip_pull_images
9999
else:
100100
image_n_tag = '{}:{}'.format(image, images_dict[image]['tag'])
101101
image_status = docker_obj_status(image_n_tag, 'image', devlab_bench.helpers.docker.DOCKER, logger=log)[0]
102-
image_context = os.path.dirname('{}/{}'.format(devlab_bench.PROJ_ROOT, images_dict[image]['docker_file']))
102+
image_context = images_dict[image].get(
103+
'build_context',
104+
os.path.dirname('{}/{}'.format(devlab_bench.PROJ_ROOT, images_dict[image]['docker_file']))
105+
)
103106
docker_helper_obj = docker_helper
104107
build_context = devlab_bench.PROJ_ROOT
105108
if image in base_images_to_build: #Override default build context for built-in images

0 commit comments

Comments
 (0)