Docker
Prerequisites
Eligible images
|
We suppose two main CI/CD scenarios for Docker:
Automated Docker builds: All image dependencies already exist and all you need is to build and publish a Docker image.
Creating dependencies before the build: An Automation job must create image dependencies before building and publishing the image.
Space Automation DSL provides a special docker
keyword that simplifies working with Docker builds.
Build and publish a Docker image
For example, the job below first builds and then publishes the image defined in the Dockerfile
located in the project's docker
directory.
docker
: is a special step used to build and publish Docker images. In fact, it's a special type of container with Docker on board.build
: runs thedocker build
command with the following argumentscontext
: a path to Docker context (by default, it's a working directory ). The build process can refer to any of the files in the context.file
: a path toDockerfile
.args
: sets build-time variables.labels
: sets labels for the image.
push
: runs thedocker push
command with the following arguments"mycompany.registry.jetbrains.space/mydocker/myimage"
: image name including the repository URL. Note that to be able to push to a Space Packages Container registry, your script doesn't require authentication.tag
: specifies the image tag.
Create an image dependency, build, and publish a Docker image
Quite often, you may need to first generate some artifact (say, a .jar file) and then put it into an image. Such cases require running two steps: The first generates the artifact and the second one runs docker build
and docker push
.
The
container
step usesgradlew build
to generate some artifacts and put them to the file share.In the
docker
step:resources
specifies system resources as in a regular container.beforeBuildScript
is a sub-step that runs beforebuild
. Here we usebeforeBuildScript
to copy the Gradle output from the file share to the context directory.build
andpush
build and push the image correspondingly.