Next: , Previous: , Up: API  


1.2 (maak container)

Container helpers for the two engines a Linux machine is likely to have. Podman and Docker share almost all of their command line, so a task written against one should not have to be rewritten for the other: the engine is a parameter, detected once from PATH and overridable per call or with MAAK_CONTAINER_ENGINE.

The same is true of Compose, with one extra wrinkle: Podman has both ‘podman compose‘ and the older ‘podman-compose‘, so the compose program is a parameter of its own. MAAK_COMPOSE names it, and a call can pass ‘#:program‘.

Every helper has an ‘-argv‘ builder next to it. The builder returns the list of words without running anything: that is what the procedures feed to ‘run‘, what –dry-run prints, and what a test can assert without needing a container runtime.

Nothing here starts a container as a side effect of loading the module.

1.2.1 Parameters

Parameter: container-compose-command

Default value:

("podman-compose")
Parameter: container-engine

Default value:

"podman"

1.2.2 Procedures

Procedure: compose-argv arguments KEY: #:program #:file #:project #:env-files #:profiles

Return the argv that runs Compose with ARGUMENTS.

FILE is –file, PROJECT is –project-name, ENV-FILES are passed as –env-file, and PROFILES as –profile. They come before the subcommand, which is where both Docker Compose and podman-compose expect them.

Procedure: compose-available? KEY: #:program

Return #t when the Compose PROGRAM can be found on PATH.

PROGRAM is the list of words container-compose-command returns; its first word is what is looked for.

Procedure: compose-build services KEY: #:program #:file #:project #:env-files #:profiles #:no-cache? #:pull? #:allow-failure? #:verbose?

Build SERVICES with Compose; see ‘compose-build-argv‘.

Procedure: compose-build-argv services KEY: #:program #:file #:project #:env-files #:profiles #:no-cache? #:pull?

Return the argv that builds SERVICES, or every service when it is empty.

Procedure: compose-config services KEY: #:program #:file #:project #:env-files #:profiles #:quiet? #:services? #:allow-failure? #:verbose?

Render the Compose configuration; see ‘compose-config-argv‘.

Procedure: compose-config-argv services KEY: #:program #:file #:project #:env-files #:profiles #:quiet? #:services?

Return the argv that renders the resolved Compose configuration.

QUIET? asks Compose to validate without printing; SERVICES? asks for only the service definitions, and the service names are passed as arguments when given. The quiet flag is spelled -q because that is the form both Compose implementations accept.

Procedure: compose-down services KEY: #:program #:file #:project #:env-files #:profiles #:volumes? #:remove-orphans? #:rmi #:timeout #:allow-failure? #:verbose?

Stop and remove SERVICES with Compose; see ‘compose-down-argv‘.

Procedure: compose-down-argv services KEY: #:program #:file #:project #:env-files #:profiles #:volumes? #:remove-orphans? #:rmi #:timeout

Return the argv that stops and removes SERVICES, or the whole project.

VOLUMES? also removes named volumes, which is what makes a test environment return to a clean state; it is off by default because the data is otherwise kept between runs.

Procedure: compose-exec service command KEY: #:program #:file #:project #:env-files #:profiles #:tty? #:user #:workdir #:index #:no-tty? #:allow-failure? #:verbose?

Run COMMAND in SERVICE with Compose; see ‘compose-exec-argv‘.

Procedure: compose-exec-argv service command KEY: #:program #:file #:project #:env-files #:profiles #:tty? #:user #:workdir #:index #:no-tty?

Return the argv that runs COMMAND in SERVICE.

NO-TTY? (the default) passes -T, which both Docker Compose and podman-compose spell the same way. A task needs it: without it Compose tries to allocate a terminal, and a command run from a pipeline or a CI job does not have one. TTY? asks for a terminal instead, and wins over the default: the two flags contradict each other, so only one is ever emitted. Pass #:no-tty? #f for an interactive shell that should not be told what to do either way.

Procedure: compose-logs services KEY: #:program #:file #:project #:env-files #:profiles #:follow? #:tail #:no-color? #:allow-failure?

Print the logs of SERVICES with Compose; see ‘compose-logs-argv‘.

Procedure: compose-logs-argv services KEY: #:program #:file #:project #:env-files #:profiles #:follow? #:tail #:no-color?

Return the argv that prints the logs of SERVICES, or of the whole project.

Procedure: compose-output arguments KEY: #:program #:file #:project #:env-files #:profiles #:allow-failure?

Run Compose with ARGUMENTS and return its output as a string.

Procedure: compose-ps services KEY: #:program #:file #:project #:env-files #:profiles #:all? #:format #:allow-failure?

List the containers of SERVICES with Compose; see ‘compose-ps-argv‘.

Procedure: compose-ps-argv services KEY: #:program #:file #:project #:env-files #:profiles #:all? #:format

