-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJustfile
More file actions
194 lines (159 loc) · 5.5 KB
/
Justfile
File metadata and controls
194 lines (159 loc) · 5.5 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
set shell := ["bash", "-c"]
default:
just --list
initialise:= 'set -euxo pipefail
initialise() {
# Clear the terminal window title on exit
echo -ne "\033]0; \007"
}
trap initialise EXIT
just _terminal-description'
alias bp := backend-poetry
# Run the web app
backend-poetry:
#!/usr/bin/env bash
{{initialise}} "backend"
just _start-container detached="true" build="false"
docker compose -f docker-compose-base-dev.yml -f docker-compose-module.yml exec -it backend-database bash -c "poetry shell && bash"
alias bpb := backend-poetry-basic
# Run the web app
backend-poetry-basic:
#!/usr/bin/env bash
{{initialise}} "backend"
just _start-container detached="true" build="false"
docker compose exec -it backend-database bash -c "poetry shell && bash"
alias cfp := create-fake-patients
# Create fake patients
create-fake-patients:
#!/usr/bin/env bash
{{initialise}} "create-fake-patients"
just _start-container-basic detached="true" build="false"
docker compose exec backend-database /bin/sh -c "cd app && poetry run python manage.py create_fake_patients"
_start-docker-daemon:
#!/usr/bin/env bash
if ! docker info > /dev/null 2>&1; then
echo "Docker is not running."
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS: Start Docker Desktop
open -a Docker
else
# Linux: Start Docker daemon
sudo systemctl start docker
fi
# Wait for Docker to be fully running
echo "Waiting for Docker to start..."
while ! docker info > /dev/null 2>&1; do
sleep 1
done
echo "Docker is now running."
else
echo "Docker is already running."
fi
# If needed, starts Docker daemon and also starts the container (detached: default: true, build: default: true)
_start-container detached="true" build="true":
#!/usr/bin/env bash
just _start-docker-daemon
container_name="backend-database"
# Determine flags based on arguments
detached_flag=""
if [ "$detached" = "true" ]; then
detached_flag="-d"
fi
build_flag=""
if [ "$build" = "true" ]; then
build_flag="--build"
fi
if [ "$(docker ps -q -f name=$container_name)" ]; then
echo "Container $container_name is already running."
else
echo "Container $container_name is not running. Starting it now..."
sh create-module-docker-compose.sh
docker compose -f docker-compose-base-dev.yml -f docker-compose-module.yml up $detached_flag $build_flag
fi
# If needed, starts Docker daemon and also starts the container (detached: default: true, build: default: true)
_start-container-basic detached="true" build="true":
#!/usr/bin/env bash
just _start-docker-daemon
container_name="backend-database"
# Determine flags based on arguments
detached_flag=""
if [ "$detached" = "true" ]; then
detached_flag="-d"
fi
build_flag=""
if [ "$build" = "true" ]; then
build_flag="--build"
fi
if [ "$(docker ps -q -f name=$container_name)" ]; then
echo "Container $container_name is already running."
else
echo "Container $container_name is not running. Starting it now..."
docker compose up $detached_flag $build_flag
fi
alias i := initialise-project
# Initialise the project
initialise-project:
#!/usr/bin/env bash
{{initialise}} "initialise"
just _start-container-basic
docker compose exec backend-database /bin/sh -c "poetry install && poetry run python app/create_next_user.py"
just makemigrations-migrate
alias mm := makemigrations-migrate
# Run makemigrations and migrate
makemigrations-migrate:
#!/usr/bin/env bash
{{initialise}} "makemigrations-migrate"
docker compose exec backend-database /bin/sh -c "\
cd app && \
poetry run python manage.py makemigrations && \
poetry run python manage.py migrate && \
poetry run python manage.py migrate --database=patients"
alias r := run
# Run the whole service
run:
#!/usr/bin/env bash
{{initialise}} "run"
just _start-container detached="false" build="false"
alias rb := run-basic
# Run the whole service
run-basic:
#!/usr/bin/env bash
{{initialise}} "run"
just _start-container-basic detached="false" build="false"
find-subfolders:
#!/usr/bin/env bash
directory="./backend/.pypoetry/virtualenvs"
first_subfolder=$(find "$directory" -type d -mindepth 1 -maxdepth 1 | head -n 1)
python="${first_subfolder}/bin/python3.12"
site_packages="${first_subfolder}/lib/python3.12/site-packages"
echo $python
echo $site_packages
alias s := setup-terminal-description
# Set up the description for terminal windows
setup-terminal-description:
#!/usr/bin/env bash
{{initialise}} setup-terminal-description
alias_definition="alias j='just'"
if grep -Fxq "$alias_definition" ~/.zshrc
then
echo "Alias already exists in ~/.zshrc"
else
echo "$alias_definition" >> ~/.zshrc
echo "Alias added to ~/.zshrc"
fi
echo "Please run the following command to apply the changes to this terminal:"
echo "source ~/.zshrc"
alias sp := setup-python
# Set up python
setup-python:
#!/usr/bin/env bash
{{initialise}} setup-poetry
if ! command -v jq &> /dev/null
then
echo "jq could not be found, installing..."
brew install jq
else
echo "jq is already installed"
fi
_terminal-description message=" ":
echo -ne "\033]0;{{message}}\007"