Namespace src/Docker
src/Docker
Overview
checkout usage doc below
Docker::buildImage
try to docker build image from eventual tagged image cache
- Using DOCKER_BUILDKIT=1
- Using BUILDKIT_INLINE_CACHE in order to use the resulting image as a cache source
You can specify cacheFrom options using the method Docker::getBuildCacheFromArg
Example
## notice that there is no double quotes around $(Docker::getBuildCacheFromArg bash-tools:tag1 bash-tools:tag2)
Docker::buildImage "." "Dockerfile" "bash-tools" $(Docker::getBuildCacheFromArg bash-tools:tag1 bash-tools:tag2)
Arguments
- $1 (buildDirectory:String): base directory from where Dockerfile will take hits resources
- $2 (dockerFilePath:String): docker file path
- $3 (localImageName:String): the local image name of the resulting image (eg: in ubuntu:latest, ubuntu is the image name
- … (dockerBuildParams:String[]): rest of the parameters to pass to docker build method
Exit codes
- 1: if buildDirectory does not exists
- 2: if dockerFilePath does not exists
- 3: if empty or invalid localImageName
Output on stdout
- {String} the tag that has been successfully pulled, return 1 if no
Output on stderr
- diagnostics information is displayed
Requires
- Docker::requireDockerCommand
See also
src/Docker/buildPushDockerImage.sh
file source src/Docker/buildPushDockerImage.sh
Docker::buildPushDockerImage
build image and push it to registry
Environment variables
- DOCKER_OPTION_IMAGE_TAG (String): computed from optionVendor and optionBashVersion if not provided
- DOCKER_OPTION_IMAGE (String): default scrasnups/${DOCKER_OPTION_IMAGE_TAG}
- DOCKER_BUILD_OPTIONS (String): list of docker arguments to pass to docker build command
- FRAMEWORK_ROOT_DIR (String): path allowing to deduce .docker/Dockerfile.{vendor}
src/Docker/getBuildCacheFromArg.sh
file source src/Docker/getBuildCacheFromArg.sh
Docker::getBuildCacheFromArg
generate list of –cache-from arg to pass to docker build
Arguments
- … (tags:String[]): list of tags to use as cache
Output on stdout
- string representing arguments to pass to Docker::buildImage to build image using cache
Requires
- Docker::requireDockerCommand
See also
src/Docker/getRemoteTag.sh
file source src/Docker/getRemoteTag.sh
Docker::getRemoteTag
generates a string representing a docker remote tag
Example
id.dkr.ecr.eu-west-1.amazonaws.com/bash-tools:v1.0.0
@arg $1 remoteUrl:String eg: id.dkr.ecr.eu-west-1.amazonaws.com
@arg $2 imageName:String eg: bash-tools
@arg $3 tag:String the tag to retrieve (eg: v1.0.0)
@stdout a string representing a docker remote tag
@require Docker::requireDockerCommand
src/Docker/getTagCompatibleFromBranch.sh
file source src/Docker/getTagCompatibleFromBranch.sh
Docker::getTagCompatibleFromBranch
generates a string compatible with docker tag format Eg: transforms origin/feature/My-beautiful-feature to feature_my_beautiful_feature
Arguments
- $1 (separator:String): replace / by separator (Default value: ‘_’)
Input on stdin
- the name of the branch
Output on stdout
- a string compatible with docker tag format
Requires
- Docker::requireDockerCommand
src/Docker/imageExists.sh
file source src/Docker/imageExists.sh
Docker::imageExists
Check if image is tagged on docker registry best practice: provide tags ’tagPrefix_shortSha’ ’tagPrefix_branchName' so image will be tagged with
- tagPrefix_shortSha
- tagPrefix_branchName
Arguments
- $1 (registryImageUrl:String): eg:889859566884.dkr.ecr.eu-west-1.amazonaws.com/bast-tools-dev-env
- … (tags:String[]): list of tags used to check if image exists on docker registry
Exit codes
- 1: if at least one tag does not exist
Output on stderr
- diagnostics information is displayed
Requires
- Docker::requireDockerCommand
src/Docker/pullImage.sh
file source src/Docker/pullImage.sh
Docker::pullImage
try to docker pull image from pullTags arg best practice: provide tags ’tagPrefix_shortSha’ ’tagPrefix_branchName' so image will be tagged with
- tagPrefix_shortSha
- tagPrefix_branchName
Arguments
- $1 (registryImageUrl:String): eg:889859566884.dkr.ecr.eu-west-1.amazonaws.com/bast-tools-dev-env
- … (tags:String[]): list of tags used to pull image from docker registry
Exit codes
- 1: if tags list is empty or on on invalid argument
- 2: if no image pulled
Output on stdout
- {String} the tag that has been successfully pulled, return 1 if none
Output on stderr
- diagnostics information is displayed
Requires
- Docker::requireDockerCommand
src/Docker/pushImage.sh
file source src/Docker/pushImage.sh
Docker::pushImage
push tagged docker image to docker registry best practice: provide tags ’tagPrefix_shortSha’ ’tagPrefix_branchName' so image will be tagged with
- tagPrefix_shortSha
- tagPrefix_branchName
Arguments
- $1 (registryImageUrl:String): eg:889859566884.dkr.ecr.eu-west-1.amazonaws.com/bast-tools-dev-env
- … (tags:String[]): list of tags used to push image to docker registry
Exit codes
- 1: if tags list is empty
Output on stderr
- diagnostics information is displayed
Requires
- Docker::requireDockerCommand
See also
src/Docker/requireDockerCommand.sh
file source src/Docker/requireDockerCommand.sh
Docker::requireDockerCommand
ensure command docker is available
Exit codes
- 1: if docker command not available
Output on stderr
- diagnostics information is displayed
src/Docker/requireDockerComposeCommand.sh
file source src/Docker/requireDockerComposeCommand.sh
Docker::requireDockerComposeCommand
ensure command docker-compose is available
Exit codes
- 1: if docker-compose command not available
Output on stderr
- diagnostics information is displayed
src/Docker/tagImage.sh
file source src/Docker/tagImage.sh
Docker::tagImage
Image built is tagged with tags provided best practice: provide tags ’tagPrefix_shortSha’ ’tagPrefix_branchName' so image will be tagged with
- tagPrefix_shortSha
- tagPrefix_branchName
Arguments
- $1 (registryImageUrl:String): eg:889859566884.dkr.ecr.eu-west-1.amazonaws.com/bast-tools-dev-env
- $2 (localTag:String): the docker image local tag that needs to be remotely tagged (eg: bash-tools:latest)
- … (tags:String[]): list of tags used to push image to docker registry
Exit codes
- 1: if tags list is empty
Requires
- Docker::requireDockerCommand
src/Docker/testContainer.sh
file source src/Docker/testContainer.sh
Docker::testContainer
Test if a container launched by docker-compose is reachable docker-compose will be up and shutdown at the end of the process if success or not
Arguments
- $1 (dir:String): the directory that contains the docker-compose.yml file
- $2 (containerName:String): name of the container that is tested
- $3 (title:String): a title that allows to discriminate the log lines
- $4 (testCallback:Function): a function callback that will be called to check the container
Exit codes
- 1: if directory does not exists
- 2: on container test failure
- 3: on
failure - 4: if testCallBack is not a function
Requires
- Docker::requireDockerCommand