Return the argv that lists the containers of SERVICES, or of the project.

ALL? is Docker Compose’s –all; podman-compose has no equivalent flag and lists the project’s containers already, so leave it off with that program.

Procedure: compose-pull services KEY: #:program #:file #:project #:env-files #:profiles #:ignore-pull-failures? #:allow-failure? #:verbose?

Pull the images of SERVICES with Compose; see ‘compose-pull-argv‘.

Procedure: compose-pull-argv services KEY: #:program #:file #:project #:env-files #:profiles #:ignore-pull-failures?

Return the argv that pulls the images of SERVICES.

IGNORE-PULL-FAILURES? is Docker Compose’s flag; podman-compose does not accept it, so leave it off with that program.

Procedure: compose-restart services KEY: #:program #:file #:project #:env-files #:profiles #:timeout #:allow-failure? #:verbose?

Restart SERVICES with Compose; see ‘compose-restart-argv‘.

Procedure: compose-restart-argv services KEY: #:program #:file #:project #:env-files #:profiles #:timeout

Return the argv that restarts SERVICES.

Procedure: compose-run service command KEY: #:program #:file #:project #:env-files #:profiles #:remove? #:no-deps? #:user #:workdir #:allow-failure? #:verbose?

Run COMMAND in a one-off container for SERVICE; see ‘compose-run-argv‘.

Procedure: compose-run-argv service command KEY: #:program #:file #:project #:env-files #:profiles #:remove? #:no-deps? #:user #:workdir

Return the argv that runs COMMAND in a one-off container for SERVICE.

REMOVE? (the default) passes –rm; NO-DEPS? keeps Compose from starting the service’s dependencies.

Procedure: compose-up services KEY: #:program #:file #:project #:env-files #:profiles #:detach? #:build? #:force-recreate? #:remove-orphans? #:no-start? #:wait? #:allow-failure? #:verbose?

Start SERVICES with Compose; see ‘compose-up-argv‘.

Procedure: compose-up-argv services KEY: #:program #:file #:project #:env-files #:profiles #:detach? #:build? #:force-recreate? #:remove-orphans? #:no-start? #:wait?

Return the argv that starts SERVICES, or every service when it is empty.

DETACH? (the default) is –detach, because a task that starts a stack wants its shell back. BUILD? rebuilds images, FORCE-RECREATE? replaces the containers, REMOVE-ORPHANS? is on by default, and WAIT? waits for the services to be healthy before returning.

Procedure: container arguments KEY: #:engine #:allow-failure? #:verbose?

Run ENGINE with ARGUMENTS, a list of strings.

The escape hatch for subcommands without a wrapper, such as ‘volume ls‘. Nothing is handed to a shell, so a label or a path with a space in it stays one argument.

Procedure: container-argv arguments KEY: #:engine

Return the argv that runs ENGINE with ARGUMENTS.

This is the shared shape of every helper below: the engine first, then the subcommand and its flags. It is exported because a subcommand without a wrapper is still a subcommand – pass ‘(list "volume" "ls")‘ and it works.

Procedure: container-available? KEY: #:engine

Return #t when ENGINE can be found on PATH.

Procedure: container-build context KEY: #:engine #:tag #:file #:target #:build-args #:labels #:no-cache? #:pull? #:platform #:network #:quiet? #:allow-failure? #:verbose?

Build the image described by CONTEXT; see ‘container-build-argv‘.

Procedure: container-build-argv context KEY: #:engine #:tag #:file #:target #:build-args #:labels #:no-cache? #:pull? #:platform #:network #:quiet?

Return the argv that builds the image described by CONTEXT.

TAG is –tag, FILE is –file, TARGET is –target, and BUILD-ARGS and LABELS are lists of strings. CONTEXT is the directory sent to the engine, normally the last argument.

Procedure: container-exec name command KEY: #:engine #:interactive? #:tty? #:env #:workdir #:user #:allow-failure? #:verbose?

Run COMMAND in the container NAME; see ‘container-exec-argv‘.

Procedure: container-exec-argv name command KEY: #:engine #:interactive? #:tty? #:env #:workdir #:user

Return the argv that runs COMMAND in the container NAME.

COMMAND is a list of strings. INTERACTIVE? and TTY? are the usual -i and -t; a non-interactive command needs neither, which is what a build step wants.

Procedure: container-images KEY: #:engine #:arguments #:allow-failure?

List images; see ‘container-images-argv‘.

Procedure: container-images-argv KEY: #:engine #:arguments

Return the argv that lists images, with any extra ARGUMENTS.

Procedure: container-inspect names KEY: #:engine #:format #:type #:allow-failure?

Inspect NAMES; see ‘container-inspect-argv‘.

