Skip to content

Commit ec2ff39

Browse files
authored
Cotainr devcontainer (#153)
* First draft of devcontainer for cotainr * Dev container pre-commit and vscode integrations. * Cleaned up comments in devcontainer.json * Persisted bash history and set LANG in devcontainer.json * Updated dev container to use main branch container. * Added missing relnotes .PHONY target in docs Makefile. * Added common runtime env vars to Dockerfile. * Removed env vars from devcontainer.json that are now in the Dockerfile. * Added comment to devcontainer.json about volume mounts with docker. * Updated devcontainer.json to persist venv in volume mount.
1 parent c1e365d commit ec2ff39

File tree

3 files changed

+94
-2
lines changed

3 files changed

+94
-2
lines changed

.devcontainer/devcontainer.json

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/universal
3+
{
4+
"name": "Cotainr dev container",
5+
6+
// Default image to use as a base for the dev container.
7+
// If you don't have access to this registry, you can build the container locally from the ./github/dockerfiles/Dockerfile.
8+
"image": "ghcr.io/deic-hpc/cotainr-dev_env-apptainer-1.3.4:main",
9+
10+
// Set security options needed to run Apptainer/SingularityCE in the container.
11+
// These should be sufficient for running the container using rootless Podman.
12+
// More settings may be needed for other container runtimes, e.g. Docker.
13+
"securityOpt": [
14+
"systempaths=unconfined",
15+
"no-new-privileges"
16+
],
17+
18+
// Mounts to persist select data between container restarts and rebuilds.
19+
"mounts": [
20+
{// Persist the virtual environment (with paths relative to the dev container setup)
21+
"source": "uv-venv",
22+
"target": "/uv-venv",
23+
"type": "volume"
24+
},
25+
{// Persist the pre-commit environment
26+
"source": "pre-commit-env",
27+
"target": "/pre-commit-env",
28+
"type": "volume"
29+
},
30+
{// Persist the command history
31+
"source": "commandhistory",
32+
"target": "/commandhistory",
33+
"type": "volume"
34+
}
35+
],
36+
37+
// Sync the uv python venv on startup
38+
// https://code.visualstudio.com/remote/advancedcontainers/start-processes
39+
"postStartCommand": "uv sync --frozen",
40+
41+
// Set environment variables to use in IDE processes in the container.
42+
"remoteEnv": {
43+
"UV_PROJECT_ENVIRONMENT": "/uv-venv", // Set the uv virtual environment path to a persisted mounted volume
44+
"PRE_COMMIT_HOME": "/pre-commit-env", // Set the pre-commit env path to a persisted mounted volume
45+
"HISTFILE": "/commandhistory/.bash_history", // Set the history file to a persisted mounted volume
46+
"PROMPT_COMMAND": "history -a" // Append to the history file after each command
47+
},
48+
49+
// Run container as non-root user. More info: https://aka.ms/dev-containers-non-root.
50+
// https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user#_specifying-a-user-for-vs-code
51+
// containerUser is needed over remoteUser to have volumes mounted with the correct permissions for use by the non-root user.
52+
// This has been tested with Podman. If using Docker, more configuration may be needed to avoid permission errors with the volume mounts.
53+
// See https://github.com/microsoft/vscode-remote-release/issues/9931 for more details.
54+
"containerUser": "1000:1000",
55+
56+
// Configure tool-specific properties.
57+
"customizations": {
58+
"vscode": {
59+
// VS Code settings for the container.
60+
"settings": {
61+
"terminal.integrated.env.linux": {
62+
"GIT_EDITOR": "code --wait" // Use VS Code when editing commit messages
63+
},
64+
"python.defaultInterpreterPath": "/uv-venv/bin/python", // Set the default Python interpreter to the uv virtual environment
65+
"python.terminal.activateEnvironment": true, // Activate the uv virtual environment in the terminal
66+
"github.copilot.chat.codeGeneration.instructions": [
67+
{
68+
"text": "This dev container is used for developing and testing Cotainr. Cotainr is a tool for building Singularity / Apptainer containers in a rootless setting. It is written in pure Python and uses pytest for testing as well as sphinx for building the documentation. The documentation is written as restructured text."
69+
}
70+
]
71+
},
72+
// VS Code extensions to install in the dev container.
73+
// https://code.visualstudio.com/docs/devcontainers/containers#_managing-extensions
74+
"extensions": [
75+
"ms-python.python",
76+
"ms-azuretools.vscode-containers",
77+
"ms-vscode.makefile-tools",
78+
"github.vscode-github-actions",
79+
"streetsidesoftware.code-spell-checker",
80+
"tamasfe.even-better-toml",
81+
"redhat.vscode-yaml",
82+
"DavidAnson.vscode-markdownlint",
83+
"trond-snekvik.simple-rst"
84+
]
85+
}
86+
}
87+
}

.github/workflows/dockerfiles/Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM ubuntu:latest
2-
LABEL authors="julius"
2+
LABEL authors="DeiC HPC"
33

44
# get build-arg inputs to set the singularity provider and versions
55
ARG SINGULARITY_PROVIDER
@@ -77,5 +77,10 @@ RUN set -eux;\
7777
singularity --version
7878

7979
# Download and install unmanaged uv
80+
# Set UV_LINK_MODE to copy since hardlinking does not work with volume mounts
8081
RUN set -eux;\
8182
curl -LsSf https://astral.sh/uv/install.sh | env UV_UNMANAGED_INSTALL="/usr/local/bin" sh
83+
ENV UV_LINK_MODE="copy"
84+
85+
# Set default locale to english (as needed for the docs prepare-release.py script) and utf-8 as required when using with e.g. a VS Code terminal.
86+
ENV LANG="C.UTF-8"

doc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ help:
1616
@python3 -c """import sphinx.util; print(' %s to autogenerate the API reference rst files' % sphinx.util.console.blue('apidoc'.ljust(10)))"""
1717
@python3 -c """import sphinx.util; print(' %s to autogenerate the release notes rst file' % sphinx.util.console.blue('relnotes'.ljust(10)))"""
1818

19-
.PHONY: help apidoc Makefile
19+
.PHONY: help apidoc relnotes Makefile
2020

2121
apidoc:
2222
@$(SPHINXAPIDOC) --force --separate --no-toc -o api_reference $(SOURCEDIR)/../$(PACKAGENAME) $(SOURCEDIR)/../$(PACKAGENAME)/tests/*

0 commit comments

Comments
 (0)