djd 0.1.0__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 (49) hide show
  1. djd-0.1.0/LICENSE +21 -0
  2. djd-0.1.0/PKG-INFO +86 -0
  3. djd-0.1.0/README.md +63 -0
  4. djd-0.1.0/pyproject.toml +50 -0
  5. djd-0.1.0/setup.cfg +4 -0
  6. djd-0.1.0/src/deploy/__init__.py +3 -0
  7. djd-0.1.0/src/deploy/aws.py +108 -0
  8. djd-0.1.0/src/deploy/cli/deploy.py +428 -0
  9. djd-0.1.0/src/deploy/cli/templates.py +118 -0
  10. djd-0.1.0/src/deploy/config.py +42 -0
  11. djd-0.1.0/src/deploy/context.py +259 -0
  12. djd-0.1.0/src/deploy/git.py +97 -0
  13. djd-0.1.0/src/deploy/history.py +8 -0
  14. djd-0.1.0/src/deploy/logging.py +74 -0
  15. djd-0.1.0/src/deploy/management/__init__.py +0 -0
  16. djd-0.1.0/src/deploy/management/base_command.py +12 -0
  17. djd-0.1.0/src/deploy/management/commands/__init__.py +0 -0
  18. djd-0.1.0/src/deploy/management/commands/deploy.py +6 -0
  19. djd-0.1.0/src/deploy/management/commands/templates.py +6 -0
  20. djd-0.1.0/src/deploy/renderables/tables.py +212 -0
  21. djd-0.1.0/src/deploy/renderables/util.py +55 -0
  22. djd-0.1.0/src/deploy/templates/Dockerfile.j2 +80 -0
  23. djd-0.1.0/src/deploy/templates/terraform/deployments/{{ name }}/main.tf.j2 +31 -0
  24. djd-0.1.0/src/deploy/templates/terraform/modules/application/alb.tf.j2 +123 -0
  25. djd-0.1.0/src/deploy/templates/terraform/modules/application/ecr.tf.j2 +3 -0
  26. djd-0.1.0/src/deploy/templates/terraform/modules/application/ecs.tf.j2 +155 -0
  27. djd-0.1.0/src/deploy/templates/terraform/modules/application/elasticache.tf.j2 +34 -0
  28. djd-0.1.0/src/deploy/templates/terraform/modules/application/iam.tf.j2 +204 -0
  29. djd-0.1.0/src/deploy/templates/terraform/modules/application/locals.tf.j2 +49 -0
  30. djd-0.1.0/src/deploy/templates/terraform/modules/application/outputs.tf.j2 +59 -0
  31. djd-0.1.0/src/deploy/templates/terraform/modules/application/rds.tf.j2 +34 -0
  32. djd-0.1.0/src/deploy/templates/terraform/modules/application/route53.tf.j2 +45 -0
  33. djd-0.1.0/src/deploy/templates/terraform/modules/application/s3.tf.j2 +50 -0
  34. djd-0.1.0/src/deploy/templates/terraform/modules/application/secrets_manager.tf.j2 +35 -0
  35. djd-0.1.0/src/deploy/templates/terraform/modules/application/security_groups.tf.j2 +126 -0
  36. djd-0.1.0/src/deploy/templates/terraform/modules/application/ses.tf.j2 +27 -0
  37. djd-0.1.0/src/deploy/templates/terraform/modules/application/variables.tf.j2 +119 -0
  38. djd-0.1.0/src/deploy/templates/terraform/modules/application/vpc.tf.j2 +44 -0
  39. djd-0.1.0/src/deploy/templates/terraform/modules/shared/route53.tf.j2 +11 -0
  40. djd-0.1.0/src/deploy/templates/terraform/modules/shared/ses.tf.j2 +3 -0
  41. djd-0.1.0/src/deploy/templates/terraform/modules/shared/variables.tf.j2 +10 -0
  42. djd-0.1.0/src/deploy/terraform.py +46 -0
  43. djd-0.1.0/src/deploy/util.py +6 -0
  44. djd-0.1.0/src/djd.egg-info/PKG-INFO +86 -0
  45. djd-0.1.0/src/djd.egg-info/SOURCES.txt +47 -0
  46. djd-0.1.0/src/djd.egg-info/dependency_links.txt +1 -0
  47. djd-0.1.0/src/djd.egg-info/entry_points.txt +3 -0
  48. djd-0.1.0/src/djd.egg-info/requires.txt +10 -0
  49. djd-0.1.0/src/djd.egg-info/top_level.txt +1 -0
