Dockertools¶
Functions for creating the Dockerfile or asset files.
- concoursetools.dockertools.create_script_file(path, resource_class, method_name, executable='/usr/bin/env python3', permissions=493, encoding=None)[source]¶
Create a script file at a given path.
- Parameters:
path (
Path) – The path at which the file will be created.resource_class (
type[ConcourseResource[Any]]) – TheConcourseResourceclass to be exported.method_name (
Literal['check_main','in_main','out_main']) – The name of the method to be invoked.executable (
str) – The executable to use for the script (at the top).permissions (
int) – The (Linux) permissions the file should have. Defaults torwxr-xr-x.encoding (
str|None) – The encoding of the file as passed towrite_text(). Setting toNone(default) will use the user’s default encoding.
- Return type:
Dockerfile¶
For easier dynamic creation of Dockerfiles, the module contains a number of
Instruction classes:
A Comment class is also included:
- class concoursetools.dockertools.Comment(comment)[source]¶
Represents a comment in a Dockerfile.
- Comment:
The comment to be added.
- Example:
>>> print(Comment("This is a comment")) # This is a comment
- Parameters:
comment (
str)
All instructions and comments are added to a A Dockerfile instance
in instruction groups:
- class concoursetools.dockertools.Dockerfile(instruction_groups=None)[source]¶
Represents the contents of a Dockerfile.
- Parameters:
instruction_groups (
list[list[Instruction|Comment]] |None) – A list of lists of instructions or comments. Separation between groups is larger than between instructions within the group to imply sections to the Dockerfile.
- new_instruction_group(*instructions)[source]¶
Add instructions to a new instruction group within the Dockerfile.
- Parameters:
instructions (
Instruction|Comment) – Instructions or comments to add to the new group.- Return type:
Dockerfile Instructions¶
All currently relevant instructions have been implemented:
Instruction |
Description |
Classes |
|---|---|---|
|
Add local or remote files and directories. |
|
|
Use build-time variables. |
|
|
Specify default commands. |
|
|
Copy files and directories. |
|
|
Specify default executable. |
|
|
Set environment variables. |
|
|
Describe which ports your application is listening on. |
|
|
Check a container’s health on startup. |
|
|
Check a container’s health on startup. |
|
|
Add metadata to an image. |
|
|
Specify the author of an image. |
|
|
Specify instructions for when the image is used in a build. |
|
|
Execute build commands. |
|
|
Set the default shell of an image. |
|
|
Specify the system call signal for exiting a container. |
|
|
Set user and group ID. |
|
|
Create volume mounts. |
|
|
Change working directory. |
- class concoursetools.dockertools.CopyInstruction(source, dest=None)[source]¶
Represents a
COPYinstruction.- Parameters:
- Example:
>>> print(CopyInstruction("folder/file.txt")) COPY folder/file.txt file.txt >>> print(CopyInstruction("folder/file.txt", "folder/new_file.txt")) COPY folder/file.txt folder/new_file.txt
- class concoursetools.dockertools.EntryPointInstruction(commands)[source]¶
Represents an
ENTRYPOINTinstruction.Note
Docker recommends the “exec” form of this instruction over the “shell” form, and so the former is used here.
- class concoursetools.dockertools.FromInstruction(image, tag=None, digest=None, platform=None)[source]¶
Represents a
FROMinstruction.- Parameters:
- Example:
>>> print(FromInstruction("python")) FROM python >>> print(FromInstruction("python", tag="3.11-slim")) FROM python:3.11-slim >>> print(FromInstruction("python", digest="sha256:380094...")) FROM python@sha256:380094... >>> print(FromInstruction("python", tag="3.11-slim", platform="linux/386")) FROM --platform=linux/386 python:3.11-slim
- class concoursetools.dockertools.RunInstruction(commands)[source]¶
Represents a
RUNinstruction.Note
The
shellform of this command is more common than theexecform, so the former is used.- Parameters:
- Example:
>>> print(RunInstruction(["pip install --upgrade pip"])) RUN pip install --upgrade pip >>> print(RunInstruction(["pip install --upgrade pip", "pip install -r requirements.txt"])) RUN pip install --upgrade pip && pip install -r requirements.txt
- class concoursetools.dockertools.MultiLineRunInstruction(commands, mounts=None)[source]¶
Represents a
RUNinstruction which will be split across multiple lines.- Parameters:
- Example:
>>> print(MultiLineRunInstruction( ... ["pip install --upgrade pip", "pip install -r requirements.txt"] ... )) RUN \ pip install --upgrade pip && \ pip install -r requirements.txt >>> print(MultiLineRunInstruction( ... ["pip install --upgrade pip", "pip install -r requirements.txt"], ... [SecretMount(secret_id="aws", target="/root/.aws/credentials")] ... )) RUN \ --mount=type=secret,id=aws,target=/root/.aws/credentials \ pip install --upgrade pip && \ pip install -r requirements.txt
Dockerfile Mounts¶
The module also implements some mounts for the RUN step to facilitate secrets:
All currently relevant mount types have been implemented:
Mount |
Description |
Classes |
|---|---|---|
|
Bind-mount context directories (read-only). |
|
|
Mount a temporary directory to cache directories for compilers and package managers. |
|
|
Mount a |
|
|
Allow the build container to access secure files such as private keys without baking them into the image or build cache. |
|
|
Allow the build container to access SSH keys via SSH agents, with support for passphrases. |
- class concoursetools.dockertools.SecretMount(secret_id=None, target=None, required=None, mode=None, user_id=None, group_id=None)[source]¶
Represents a mounted secret value.
- Parameters:
- Example:
>>> print(SecretMount(secret_id="aws", target="/root/.aws/credentials")) --mount=type=secret,id=aws,target=/root/.aws/credentials