Commit ed2f75db authored by Thibault Coupin's avatar Thibault Coupin Committed by Thomas Boni
Browse files

Docker: Allows context different from root

parent b086bfd9
Loading
Loading
Loading
Loading
+20 −18
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ from a Dockerfile at the root of your project, and push it to a remote registry
The registry and tag of the resulting Docker image follow this behavior:

| `CUSTOM_TAG` used ? | Are you pushing git tag ? | Registry where image is pushed | Docker tag applied to the image |
|:-|:-|:-|:-
|:--------------------|:--------------------------|:-------------------------------|:--------------------------------|
| No                  | No                        | Gitlab project registry        | Last commit SHA                 |
| No                  | Yes                       | Gitlab project registry        | Git tag name                    |
| Yes                 | No                        | Gitlab project registry        | `CUSTOM_TAG`                    |
@@ -49,11 +49,12 @@ The registry and tag of the resulting Docker image follow this behavior:
### Variables

| VARIABLE NAME                    | DESCRIPTION                                                                                                                                                                          | DEFAULT VALUE |
|:-|:-|:-
|:---------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------------|
| `CUSTOM_TAG`                     | If you want a specific tag for your image                                                                                                                                            | ` `           |
| `COMMIT_CREATE_LATEST`           | In a commit context, also update `latest` tag                                                                                                                                        | `false`       |
| `TAG_CREATE_LATEST`              | In a tag context, also update `latest` tag                                                                                                                                           | `true`        |
| `DOCKERFILE_PATH` | Path to Dockerfile from the repository root | `Dockerfile` |
| `DOCKER_CONTEXT_PATH`            | Path of build context from to repository root                                                                                                                                        | ` `           |
| `DOCKERFILE_PATH`                | Path to Dockerfile from the build context (see `DOCKER_CONTEXT_PATH`)                                                                                                                | `Dockerfile`  |
| `DOCKER_USE_CACHE`               | Cache Dockerfile layers. Cached layers are stored in the [container registry](https://docs.gitlab.com/ee/user/packages/container_registry/){:target="_blank"} in `/cache` repository | `false`       |
| `DOCKER_CACHE_TTL`               | Cached layers TTL                                                                                                                                                                    | `336h`        |
| `KANIKO_USE_NEWRUN`              | Enable Kaniko option [`--use-new-run`](https://github.com/GoogleContainerTools/kaniko#--use-new-run)                                                                                 | `true`        |
@@ -67,6 +68,7 @@ The registry and tag of the resulting Docker image follow this behavior:
    --destination registry.hub.docker.com/admin/myimages:latest --destination containerregistry.azurecr.io/admin/myimages:1.6.9-lite
    ```


* Example of file `CONFIG_FILE`:
    ```json
    {"auths":
+6 −3
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ docker_build:
  variables:
    CUSTOM_REGISTRIES_DESTINATIONS: ""
    CONFIG_FILE: ""
    DOCKER_CONTEXT_PATH: ""
    
    CUSTOM_TAG: ""
    COMMIT_CREATE_LATEST: "false"
@@ -47,17 +48,19 @@ docker_build:
    -   DOCKER_OPTIONS="--use-new-run ${DOCKER_OPTIONS}"
    - fi

    - DOCKER_CONTEXT_PATH=${CI_PROJECT_DIR}/${DOCKER_CONTEXT_PATH}

    - DOCKER_OPTIONS="--verbosity=${DOCKER_VERBOSITY} ${DOCKER_OPTIONS}"

    - if [ ! -z "$CUSTOM_REGISTRIES_DESTINATIONS" ]; then
    -   cp -rf $CONFIG_FILE /kaniko/.docker/config.json
    -   DOCKER_OPTIONS="${DOCKER_OPTIONS} $CUSTOM_REGISTRIES_DESTINATIONS"
    -   /kaniko/executor --context ${CI_PROJECT_DIR} --dockerfile ${CI_PROJECT_DIR}/${DOCKERFILE_PATH} ${DOCKER_OPTIONS}
    -   /kaniko/executor --context ${DOCKER_CONTEXT_PATH} --dockerfile ${DOCKER_CONTEXT_PATH}/${DOCKERFILE_PATH} ${DOCKER_OPTIONS}
    - else
    -   echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
    -     if [ ! -z ${CUSTOM_TAG} ]; then
    -       /kaniko/executor --context ${CI_PROJECT_DIR} --dockerfile ${CI_PROJECT_DIR}/${DOCKERFILE_PATH} --destination ${CI_REGISTRY_IMAGE}:${CUSTOM_TAG} ${DOCKER_OPTIONS}
    -       /kaniko/executor --context ${DOCKER_CONTEXT_PATH} --dockerfile ${DOCKER_CONTEXT_PATH}/${DOCKERFILE_PATH} --destination ${CI_REGISTRY_IMAGE}:${CUSTOM_TAG} ${DOCKER_OPTIONS}
    -     else
    -       /kaniko/executor --context ${CI_PROJECT_DIR} --dockerfile ${CI_PROJECT_DIR}/${DOCKERFILE_PATH} --destination ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} ${OPTIONAL_TAG} ${DOCKER_OPTIONS}
    -       /kaniko/executor --context ${DOCKER_CONTEXT_PATH} --dockerfile ${DOCKER_CONTEXT_PATH}/${DOCKERFILE_PATH} --destination ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} ${OPTIONAL_TAG} ${DOCKER_OPTIONS}
    -     fi
    - fi
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
* Allows context different from root with new variable `DOCKER_CONTEXT_PATH`
 No newline at end of file