djd-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Zagaran, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
djd-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,86 @@
1
+ Metadata-Version: 2.4
2
+ Name: djd
3
+ Version: 0.1.0
4
+ Summary: A tool for managing Django + AWS ECS deployments
5
+ Author-email: Matthew Coleman <matthew@zagaran.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/zagaran/djd
8
+ Project-URL: Repository, https://github.com/zagaran/djd
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: boto3>=1.26.0
13
+ Requires-Dist: django>=4.2
14
+ Requires-Dist: gitpython>=3.1.0
15
+ Requires-Dist: ipython>=8.0.0
16
+ Requires-Dist: jinja2>=3.1.0
17
+ Requires-Dist: pygithub>=2.0.0
18
+ Requires-Dist: python-dotenv>=1.0.0
19
+ Requires-Dist: pytz>=2023.3
20
+ Requires-Dist: rich>=13.0.0
21
+ Requires-Dist: typer>=0.9.0
22
+ Dynamic: license-file
23
+
24
+ <p align="center">
25
+ <img src="https://cdn-icons-png.flaticon.com/512/5731/5731863.png" width=256 />
26
+ </p>
27
+
28
+ ## djd
29
+
30
+ **djd** is a command line tool for creating and managing Django + AWS ECS deployments. It wraps
31
+ Terraform, AWS (via [Boto3](https://github.com/boto/boto3)), Docker, Git, and GitHub to coordinate
32
+ running deployments, building and uploading Docker images, and accessing infrastructure from the terminal.
33
+
34
+ ## Installation
35
+
36
+ ```bash
37
+ pip install djd
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ ### Creating a deployment
43
+
44
+ This package includes templates for a canonical ECS web deployment architecture. Run the following
45
+ command to scaffold a named deployment in your project's repository. (Recommended: commit the generated files.)
46
+
47
+ ```bash
48
+ djd-templates init {deployment_name}
49
+ ```
50
+
51
+ To see all configuration options, append `--help`.
52
+
53
+ ### ECS Services
54
+
55
+ To visualize running / configured ECS services:
56
+
57
+ ```bash
58
+ djd {deployment_name} show-services
59
+ ```
60
+
61
+ You will get a table that shows each ECS service's ID, name, latest deployment indicator,
62
+ task counts, status, and rollout state:
63
+
64
+ ```
65
+ Deployment Status
66
+
67
+ Deployment ID Service Latest Created On Count Status Rollout State
68
+ ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
69
+ ecs-svc/0938446537801788686 deploy-staging-web * 2025-10-24 12:30:48 PM 0 -> 1 / 1 Primary Completed
70
+ ecs-svc/2070367854272485563 deploy-staging-worker * 2025-10-24 12:30:48 PM 0 -> 0 / 0 Primary Completed
71
+ ```
72
+
73
+ To visualize individual tasks on the cluster:
74
+
75
+ ```bash
76
+ djd {deployment_name} show-tasks
77
+ ```
78
+
79
+ ```
80
+ Task Status
81
+
82
+ Task ID Task Definition ID Created At Health Status Status
83
+ ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
84
+ b21dc0a1442740c5a00930a64d6b00cd deploy-staging-web:2 2025-10-24 12:31:06 PM Unknown Running
85
+
86
+ ```
djd-0.1.0/README.md ADDED
@@ -0,0 +1,63 @@
1
+ <p align="center">
2
+ <img src="https://cdn-icons-png.flaticon.com/512/5731/5731863.png" width=256 />
3
+ </p>
4
+
5
+ ## djd
6
+
7
+ **djd** is a command line tool for creating and managing Django + AWS ECS deployments. It wraps
8
+ Terraform, AWS (via [Boto3](https://github.com/boto/boto3)), Docker, Git, and GitHub to coordinate
9
+ running deployments, building and uploading Docker images, and accessing infrastructure from the terminal.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ pip install djd
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### Creating a deployment
20
+
21
+ This package includes templates for a canonical ECS web deployment architecture. Run the following
22
+ command to scaffold a named deployment in your project's repository. (Recommended: commit the generated files.)
23
+
24
+ ```bash
25
+ djd-templates init {deployment_name}
26
+ ```
27
+
28
+ To see all configuration options, append `--help`.
29
+
30
+ ### ECS Services
31
+
32
+ To visualize running / configured ECS services:
33
+
34
+ ```bash
35
+ djd {deployment_name} show-services
36
+ ```
37
+
38
+ You will get a table that shows each ECS service's ID, name, latest deployment indicator,
39
+ task counts, status, and rollout state:
40
+
41
+ ```
42
+ Deployment Status
43
+
44
+ Deployment ID Service Latest Created On Count Status Rollout State
45
+ ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
46
+ ecs-svc/0938446537801788686 deploy-staging-web * 2025-10-24 12:30:48 PM 0 -> 1 / 1 Primary Completed
47
+ ecs-svc/2070367854272485563 deploy-staging-worker * 2025-10-24 12:30:48 PM 0 -> 0 / 0 Primary Completed
48
+ ```
49
+
50
+ To visualize individual tasks on the cluster:
51
+
52
+ ```bash
53
+ djd {deployment_name} show-tasks
54
+ ```
55
+
56
+ ```
57
+ Task Status
58
+
59
+ Task ID Task Definition ID Created At Health Status Status
60
+ ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
61
+ b21dc0a1442740c5a00930a64d6b00cd deploy-staging-web:2 2025-10-24 12:31:06 PM Unknown Running
62
+
63
+ ```
@@ -0,0 +1,50 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "djd"
7
+ version = "0.1.0"
8
+ description = "A tool for managing Django + AWS ECS deployments"
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ requires-python = ">=3.10"
12
+ dependencies = [
13
+ "boto3>=1.26.0",
14
+ "django>=4.2",
15
+ "gitpython>=3.1.0",
16
+ "ipython>=8.0.0",
17
+ "jinja2>=3.1.0",
18
+ "pygithub>=2.0.0",
19
+ "python-dotenv>=1.0.0",
20
+ "pytz>=2023.3",
21
+ "rich>=13.0.0",
22
+ "typer>=0.9.0",
23
+ ]
24
+ authors = [
25
+ { name="Matthew Coleman", email="matthew@zagaran.com" }
26
+ ]
27
+
28
+ [project.urls]
29
+ Homepage = "https://github.com/zagaran/djd"
30
+ Repository = "https://github.com/zagaran/djd"
31
+
32
+ [project.scripts]
33
+ djd = "deploy.cli.deploy:main"
34
+ djd-templates = "deploy.cli.templates:main"
35
+
36
+ [tool.setuptools.packages.find]
37
+ where = ["src"]
38
+
39
+ [tool.setuptools.package-data]
40
+ deploy = ["templates/**/*"]
41
+
42
+ [dependency-groups]
43
+ dev = [
44
+ "autopep8>=2.3.2",
45
+ "basedpyright>=1.31.7",
46
+ "django-stubs>=5.2.7",
47
+ "ipdb>=0.13.13",
48
+ "pre-commit>=4.3.0",
49
+ "setuptools>=80.9.0",
50
+ ]
djd-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ from deploy.logging import initialize_logging
2
+
3
+ initialize_logging(log_name="deploy")
@@ -0,0 +1,108 @@
1
+ import logging
2
+ import os
3
+ import pty
4
+ import subprocess
5
+ import traceback
6
+
7
+ from botocore.exceptions import BotoCoreError, ClientError
8
+
9
+ from deploy.config import AWS_REGION
10
+
11
+
12
+ def describe_service_deployments(client, cluster: str, services: list[str]):
13
+ describe_services_response = client.describe_services(cluster=cluster, services=services)
14
+
15
+ all_deployment_updates = []
16
+ for response in describe_services_response["services"]:
17
+ service_name = response["serviceName"]
18
+ deployment_updates = response["deployments"]
19
+ latest_deployment_id = next(reversed(sorted(deployment_updates, key=lambda x: x["createdAt"])))["id"]
20
+
21
+ for deployment_update in deployment_updates:
22
+ deployment_update["service"] = service_name
23
+ deployment_update["is_latest"] = latest_deployment_id == deployment_update["id"]
24
+ all_deployment_updates.append(deployment_update)
25
+
26
+ return all_deployment_updates
27
+
28
+
29
+ def describe_service_tasks(client, cluster: str, services: list[str] | None = None):
30
+ task_ids = []
31
+ if services:
32
+ for service in services:
33
+ list_tasks_response = client.list_tasks(cluster=cluster, serviceName=service)
34
+ task_ids += list_tasks_response["taskArns"]
35
+ else:
36
+ list_tasks_response = client.list_tasks(cluster=cluster)
37
+ task_ids += list_tasks_response["taskArns"]
38
+
39
+ tasks = []
40
+ if task_ids:
41
+ describe_tasks_response = client.describe_tasks(cluster=cluster, tasks=task_ids)
42
+ tasks = describe_tasks_response["tasks"]
43
+
44
+ return tasks
45
+
46
+
47
+ def execute_command(client, command: str, cluster: str, service: str, interactive: bool = False):
48
+ list_tasks_response = client.list_tasks(cluster=cluster, serviceName=service)
49
+ task_ids = list_tasks_response["taskArns"]
50
+
51
+ # TODO: exec command in most recent task (sort first)
52
+
53
+ if len(task_ids):
54
+ task_id = task_ids[0]
55
+
56
+ logging.info("Starting Interactive Session...")
57
+ cmd = ["aws", "ecs", "execute-command", "--cluster", cluster, "--region",
58
+ AWS_REGION, "--task", task_id, "--interactive", "--command", f"'{command}'"]
59
+ logging.info(f'Running Command: \n"{(" ").join(cmd)}"')
60
+
61
+ try:
62
+ if interactive:
63
+ pty.spawn(cmd)
64
+ else:
65
+ subprocess.run(
66
+ cmd,
67
+ check=True,
68
+ text=True,
69
+ capture_output=True
70
+ )
71
+
72
+ except subprocess.CalledProcessError as e:
73
+ traceback.print_exception(e)
74
+ logging.error("Command failed")
75
+
76
+ else:
77
+ logging.info("No running task")
78
+
79
+
80
+ def copy_ecr_image(
81
+ client,
82
+ source_repo_name: str,
83
+ target_repo_name: str,
84
+ image_tag: str = "latest",
85
+ ):
86
+ try:
87
+ # Get the image manifest from the source repo
88
+ get_response = client.batch_get_image(repositoryName=source_repo_name, imageIds=[{"imageTag": image_tag}])
89
+
90
+ if not get_response["images"]:
91
+ raise RuntimeError("Image not found in source repo")
92
+
93
+ image = get_response["images"][0]
94
+ manifest = image["imageManifest"]
95
+ media_type = image.get("imageManifestMediaType", "application/vnd.docker.distribution.manifest.v2+json")
96
+
97
+ # Push the manifest to the target repo
98
+ client.put_image(
99
+ repositoryName=target_repo_name,
100
+ imageManifest=manifest,
101
+ imageTag=image_tag,
102
+ imageManifestMediaType=media_type,
103
+ )
104
+
105
+ except (ClientError, BotoCoreError):
106
+ return False
107
+
108
+ return True