Skip to content

Commit

Permalink
document docker-helper variables, add DOCKER_TAG
Browse files Browse the repository at this point in the history
in particular, using docker instead of podman
  • Loading branch information
katrinafyi committed Dec 18, 2024
1 parent 3a60c4c commit 6bd37a2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/test/make/docker-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ fi
# unique names depend only on DOCKER_FLAKE, allowing them to be computed without nix.
commit=$(printf '%s' "$DOCKER_FLAKE" | grep --only-matching -E '[0-9a-fA-F]{40}' | head -c8)
flake_hash=flake-$(printf '%s' "$DOCKER_FLAKE" | md5sum | cut -d' ' -f1 | head -c4)
unique_image="$DOCKER_IMAGE:$flake_hash-$commit"
unique_container=container-$flake_hash-$commit

if [[ -z "${DOCKER_TAG:-}" ]]; then
DOCKER_TAG="$flake_hash-$commit"
fi

unique_image="$DOCKER_IMAGE:$DOCKER_TAG"
unique_container="container-$DOCKER_TAG"

# this allows the env subcommand to output syntax compatible with multiple shells
shell=$(basename $SHELL)
Expand Down Expand Up @@ -124,6 +129,7 @@ elif [[ "$1" == env ]]; then
echoexport USE_DOCKER "1"
echoexport DOCKER_FLAKE "$DOCKER_FLAKE"
echoexport DOCKER_IMAGE "$DOCKER_IMAGE"
echoexport DOCKER_TAG "$DOCKER_TAG"
echoexport DOCKER_PLATFORM "$DOCKER_PLATFORM"
echoexport DOCKER "$DOCKER"
echoexport DOCKER_USER "$DOCKER_USER"
Expand Down
40 changes: 40 additions & 0 deletions src/test/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ the lifted test cases.
This also adds a `docker-helper.sh` alias into the current shell session.
To de-activate this environment, use the same command with `--unset` after "env".

The environment can be configured by setting environment variables before running the "env"
subcommand. See the "Customising Docker behaviour" subsection below.

3. After setting up the environment, to pull the Docker image [from GHCR](https://github.com/UQ-PAC/BASIL/pkgs/container/basil-tools-docker), run:
```bash
docker-helper.sh pull
Expand All @@ -92,6 +95,43 @@ the lifted test cases.

6. The last two steps will have to be repeated if the Docker image changes.

#### Customising Docker options

Before running `docker-helper.sh env`, several environment variables can be set
to influence its behaviour:

- `DOCKER` is the name of the Docker program (default: podman).
- `DOCKER_USER` is the name/ID of a user _inside_ the container, to be used
to run the lifter commands (default: root).
- `DOCKER_FLAKE` is a Nix flake reference to a streamed Docker image builder (default: read from docker-flake.txt).
- `DOCKER_IMAGE` is name of the image, including the registry URL (default: ghcr.io/uq-pac/basil-tools-docker)
- `DOCKER_TAG` is the tag of the image (default: hashed from DOCKER_FLAKE).

The values of these variables will be printed by `eval $(docker-helper.sh env)`.
Note that if you want to change these variables, you should first deactivate the environment,
make the changes, then re-activate.
This will make sure dependent variables are updated correctly.
```bash
eval $(docker-helper.sh env --unset)
# set variables here
export DOCKER=docker
# ... etc
eval $(docker-helper.sh env)
```

To use traditional `docker` instead of `podman`:
- By default, the container runner is `podman`. Podman is
an implementation of the Docker protocol which is rootless by default.
Containers are run as your usual user, without needing a separate system
service. Change `DOCKER` to "docker" to use the original Docker program.
- If you are using the traditional `docker` program in a _non_ rootless setup,
you will have to set `DOCKER_USER` to `UID:GID` where UID/GID are is the user/group ID of
your _outside_ user (obtain with `id -u` and `id -g`).
This will make sure the produced files are editable by your ordinary user.

To use a custom Docker image, change `DOCKER_IMAGE` and `DOCKER_TAG` as necessary.
Note that changing these will likely break the "build" subcommand.

### Building with Docker

Now, running make commands should use compilers from Docker.
Expand Down

0 comments on commit 6bd37a2

Please sign in to comment.