Procedure: container-inspect-argv names KEY: #:engine #:format #:type

Return the argv that inspects NAMES.

FORMAT is passed as –format, which is how a task reads a field rather than the whole JSON document. TYPE is –type for engines that accept it.

Procedure: container-logs name KEY: #:engine #:follow? #:tail #:since #:allow-failure?

Print the logs of the container NAME; see ‘container-logs-argv‘.

Procedure: container-logs-argv name KEY: #:engine #:follow? #:tail #:since

Return the argv that prints the logs of the container NAME.

FOLLOW? is –follow; TAIL is a number or the word all, passed as –tail; SINCE is passed as –since.

Procedure: container-output arguments KEY: #:engine #:allow-failure?

Run ENGINE with ARGUMENTS and return its output as a string.

This is the reading counterpart of ‘container‘: the output is a value a task can trim and compare rather than a line on the terminal. In dry-run mode nothing runs, the command is printed, and the empty string comes back.

Procedure: container-ps KEY: #:engine #:all? #:allow-failure?

List containers; see ‘container-ps-argv‘.

Procedure: container-ps-argv KEY: #:engine #:all?

Return the argv that lists containers, including stopped ones with ALL?.

Procedure: container-pull image KEY: #:engine #:allow-failure?

Pull IMAGE; see ‘container-pull-argv‘.

Procedure: container-pull-argv image KEY: #:engine

Return the argv that pulls IMAGE.

Procedure: container-push image KEY: #:engine #:allow-failure?

Push IMAGE; see ‘container-push-argv‘.

Procedure: container-push-argv image KEY: #:engine

Return the argv that pushes IMAGE.

Procedure: container-rm names KEY: #:engine #:force? #:volumes? #:allow-failure?

Remove the containers NAMES; see ‘container-rm-argv‘.

Procedure: container-rm-argv names KEY: #:engine #:force? #:volumes?

Return the argv that removes the containers NAMES.

FORCE? is the default because a task that removes a container means it, and a running container would otherwise fail the whole task.

Procedure: container-run image KEY: #:engine #:command #:name #:detach? #:remove? #:interactive? #:tty? #:env #:publish #:volume #:mount #:workdir #:entrypoint #:network #:user #:platform #:pull #:labels #:privileged? #:allow-failure? #:verbose?

Run IMAGE as a container; see ‘container-run-argv‘ for the options.

Procedure: container-run-argv image KEY: #:engine #:command #:name #:detach? #:remove? #:interactive? #:tty? #:env #:publish #:volume #:mount #:workdir #:entrypoint #:network #:user #:platform #:pull #:labels #:privileged?

Return the argv that runs IMAGE as a container.

COMMAND is the list of arguments passed to the image, after its name. The defaults are the ones an unattended task wants: REMOVE? is #t, so a finished container leaves nothing behind, and nothing is attached to the terminal unless INTERACTIVE? or TTY? asks for it. ENV, PUBLISH, VOLUME, MOUNT and LABELS are lists of strings, each passed with its flag.

Procedure: container-stop names KEY: #:engine #:allow-failure?

Stop the containers NAMES, a list of strings.

Procedure: container-stop-argv names KEY: #:engine

Return the argv that stops the containers NAMES.

Procedure: container-tag source target KEY: #:engine #:allow-failure?

Tag SOURCE as TARGET; see ‘container-tag-argv‘.

Procedure: container-tag-argv source target KEY: #:engine

Return the argv that gives SOURCE the additional name TARGET.

Procedure: detect-compose-command KEY: #:engine #:path #:preferred

Return the words that run Compose, as a list.

PREFERRED, when non-empty, is split on whitespace and used as it stands. For Podman, the standalone ‘podman-compose‘ is preferred when it is installed, and ‘podman compose‘ is used otherwise; Docker always answers ‘docker compose‘. The engine is passed in rather than read from the parameter, so the result is a pure function of its arguments.

Procedure: detect-container-engine KEY: #:path #:preferred

Return the container engine maak should use.

PREFERRED, when non-empty, wins unchanged. Otherwise Podman is chosen when it is on PATH, then Docker. The fallback is Podman even when neither is installed, so a missing engine is reported as a missing program rather than silently replaced by another one.

PATH is the search path, PATH itself by default, so the choice can be tested without changing the process environment.

(detect-container-engine #:path search-path)
(detect-container-engine #:preferred engine-name)
Procedure: run-compose arguments KEY: #:program #:file #:project #:env-files #:profiles #:allow-failure? #:verbose?

Run Compose with ARGUMENTS, a list of strings.

The escape hatch for subcommands without a wrapper, such as ‘top‘. FILE, PROJECT, ENV-FILES and PROFILES are passed before the subcommand, the way both Compose implementations expect.


Next: (maak dsl), Previous: (maak archive), Up: API