-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
justfile
247 lines (193 loc) · 7.52 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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
project_name := "baibot"
container_image_name := "localhost/baibot"
project_container_network := "baibot"
# Show help by default
default:
@just --list --justfile {{ justfile() }}
# Builds and runs a development binary
run-locally *extra_args: app-local-prepare
RUST_BACKTRACE=1 \
BAIBOT_CONFIG_FILE_PATH={{ justfile_directory() }}/var/app/local/config.yml \
BAIBOT_PERSISTENCE_DATA_DIR_PATH={{ justfile_directory() }}/var/app/local/data \
cargo run -- {{ extra_args }}
# Builds and runs the bot in a container
run-in-container *extra_args: app-container-prepare build-container-image-debug
/usr/bin/env docker run \
-it \
--rm \
--name={{ project_name }} \
--user=$(id -u):$(id -g) \
--cap-drop=ALL \
--read-only \
--network={{ project_container_network }} \
--env BAIBOT_PERSISTENCE_DATA_DIR_PATH=/data \
--mount type=bind,src={{ justfile_directory() }}/var/app/container/config.yml,dst=/app/config.yml,ro \
--mount type=bind,src={{ justfile_directory() }}/var/app/container/data,dst=/data \
{{ container_image_name }}:latest {{ extra_args }}
# Runs tests
test *extra_args:
RUST_BACKTRACE=1 cargo test {{ extra_args }}
# Builds a debug binary (target/debug/*)
build-debug *extra_args:
RUST_BACKTRACE=1 cargo build {{ extra_args }}
# Builds an optimized release binary (target/release/*)
build-release *extra_args: (build-debug "--release")
# Builds a container image (debug mode)
build-container-image-debug tag='latest': (_build-container-image "false" tag)
# Builds a container image (release mode)
build-container-image-release tag='latest': (_build-container-image "true" tag)
_build-container-image release_build tag:
/usr/bin/env docker build \
--build-arg RELEASE_BUILD={{ release_build }} \
-f {{ justfile_directory() }}/Dockerfile \
-t {{ container_image_name }}:{{ tag }} \
.
# Runs a docker-compose command
docker-compose services_type *extra_args:
/usr/bin/docker compose \
--project-directory var/services \
--env-file var/services/env \
-f etc/services/{{ services_type }}/compose.yml \
-p {{ project_name }}-{{ services_type }} \
{{ extra_args }}
# Runs a docker-compose command against the core services
docker-compose-core *extra_args:
just docker-compose core {{ extra_args }}
# Runs a docker-compose command against the localai services
docker-compose-localai *extra_args:
just docker-compose localai {{ extra_args }}
# Runs a docker-compose command against the ollama services
docker-compose-ollama *extra_args:
just docker-compose ollama {{ extra_args }}
# Runs all core dependency components (in the background)
services-start: services-prepare (docker-compose-core "up" "-d")
# Stops all core dependency components
services-stop: (docker-compose-core "down")
# Tails the logs for all running core services
services-tail-logs: (docker-compose-core "logs" "-f")
# Prepares the core services for running
services-prepare: _prepare-var-services-env _prepare-var-services-postgres _prepare-var-services-synapse _prepare-container-network
# Runs LocalAI (in the background)
localai-start: localai-prepare (docker-compose-localai "up" "-d")
# Stops LocalAI
localai-stop: (docker-compose-localai "down")
# Tails the logs for LocalAI
localai-tail-logs: (docker-compose-localai "logs" "-f")
# Prepares LocalAI for running
localai-prepare: _prepare-var-services-env _prepare-var-services-localai _prepare-container-network
# Runs Ollama (in the background)
ollama-start: ollama-prepare (docker-compose-ollama "up" "-d")
# Stops Ollama
ollama-stop: (docker-compose-ollama "down")
# Tails the logs for Ollama
ollama-tail-logs: (docker-compose-ollama "logs" "-f")
# Prepares Ollama for running
ollama-prepare: _prepare-var-services-env _prepare-var-services-ollama _prepare-container-network
# Pulls an Ollama model
ollama-pull-model model_id:
just -f {{ justfile_directory() }}/justfile docker-compose-ollama \
exec ollama \
ollama pull {{ model_id }}
# Prepares the app for running locally
app-local-prepare: _prepare-var-app-local-config_yml _prepare-var-app-local-data
# Prepares the app for running in a container
app-container-prepare: _prepare-var-app-container-config_yml _prepare-var-app-container-data
# Prepares the user accounts
users-prepare: services-prepare
just -f {{ justfile_directory() }}/justfile synapse-register-admin-user "admin" "admin"
just -f {{ justfile_directory() }}/justfile synapse-register-regular-user "baibot" "baibot"
# Starts a Postgres CLI (psql)
postgres-cli: services-prepare (docker-compose-core "exec" "postgres" "/bin/sh" "-c" "'PGUSER=synapse PGPASSWORD=synapse-password PGDATABASE=homeserver psql -h postgres'")
# Creates an administrator user
synapse-register-admin-user username password: services-prepare
just -f {{ justfile_directory() }}/justfile docker-compose-core \
exec synapse \
register_new_matrix_user \
--admin \
-u {{ username }} \
-p {{ password }} \
-c /config/homeserver.yaml \
http://localhost:8008
# Create a regular user
synapse-register-regular-user username password: services-prepare
just -f {{ justfile_directory() }}/justfile docker-compose-core \
exec synapse \
register_new_matrix_user \
--no-admin \
-u {{ username }} \
-p {{ password }} \
-c /config/homeserver.yaml \
http://localhost:8008
# Runs the clippy linter
clippy *extra_args:
cargo clippy {{ extra_args }}
_prepare-var-services-env:
#!/bin/sh
cd {{ justfile_directory() }};
if [ ! -f var/services/env ]; then
mkdir -p var/services
cp {{ justfile_directory() }}/etc/services/env.dist var/services/env
echo 'UID='`id -u` >> var/services/env;
echo 'GID='`id -g` >> var/services/env;
echo 'NETWORK_NAME={{ project_container_network }}' >> var/services/env;
fi
_prepare-var-services-postgres:
#!/bin/sh
cd {{ justfile_directory() }};
if [ ! -f var/services/postgres ]; then
mkdir -p var/services/postgres
chown `id -u`:`id -g` var/services/postgres
fi
_prepare-var-services-synapse:
#!/bin/sh
cd {{ justfile_directory() }};
if [ ! -f var/services/synapse ]; then
mkdir -p var/services/synapse/media-store
fi
_prepare-var-services-ollama:
#!/bin/sh
cd {{ justfile_directory() }};
if [ ! -f var/services/ollama ]; then
mkdir -p var/services/ollama
fi
_prepare-var-services-localai:
#!/bin/sh
cd {{ justfile_directory() }};
if [ ! -f var/services/localai ]; then
mkdir -p var/services/localai
fi
_prepare-container-network:
#!/bin/sh
network_definition=$(/usr/bin/env docker network ls --filter='name={{ project_container_network }}' --format=json)
if [ "$network_definition" = "" ]; then
/usr/bin/docker network create {{ project_container_network }}
fi
_prepare-var-app-local-config_yml:
#!/bin/sh
cd {{ justfile_directory() }};
if [ ! -f var/app/local/config.yml ]; then
mkdir -p var/app/local
cp {{ justfile_directory() }}/etc/app/config.yml.dist var/app/local/config.yml
fi
_prepare-var-app-local-data:
#!/bin/sh
cd {{ justfile_directory() }};
if [ ! -f var/app/local/data ]; then
mkdir -p var/app/local/data
fi
_prepare-var-app-container-config_yml:
#!/bin/sh
cd {{ justfile_directory() }};
if [ ! -f var/app/container/config.yml ]; then
mkdir -p var/app/container
cp {{ justfile_directory() }}/etc/app/config.yml.dist var/app/container/config.yml
sed --in-place 's/synapse.127.0.0.1.nip.io:42020/synapse:8008/g' var/app/container/config.yml
sed --in-place 's/127.0.0.1:42026/ollama:11434/g' var/app/container/config.yml
sed --in-place 's/127.0.0.1:42027/localai:8080/g' var/app/container/config.yml
fi
_prepare-var-app-container-data:
#!/bin/sh
cd {{ justfile_directory() }};
if [ ! -f var/app/container/data ]; then
mkdir -p var/app/container/data
fi