-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathjustfile
More file actions
199 lines (164 loc) · 6.84 KB
/
justfile
File metadata and controls
199 lines (164 loc) · 6.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# This is a `justfile` for the development of ChRIS backend. For the most part,
# it is a wrapper around the `docker compose` or `podman compose` command.
# Use the `just` program to execute `justfile` commands. Run
#
# just -l
#
# to list commands and their descriptions.
#
# The syntax and usage of `justfile` is similar to Makefile of GNU Make.
# For more information, see https://just.systems/man/en/chapter_1.html
# Storage mode: "fslink" (default), "swift" (Swift object storage), or "s3" (S3-compatible storage).
# Usage: just storage=swift dev
# Or persist the preference: just set-storage swift
storage := `if [ -f '.storage' ]; then cat .storage; else echo fslink; fi`
# Start the ChRIS backend in development mode, and attach to the live-reloading server.
[group('(1) start-up')]
dev: chrisomatic attach
# Start the ChRIS backend in development mode.
[group('(1) start-up')]
start: start-ancillary migrate up
# Start services (without running database migrations).
[group('(1) start-up')]
up: (docker-compose '--profile=cube up -d')
# Attach to the chris container.
[group('(3) development')]
attach: (docker-compose '--profile=cube attach chris | grep -Fv "\"GET /api/v1/users/ HTTP/1.1\" 200"')
# Open a Python shell.
[group('(3) development')]
shell: (run 'python manage.py shell')
# Open a Bash shell.
[group('(3) development')]
bash: (run 'bash')
# Run chrisomatic, a tool which adds plugins and users to CUBE.
[group('(1) start-up')]
chrisomatic *args: start
@just storage={{ storage }} docker-compose --profile=cube run --rm chrisomatic chrisomatic {{ args }}
# Run chrisomatic with the contents of chrisomatic/postscript.yml
[group('(1) start-up')]
postscript: (chrisomatic 'postscript.yml')
# Perform database migrations.
[group('(1) start-up')]
migrate: (run 'python manage.py migrate --noinput')
# Create database migrations.
[group('(3) development')]
makemigrations: (run 'python manage.py makemigrations')
# Run tests, e.g. `just test pacsfiles`
[group('(3) development')]
test *args:
@just storage={{ storage }} run python manage.py test --force-color {{ args }}
# Run all tests.
[group('(3) development')]
test-all: test-unit test-integration
# Run unit tests.
[group('(3) development')]
test-unit: start-ancillary (run 'python manage.py test --force-color --exclude-tag integration')
# Run integration tests.
[group('(3) development')]
test-integration: start-ancillary (run 'python manage.py test --force-color --tag integration')
# Start dependency services.
[group('(1) start-up')]
start-ancillary: (docker-compose 'up -d')
# Stop services.
[group('(2) shutdown')]
down: (docker-compose '--profile=cube --profile=tools down')
# Stop services and remove all data.
[group('(2) shutdown')]
nuke: reap-plugin-instances (docker-compose '--profile=cube --profile=tools down -v --remove-orphans')
# Remove all plugin instance containers.
[group('(2) shutdown')]
reap-plugin-instances: (docker-compose 'run --rm pfcon python -c' '''
'
import os
import docker
d = docker.from_env()
filters = {"label": os.getenv("JOB_LABELS")}
containers = d.containers.list(all=True, filters=filters)
for container in containers:
print(f"Removing container: {container.name} ({container.image})", flush=True)
container.remove(force=True)
'
''')
# (Re-)build the container image.
[group('(4) docker-compose')]
build: (docker-compose '--profile=cube build')
# Pull container images.
[group('(4) docker-compose')]
pull: (docker-compose 'pull')
# Get container logs.
[group('(4) docker-compose')]
logs *args:
@just storage={{ storage }} docker-compose --profile=cube logs {{ args }}
# docker-compose ... run helper function.
[group('(4) docker-compose')]
run +command:
@just storage={{ storage }} docker-compose --profile=cube run --rm chris {{ command }}
# docker-compose ... helper function.
[group('(4) docker-compose')]
docker-compose +command:
env UID=$(id -u) GID=$(id -g) DOCKER_SOCK="$(just get-socket)" $(just get-engine) compose {{ if storage == "swift" { "-f docker-compose.yml -f docker-compose_swift.yml" } else if storage == "s3" { "-f docker-compose.yml -f docker-compose_s3.yml" } else { "" } }} {{ command }}
# Get the container engine to use (docker or podman)
[group('helper function')]
get-engine:
@if [ -f '.preference' ]; then \
cat .preference && exit 0; \
elif type podman > /dev/null 2>&1; then \
echo podman; \
else \
echo docker; \
fi \
# Get the docker daemon socket path.
[group('helper function')]
get-socket:
@if [ "$(just get-engine)" = 'podman' ]; then \
just get-podman-socket; \
else \
echo '/var/run/docker.sock'; \
fi
# Get the podman daemon socket path.
[group('helper function')]
get-podman-socket: check-podman-socket
@podman info --format '{{{{ .Host.RemoteSocket.Path }}'
# Ensure that the podman daemon is running.
[group('helper function')]
check-podman-socket:
@if [ "$(podman info --format '{{{{ .Host.RemoteSocket.Exists }}')" != 'true' ]; then \
cmd='systemctl --user start podman.service'; \
>&2 echo "Podman daemon not running. Please run \`$(tput bold)$cmd$(tput sgr0)\`"; \
exit 1; \
fi
# Set a preference for using either Docker or Podman.
[group('(5) docker/podman preference')]
prefer docker_or_podman:
@[ '{{ docker_or_podman }}' = 'docker' ] || [ '{{ docker_or_podman }}' = 'podman' ] \
|| ( \
>&2 echo 'argument must be either "docker" or "podman"'; \
exit 1 \
)
echo '{{ docker_or_podman }}' > .preference
# Remove your preference for Docker or Podman.
[group('(5) docker/podman preference')]
unset-preference:
rm -f .preference
# Set a preference for storage mode ("fslink", "swift", or "s3").
[group('(5) docker/podman preference')]
set-storage mode:
@[ '{{ mode }}' = 'fslink' ] || [ '{{ mode }}' = 'swift' ] || [ '{{ mode }}' = 's3' ] \
|| ( \
>&2 echo 'argument must be "fslink", "swift", or "s3"'; \
exit 1 \
)
echo '{{ mode }}' > .storage
# Remove your preference for storage mode.
[group('(5) docker/podman preference')]
unset-storage:
rm -f .storage
# Print the OpenAPI schema via drf-spectacular.
[group('(3) development')]
openapi:
@just storage={{ storage }} run python manage.py spectacular --color
# Print the OpenAPI schema using drf-spectacular, using workarounds for more
# reliable client generation.
[group('(3) development')]
openapi-split:
env SPECTACULAR_SPLIT_REQUEST=true just storage={{ storage }} openapi