Skip to content

Commit a811b60

Browse files
joasodeChroxvi
authored andcommitted
Introduce dev container Makefile (#139)
* Added a makefile with what we think is reasonable * remove test thingy * Better singularity url * Update makefile to non-privileged run * Add docs building functionality and default target * Fix building docs * Remove userid things * Comments, help and very explicit login * Just a bit .PHONY * Enhance Makefile (#156) * Enhance Makefile * Add review changes * Move quotation mark
1 parent 60dbc66 commit a811b60

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

Makefile

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
CONTAINER_RUN=docker
2+
3+
TESTFLAGS=
4+
CONTAINER_TEST_COMMAND=cd /home/ubuntu/code && uv sync --group=tests && uv run pytest
5+
CONTAINER_DOC_COMMAND=cd /home/ubuntu/code/doc && uv sync --group docs && uv run make apidoc && uv run make relnotes && uv run make html
6+
7+
8+
CONTAINER_ENTRYPOINT=--entrypoint bash
9+
CONTAINER_INTERNAL_PYTHON_VENV=--tmpfs=/venv:exec
10+
CONTAINER_ENVIRONMENT=--env UV_PROJECT_ENVIRONMENT=/venv
11+
CONTAINER_VOLUME_MOUNT=-v ${PWD}:/home/ubuntu/code
12+
CONTAINER_USER_ID=1000
13+
CONTAINER_SECURITY_OPTIONS=--security-opt label=disable --security-opt systempaths=unconfined --security-opt seccomp=unconfined --security-opt apparmor=unconfined
14+
CONTAINER_OPTIONS=--rm -it --user=$(CONTAINER_USER_ID) $(CONTAINER_SECURITY_OPTIONS) $(CONTAINER_ENTRYPOINT) $(CONTAINER_INTERNAL_PYTHON_VENV) $(CONTAINER_ENVIRONMENT) $(CONTAINER_VOLUME_MOUNT) $(OPTIONAL)
15+
16+
APPTAINER_URL=ghcr.io/deic-hpc/cotainr-dev_env-apptainer-1.3.6:main
17+
SINGULARITY_URL=ghcr.io/deic-hpc/cotainr-dev_env-singularity-ce-4.3.0:main
18+
19+
CONTAINER_URL=$(APPTAINER_URL)
20+
21+
HELP_OUTPUT=" Welcome to the cotainr makefile\n\
22+
This is to help you easily test cotainr\n\
23+
\n\
24+
The default way of running cotainr is by using 'make test'\n\
25+
We have a list of different goals defined to help out:\n\
26+
\n\
27+
help: prints this output\n\
28+
login: helps you login to the container registry\n\
29+
\n\
30+
Execution goals that are executed in the container\n\
31+
test: executes the cotainr test-suite in a container\n\
32+
docs: build the cotainr documentation in a container\n\
33+
\n\
34+
Environments goals that are defined before the execution goal to setup the environment\n\
35+
podman: changes the cotainer runner from docker to podman\n\
36+
singularity: changes the container to one containing singularity\n\
37+
apptainer: changes the container to one containing apptainer (default)\n\
38+
\n\
39+
Runtime environment flags can be provided in any order\n\
40+
TESTFLAGS: string that is parsed to pytest, e.g. TESTFLAGS='-k test_info.py'\n\
41+
"
42+
43+
.PHONY:default help podman login singularity apptainer test docs
44+
default: test
45+
46+
help:
47+
@echo $(HELP_OUTPUT)
48+
49+
podman:
50+
$(eval OPTIONAL=--userns=keep-id)
51+
$(eval CONTAINER_RUN=podman)
52+
53+
login:
54+
@echo "For more details on how to login to the github container registry see: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry";\
55+
read -p "Enter Github username:" USERNAME;\
56+
echo "Username: "$$USERNAME;\
57+
read -p "Enter Github token:" CR_PAT;\
58+
read -p "Enter Github password:" -s PASS;\
59+
echo $$CR_PAT | $(CONTAINER_RUN) login ghcr.io -u $$USERNAME -p $$PASS
60+
61+
singularity:
62+
$(eval CONTAINER_URL=$(SINGULARITY_URL))
63+
64+
apptainer:
65+
$(eval CONTAINER_URL=$(APPTAINER_URL))
66+
67+
test:
68+
$(eval CONTAINER_COMMAND="$(CONTAINER_TEST_COMMAND) $(TESTFLAGS)")
69+
$(call execute)
70+
71+
docs:
72+
$(eval CONTAINER_COMMAND="$(CONTAINER_DOC_COMMAND)")
73+
$(call execute)
74+
75+
execute = $(CONTAINER_RUN) run $(CONTAINER_OPTIONS) $(CONTAINER_URL) -c $(CONTAINER_COMMAND)

0 commit comments

Comments
 (0)