cave-cli 3.5.4__tar.gz → 3.5.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. {cave_cli-3.5.4/cave_cli.egg-info → cave_cli-3.5.5}/PKG-INFO +1 -1
  2. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/cli.py +18 -0
  3. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/commands/prettify.py +1 -1
  4. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/commands/reset.py +1 -1
  5. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/commands/run.py +48 -1
  6. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/commands/test.py +1 -1
  7. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/utils/docker.py +73 -0
  8. {cave_cli-3.5.4 → cave_cli-3.5.5/cave_cli.egg-info}/PKG-INFO +1 -1
  9. {cave_cli-3.5.4 → cave_cli-3.5.5}/pyproject.toml +1 -1
  10. {cave_cli-3.5.4 → cave_cli-3.5.5}/LICENSE +0 -0
  11. {cave_cli-3.5.4 → cave_cli-3.5.5}/NOTICE.md +0 -0
  12. {cave_cli-3.5.4 → cave_cli-3.5.5}/README.md +0 -0
  13. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/__init__.py +0 -0
  14. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/commands/__init__.py +0 -0
  15. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/commands/create.py +0 -0
  16. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/commands/doctor.py +0 -0
  17. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/commands/kill.py +0 -0
  18. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/commands/list_cmd.py +0 -0
  19. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/commands/list_versions.py +0 -0
  20. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/commands/purge.py +0 -0
  21. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/commands/sync_cmd.py +0 -0
  22. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/commands/theme.py +0 -0
  23. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/commands/uninstall.py +0 -0
  24. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/commands/update.py +0 -0
  25. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/commands/upgrade.py +0 -0
  26. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/commands/version.py +0 -0
  27. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/utils/__init__.py +0 -0
  28. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/utils/cache.py +0 -0
  29. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/utils/constants.py +0 -0
  30. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/utils/display.py +0 -0
  31. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/utils/env.py +0 -0
  32. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/utils/git.py +0 -0
  33. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/utils/logger.py +0 -0
  34. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/utils/net.py +0 -0
  35. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/utils/subprocess.py +0 -0
  36. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/utils/sync.py +0 -0
  37. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli/utils/validate.py +0 -0
  38. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli.egg-info/SOURCES.txt +0 -0
  39. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli.egg-info/dependency_links.txt +0 -0
  40. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli.egg-info/entry_points.txt +0 -0
  41. {cave_cli-3.5.4 → cave_cli-3.5.5}/cave_cli.egg-info/top_level.txt +0 -0
  42. {cave_cli-3.5.4 → cave_cli-3.5.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cave_cli
3
- Version: 3.5.4
3
+ Version: 3.5.5
4
4
  Summary: CLI for creating and managing Docker-based CAVE web applications.
5
5
  Author-email: MIT-CAVE <cave-contact@mit.edu>
6
6
  License: Apache-2.0
@@ -162,6 +162,12 @@ def main():
162
162
  ),
163
163
  )
164
164
  add_global_args(p_reset)
165
+ p_reset.add_argument(
166
+ "--docker-args",
167
+ default="",
168
+ metavar="ARGS",
169
+ help="Additional arguments to pass to docker run",
170
+ )
165
171
 
166
172
  # ------------------------------------------------------------------ #
167
173
  # upgrade #
@@ -233,6 +239,12 @@ def main():
233
239
  help="Run tests in cave_api/tests/",
234
240
  )
235
241
  add_global_args(p_test)
242
+ p_test.add_argument(
243
+ "--docker-args",
244
+ default="",
245
+ metavar="ARGS",
246
+ help="Additional arguments to pass to docker run",
247
+ )
236
248
  p_test.add_argument(
237
249
  "remaining",
238
250
  nargs="*",
@@ -247,6 +259,12 @@ def main():
247
259
  help="Format code with autoflake and black",
248
260
  )
249
261
  add_global_args(p_prettify)
262
+ p_prettify.add_argument(
263
+ "--docker-args",
264
+ default="",
265
+ metavar="ARGS",
266
+ help="Additional arguments to pass to docker run",
267
+ )
250
268
 
251
269
  # ------------------------------------------------------------------ #
252
270
  # list #
@@ -18,7 +18,7 @@ def prettify(args: argparse.Namespace) -> None:
18
18
  entrypoint="./utils/prettify.sh",
19
19
  interactive=False,
20
20
  it=False,
21
- docker_args="",
21
+ docker_args=getattr(args, "docker_args", "") or "",
22
22
  ip_port=None,
23
23
  yes=True,
24
24
  verbose=getattr(args, "verbose", False),
