forked from FNNDSC/ChRIS_ultron_backEnd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
justfile
executable file
·170 lines (138 loc) · 5.42 KB
/
justfile
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
compose_file := 'docker-compose_just.yml'
# 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')
# 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 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 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 pman 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 docker-compose --profile=cube logs {{ args }}
# docker-compose ... run helper function.
[group('(4) docker-compose')]
run +command:
@just 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 -f '{{ compose_file }}' {{ 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
# Print the OpenAPI schema via drf-spectacular.
[group('(3) development')]
openapi:
@just 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 openapi