@@ -40,7 +40,7 @@ def reset(
40
40
  entrypoint="./utils/reset_db.sh",
41
41
  interactive=False,
42
42
  it=False,
43
- docker_args="",
43
+ docker_args=getattr(args, "docker_args", "") or "",
44
44
  ip_port=None,
45
45
  yes=True,
46
46
  verbose=getattr(args, "verbose", False),
@@ -1,4 +1,5 @@
1
1
  import argparse
2
+ import shlex
2
3
  import signal
3
4
  import sys
4
5
  import threading
@@ -8,12 +9,14 @@ from cave_cli.utils.display import (
8
9
  RunDashboard,
9
10
  print_section,
10
11
  step_done,
12
+ step_fail,
11
13
  step_start,
12
14
  )
13
15
  from cave_cli.utils.docker import (
14
16
  build_image,
15
17
  create_network,
16
18
  remove_containers,
19
+ run_and_log,
17
20
  run_detached,
18
21
  run_detached_logged,
19
22
  run_interactive,
@@ -49,7 +52,7 @@ def run_cave(
49
52
  show_all = getattr(args, "show_all", False) or getattr(args, "verbose", False) or getattr(args, "loglevel", "INFO").upper() == "DEBUG"
50
53
  entrypoint = getattr(args, "entrypoint", None) or "./utils/run_server.sh"
51
54
  docker_args_str = getattr(args, "docker_args", "") or ""
52
- extra_docker_args = docker_args_str.split() if docker_args_str else []
55
+ extra_docker_args = shlex.split(docker_args_str) if docker_args_str else []
53
56
  ip_port_arg = getattr(args, "ip_port", None)
54
57
  command_args = getattr(args, "command_args", []) or []
55
58
  extra_env = getattr(args, "extra_env", {}) or {}
@@ -136,6 +139,50 @@ def run_cave(
136
139
 
137
140
  django_volumes = [f"{app_dir}:/app"]
138
141
 
142
+ # Check if database needs initialization
143
+ if is_server_run and "postgres" in db_image.lower():
144
+ from cave_cli.utils.docker import is_container_ready, is_db_initialized
145
+ from cave_cli.utils.validate import confirm_action
146
+
147
+ db_container = f"{app_name}_db_host"
148
+ db_user = f"{app_name}_user"
149
+ db_name = f"{app_name}_name"
150
+
151
+ step_start("Checking database")
152
+ import time
153
+
154
+ ready = False
155
+ for _ in range(30):
156
+ if is_container_ready(db_container, db_user):
157
+ ready = True
158
+ break
159
+ time.sleep(1)
160
+
161
+ if ready:
162
+ if not is_db_initialized(db_container, db_user, db_name):
163
+ step_done("Checking database")
164
+ confirm_action(
165
+ "The database for this app is not set up. "
166
+ "Would you like to set it up now?"
167
+ )
168
+ step_start("Initializing database")
169
+ run_interactive(
170
+ name=f"{app_name}_django_setup",
171
+ image=f"cave-app:{app_name}",
172
+ network=network,
173
+ volumes=django_volumes,
174
+ env_vars=django_env,
175
+ command=["./utils/reset_db.sh"],
176
+ )
177
+ run_and_log(["docker", "rm", f"{app_name}_django_setup"])
178
+ step_done("Initializing database")
179
+ else:
180
+ step_done("Checking database")
181
+ else:
182
+ step_fail("Checking database", "Database container failed to become ready.")
183
+ remove_containers(app_name)
184
+ sys.exit(1)
185
+
139
186
  parsed = parse_ip_port(ip_port_arg) if ip_port_arg else None
140
187
  django_container = f"{app_name}_django"
141
188
 
@@ -30,7 +30,7 @@ def test(args: argparse.Namespace) -> None:
30
30
  extra_env=extra_env,
31
31
  interactive=False,
32
32
  it=False,
33
- docker_args="",
33
+ docker_args=getattr(args, "docker_args", "") or "",
34
34
  ip_port=None,
35
35
  yes=True,
36
36
  verbose=getattr(args, "verbose", False),
@@ -379,6 +379,79 @@ def stream_container_logs(
379
379
  log_queue.put(None)
380
380
 
381
381
 
382
+ def is_container_ready(name: str, user: str) -> bool:
383
+ """
384
+ Usage:
385
+
386
+ - Checks if a Postgres container is ready to accept connections
387
+
388
+ Requires:
389
+
390
+ - ``name``:
391
+ - Type: str
392
+ - What: The container name
393
+
394
+ - ``user``:
395
+ - Type: str
396
+ - What: The database user to check with
397
+
398
+ Returns:
399
+
400
+ - ``ready``:
401
+ - Type: bool
402
+ - What: True if ready, False otherwise
403
+ """
404
+ result = run(
405
+ ["docker", "exec", name, "pg_isready", "-U", user],
406
+ capture=True,
407
+ )
408
+ return result.returncode == 0
409
+
410
+
411
+ def is_db_initialized(name: str, user: str, db: str) -> bool:
412
+ """
413
+ Usage:
414
+
415
+ - Checks if the Django migrations table exists in the database
416
+
417
+ Requires:
418
+
419
+ - ``name``:
420
+ - Type: str
421
+ - What: The container name
422
+
423
+ - ``user``:
424
+ - Type: str
425
+ - What: The database user
426
+
427
+ - ``db``:
428
+ - Type: str
429
+ - What: The database name
430
+
431
+ Returns:
432
+
433
+ - ``initialized``:
434
+ - Type: bool
435
+ - What: True if initialized, False otherwise
436
+ """
437
+ result = run(
438
+ [
439
+ "docker",
440
+ "exec",
441
+ name,
442
+ "psql",
443
+ "-U",
444
+ user,
445
+ "-d",
446
+ db,
447
+ "-c",
448
+ "SELECT 1 FROM django_migrations LIMIT 1;",
449
+ ],
450
+ capture=True,
451
+ )
452
+ return result.returncode == 0
453
+
454
+
382
455
  def save_redis(app_name: str) -> None:
383
456
  """
384
457
  Usage:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cave_cli
3
- Version: 3.5.4
3
+ Version: 3.5.5
4
4
  Summary: CLI for creating and managing Docker-based CAVE web applications.
5
5
  Author-email: MIT-CAVE <cave-contact@mit.edu>
6
6
  License: Apache-2.0
@@ -9,7 +9,7 @@ build-backend = "setuptools.build_meta"
9
9
 
10
10
  [project]
11
11
  name = "cave_cli"
12
- version = "3.5.4"
12
+ version = "3.5.5"
13
13
  description = "CLI for creating and managing Docker-based CAVE web applications."
14
14
  authors = [
15
15
  {name = "MIT-CAVE", email = "cave-contact@mit.edu"}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes