fujin-cli 0.7.1__tar.gz → 0.8.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.
Potentially problematic release.
This version of fujin-cli might be problematic. Click here for more details.
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/CHANGELOG.md +6 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/PKG-INFO +1 -1
- fujin_cli-0.8.0/docs/hooks.rst +41 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/pyproject.toml +2 -2
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/commands/_base.py +8 -5
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/commands/deploy.py +6 -6
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/commands/down.py +0 -3
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/commands/redeploy.py +7 -8
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/commands/server.py +0 -3
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/config.py +3 -0
- fujin_cli-0.8.0/src/fujin/hooks.py +59 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/uv.lock +1 -1
- fujin_cli-0.7.1/docs/hooks.rst +0 -2
- fujin_cli-0.7.1/src/fujin/hooks.py +0 -56
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/.github/workflows/publish.yml +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/.gitignore +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/.pre-commit-config.yaml +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/.readthedocs.yaml +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/LICENSE.txt +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/README.md +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/Vagrantfile +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/changelog.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/commands/app.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/commands/config.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/commands/deploy.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/commands/docs.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/commands/down.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/commands/index.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/commands/init.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/commands/printenv.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/commands/proxy.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/commands/prune.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/commands/redeploy.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/commands/rollback.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/commands/server.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/commands/up.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/conf.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/configuration.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/index.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/installation.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/requirements.txt +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/secrets.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/docs/tutorial.rst +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/examples/django/bookstore/README.md +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/examples/django/bookstore/bookstore/__init__.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/examples/django/bookstore/bookstore/__main__.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/examples/django/bookstore/bookstore/asgi.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/examples/django/bookstore/bookstore/settings.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/examples/django/bookstore/bookstore/urls.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/examples/django/bookstore/bookstore/wsgi.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/examples/django/bookstore/fujin.toml +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/examples/django/bookstore/manage.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/examples/django/bookstore/pyproject.toml +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/examples/django/bookstore/requirements.txt +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/examples/golang/pocketbase/.env.prod +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/examples/golang/pocketbase/fujin.toml +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/justfile +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/__init__.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/__main__.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/commands/__init__.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/commands/app.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/commands/config.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/commands/docs.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/commands/init.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/commands/printenv.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/commands/proxy.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/commands/prune.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/commands/rollback.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/commands/up.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/connection.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/errors.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/process_managers/__init__.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/process_managers/systemd.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/proxies/__init__.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/proxies/caddy.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/proxies/dummy.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/proxies/nginx.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/secrets/__init__.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/secrets/bitwarden.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/secrets/onepassword.py +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/templates/simple.service +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/templates/web.service +0 -0
- {fujin_cli-0.7.1 → fujin_cli-0.8.0}/src/fujin/templates/web.socket +0 -0
|
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [0.8.0] - 2024-11-23
|
|
8
|
+
|
|
9
|
+
### 🚀 Features
|
|
10
|
+
|
|
11
|
+
- Rewrite hooks (#30)
|
|
12
|
+
|
|
7
13
|
## [0.7.1] - 2024-11-23
|
|
8
14
|
|
|
9
15
|
### 🐛 Bug Fixes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: fujin-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
4
4
|
Summary: Get your project up and running in a few minutes on your own vps.
|
|
5
5
|
Project-URL: Documentation, https://github.com/falcopackages/fujin#readme
|
|
6
6
|
Project-URL: Issues, https://github.com/falcopackages/fujin/issues
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Hooks
|
|
2
|
+
=====
|
|
3
|
+
|
|
4
|
+
Hooks allow you to run scripts at specific points in the deployment process. These scripts can perform checks before deployment, run tests, or send a notification after a successful deployment.
|
|
5
|
+
|
|
6
|
+
The currently available ``hooks`` are:
|
|
7
|
+
|
|
8
|
+
- ``pre_build``: The first action executed when the ``deploy`` command is run, before your app is built.
|
|
9
|
+
- ``pre_deploy``: Executed after app is built before the code is pushed to the remote server.
|
|
10
|
+
- ``post_deploy``: Executed after a successful deployment.
|
|
11
|
+
|
|
12
|
+
.. note::
|
|
13
|
+
|
|
14
|
+
Hooks are run on your local machine, not on the remote server. If they fail, the deployment process is stopped.
|
|
15
|
+
|
|
16
|
+
You can specify hooks in the ``fujin.toml`` file like this:
|
|
17
|
+
|
|
18
|
+
.. code-block::
|
|
19
|
+
|
|
20
|
+
[hooks]
|
|
21
|
+
pre_build = "echo 'hello'"
|
|
22
|
+
|
|
23
|
+
.. tip::
|
|
24
|
+
|
|
25
|
+
Using a `justfile <https://just.systems/>`_ can be an easy way to write more complex scripts without adding new files.
|
|
26
|
+
|
|
27
|
+
.. code-block::
|
|
28
|
+
|
|
29
|
+
[hooks]
|
|
30
|
+
pre_build = "just run-some-checks"
|
|
31
|
+
|
|
32
|
+
Alternatively, you can create a file with the hook's name in the ``.fujin/hooks`` folder and ensure the file is executable.
|
|
33
|
+
|
|
34
|
+
.. code-block::
|
|
35
|
+
:caption: .fujin/hooks/pre_build
|
|
36
|
+
|
|
37
|
+
#!/usr/bin/env bash
|
|
38
|
+
|
|
39
|
+
echo 'hello'
|
|
40
|
+
|
|
41
|
+
The ``hooks`` configuration takes precedence over files in the ``.fujin/hooks`` folder; you cannot mix and match both.
|
|
@@ -7,7 +7,7 @@ requires = [
|
|
|
7
7
|
|
|
8
8
|
[project]
|
|
9
9
|
name = "fujin-cli"
|
|
10
|
-
version = "0.
|
|
10
|
+
version = "0.8.0"
|
|
11
11
|
description = "Get your project up and running in a few minutes on your own vps."
|
|
12
12
|
readme = "README.md"
|
|
13
13
|
keywords = [
|
|
@@ -154,7 +154,7 @@ lint.isort.required-imports = [
|
|
|
154
154
|
lint.pyupgrade.keep-runtime-typing = true
|
|
155
155
|
|
|
156
156
|
[tool.bumpversion]
|
|
157
|
-
current_version = "0.
|
|
157
|
+
current_version = "0.8.0"
|
|
158
158
|
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
|
|
159
159
|
serialize = [
|
|
160
160
|
"{major}.{minor}.{patch}",
|
|
@@ -33,6 +33,14 @@ class BaseCommand:
|
|
|
33
33
|
def app_dir(self) -> str:
|
|
34
34
|
return self.config.host.get_app_dir(app_name=self.config.app_name)
|
|
35
35
|
|
|
36
|
+
@cached_property
|
|
37
|
+
def hook_manager(self) -> HookManager:
|
|
38
|
+
return HookManager(
|
|
39
|
+
hooks=self.config.hooks,
|
|
40
|
+
app_name=self.config.app_name,
|
|
41
|
+
local_config_dir=self.config.local_config_dir,
|
|
42
|
+
)
|
|
43
|
+
|
|
36
44
|
@contextmanager
|
|
37
45
|
def connection(self):
|
|
38
46
|
with host_connection(host=self.config.host) as conn:
|
|
@@ -70,8 +78,3 @@ class BaseCommand:
|
|
|
70
78
|
|
|
71
79
|
def create_process_manager(self, conn: Connection) -> ProcessManager:
|
|
72
80
|
return self.process_manager_class.create(conn=conn, config=self.config)
|
|
73
|
-
|
|
74
|
-
def create_hook_manager(self, conn: Connection) -> HookManager:
|
|
75
|
-
return HookManager(
|
|
76
|
-
conn=conn, hooks=self.config.hooks, app_name=self.config.app_name
|
|
77
|
-
)
|
|
@@ -16,15 +16,15 @@ from fujin.secrets import resolve_secrets
|
|
|
16
16
|
)
|
|
17
17
|
class Deploy(BaseCommand):
|
|
18
18
|
def __call__(self):
|
|
19
|
+
self.hook_manager.pre_build()
|
|
19
20
|
parsed_env = self.parse_envfile()
|
|
20
21
|
self.build_app()
|
|
21
|
-
|
|
22
|
+
self.hook_manager.pre_deploy()
|
|
22
23
|
with self.connection() as conn:
|
|
23
24
|
process_manager = self.create_process_manager(conn)
|
|
24
25
|
conn.run(f"mkdir -p {self.app_dir}")
|
|
25
26
|
conn.run(f"mkdir -p {self.versioned_assets_dir}")
|
|
26
27
|
with conn.cd(self.app_dir):
|
|
27
|
-
self.create_hook_manager(conn).pre_deploy()
|
|
28
28
|
self.transfer_files(conn, env=parsed_env)
|
|
29
29
|
self.install_project(conn)
|
|
30
30
|
with self.app_environment() as app_conn:
|
|
@@ -35,7 +35,7 @@ class Deploy(BaseCommand):
|
|
|
35
35
|
self.create_web_proxy(app_conn).setup()
|
|
36
36
|
self.update_version_history(app_conn)
|
|
37
37
|
self.prune_assets(app_conn)
|
|
38
|
-
|
|
38
|
+
self.hook_manager.post_deploy()
|
|
39
39
|
self.stdout.output("[green]Project deployment completed successfully![/green]")
|
|
40
40
|
self.stdout.output(
|
|
41
41
|
f"[blue]Access the deployed project at: https://{self.config.host.domain_name}[/blue]"
|
|
@@ -60,7 +60,7 @@ class Deploy(BaseCommand):
|
|
|
60
60
|
return self.config.host.envfile.read_text()
|
|
61
61
|
|
|
62
62
|
def transfer_files(
|
|
63
|
-
|
|
63
|
+
self, conn: Connection, env: str, skip_requirements: bool = False
|
|
64
64
|
):
|
|
65
65
|
conn.run(f"echo '{env}' > {self.app_dir}/.env")
|
|
66
66
|
distfile_path = self.config.get_distfile_path()
|
|
@@ -78,7 +78,7 @@ class Deploy(BaseCommand):
|
|
|
78
78
|
)
|
|
79
79
|
|
|
80
80
|
def install_project(
|
|
81
|
-
|
|
81
|
+
self, conn: Connection, version: str | None = None, *, skip_setup: bool = False
|
|
82
82
|
):
|
|
83
83
|
version = version or self.config.version
|
|
84
84
|
if self.config.installation_mode == InstallationMode.PY_PACKAGE:
|
|
@@ -87,7 +87,7 @@ class Deploy(BaseCommand):
|
|
|
87
87
|
self._install_binary(conn, version)
|
|
88
88
|
|
|
89
89
|
def _install_python_package(
|
|
90
|
-
|
|
90
|
+
self, conn: Connection, version: str, skip_setup: bool = False
|
|
91
91
|
):
|
|
92
92
|
appenv = f"""
|
|
93
93
|
set -a # Automatically export all variables
|
|
@@ -33,8 +33,6 @@ class Down(BaseCommand):
|
|
|
33
33
|
if not confirm:
|
|
34
34
|
return
|
|
35
35
|
with self.connection() as conn:
|
|
36
|
-
hook_manager = self.create_hook_manager(conn)
|
|
37
|
-
hook_manager.pre_teardown()
|
|
38
36
|
process_manager = self.create_process_manager(conn)
|
|
39
37
|
conn.run(f"rm -rf {self.app_dir}")
|
|
40
38
|
self.create_web_proxy(conn).teardown()
|
|
@@ -42,7 +40,6 @@ class Down(BaseCommand):
|
|
|
42
40
|
process_manager.reload_configuration()
|
|
43
41
|
if self.full:
|
|
44
42
|
self.create_web_proxy(conn).uninstall()
|
|
45
|
-
hook_manager.post_teardown()
|
|
46
43
|
self.stdout.output(
|
|
47
44
|
"[green]Project teardown completed successfully![/green]"
|
|
48
45
|
)
|
|
@@ -5,22 +5,21 @@ from pathlib import Path
|
|
|
5
5
|
|
|
6
6
|
import cappa
|
|
7
7
|
|
|
8
|
-
from .deploy import Deploy
|
|
9
8
|
from fujin.commands import BaseCommand
|
|
10
9
|
from fujin.config import InstallationMode
|
|
11
10
|
from fujin.connection import Connection
|
|
11
|
+
from .deploy import Deploy
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
@cappa.command(help="Redeploy the application to apply code and environment changes")
|
|
15
15
|
class Redeploy(BaseCommand):
|
|
16
16
|
def __call__(self):
|
|
17
17
|
deploy = Deploy()
|
|
18
|
+
self.hook_manager.pre_build()
|
|
18
19
|
parsed_env = deploy.parse_envfile()
|
|
19
20
|
deploy.build_app()
|
|
20
|
-
|
|
21
|
+
self.hook_manager.pre_deploy()
|
|
21
22
|
with self.app_environment() as conn:
|
|
22
|
-
hook_manager = self.create_hook_manager(conn)
|
|
23
|
-
hook_manager.pre_deploy()
|
|
24
23
|
conn.run(f"mkdir -p {deploy.versioned_assets_dir}")
|
|
25
24
|
requirements_copied = self._copy_requirements_if_needed(conn)
|
|
26
25
|
deploy.transfer_files(
|
|
@@ -30,13 +29,13 @@ class Redeploy(BaseCommand):
|
|
|
30
29
|
deploy.release(conn)
|
|
31
30
|
self.create_process_manager(conn).restart_services()
|
|
32
31
|
deploy.update_version_history(conn)
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
self.hook_manager.post_deploy()
|
|
33
|
+
self.stdout.output("[green]Redeployment completed successfully![/green]")
|
|
35
34
|
|
|
36
35
|
def _copy_requirements_if_needed(self, conn: Connection) -> bool:
|
|
37
36
|
if (
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
not self.config.requirements
|
|
38
|
+
or self.config.installation_mode == InstallationMode.BINARY
|
|
40
39
|
):
|
|
41
40
|
return False
|
|
42
41
|
local_requirements = hashlib.md5(
|
|
@@ -23,8 +23,6 @@ class Server(BaseCommand):
|
|
|
23
23
|
@cappa.command(help="Setup uv, web proxy, and install necessary dependencies")
|
|
24
24
|
def bootstrap(self):
|
|
25
25
|
with self.connection() as conn:
|
|
26
|
-
hook_manager = self.create_hook_manager(conn)
|
|
27
|
-
hook_manager.pre_bootstrap()
|
|
28
26
|
conn.run("sudo apt update && sudo apt upgrade -y", pty=True)
|
|
29
27
|
conn.run("sudo apt install -y sqlite3 curl rsync", pty=True)
|
|
30
28
|
result = conn.run("command -v uv", warn=True)
|
|
@@ -33,7 +31,6 @@ class Server(BaseCommand):
|
|
|
33
31
|
conn.run("uv tool update-shell")
|
|
34
32
|
conn.run("uv tool install fastfetch-bin-edge")
|
|
35
33
|
self.create_web_proxy(conn).install()
|
|
36
|
-
hook_manager.post_bootstrap()
|
|
37
34
|
self.stdout.output(
|
|
38
35
|
"[green]Server bootstrap completed successfully![/green]"
|
|
39
36
|
)
|
|
@@ -176,6 +176,9 @@ Example:
|
|
|
176
176
|
dbconsole = "app exec -i dbshell" # open an interactive django database shell
|
|
177
177
|
shell = "server exec --appenv -i bash" # SSH into the project directory with environment variables loaded
|
|
178
178
|
|
|
179
|
+
hooks
|
|
180
|
+
-----
|
|
181
|
+
Run custom scripts at specific points with hooks. Check out the `secrets </hooks.html>`_ page for more information.
|
|
179
182
|
|
|
180
183
|
"""
|
|
181
184
|
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import cappa
|
|
6
|
+
from rich import print as rich_print
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
from enum import StrEnum
|
|
10
|
+
except ImportError:
|
|
11
|
+
from enum import Enum
|
|
12
|
+
|
|
13
|
+
class StrEnum(str, Enum):
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Hook(StrEnum):
|
|
18
|
+
PRE_BUILD = "pre_build"
|
|
19
|
+
PRE_DEPLOY = "pre_deploy"
|
|
20
|
+
POST_DEPLOY = "post_deploy"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
HooksDict = dict[Hook, str]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass(slots=True)
|
|
27
|
+
class HookManager:
|
|
28
|
+
app_name: str
|
|
29
|
+
hooks: HooksDict
|
|
30
|
+
local_config_dir: Path
|
|
31
|
+
|
|
32
|
+
def __post_init__(self):
|
|
33
|
+
if self.hooks:
|
|
34
|
+
return
|
|
35
|
+
hooks_folder = self.local_config_dir / "hooks"
|
|
36
|
+
if not hooks_folder.exists():
|
|
37
|
+
return
|
|
38
|
+
self.hooks = {
|
|
39
|
+
h.value: f"./{hooks_folder / h.value}" # noqa
|
|
40
|
+
for h in Hook
|
|
41
|
+
if (hooks_folder / h.value).exists() # noqa
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
def _run_hook(self, type_: Hook) -> None:
|
|
45
|
+
if cmd := self.hooks.get(type_):
|
|
46
|
+
rich_print(f"[blue]Running {type_} hook[/blue]")
|
|
47
|
+
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
|
|
48
|
+
if result.returncode != 0:
|
|
49
|
+
raise cappa.Exit(result.stderr)
|
|
50
|
+
rich_print(result.stdout)
|
|
51
|
+
|
|
52
|
+
def pre_build(self) -> None:
|
|
53
|
+
self._run_hook(Hook.PRE_BUILD)
|
|
54
|
+
|
|
55
|
+
def pre_deploy(self) -> None:
|
|
56
|
+
self._run_hook(Hook.PRE_DEPLOY)
|
|
57
|
+
|
|
58
|
+
def post_deploy(self) -> None:
|
|
59
|
+
self._run_hook(Hook.POST_DEPLOY)
|
fujin_cli-0.7.1/docs/hooks.rst
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
from dataclasses import dataclass
|
|
2
|
-
|
|
3
|
-
from rich import print as rich_print
|
|
4
|
-
|
|
5
|
-
from fujin.connection import Connection
|
|
6
|
-
|
|
7
|
-
try:
|
|
8
|
-
from enum import StrEnum
|
|
9
|
-
except ImportError:
|
|
10
|
-
from enum import Enum
|
|
11
|
-
|
|
12
|
-
class StrEnum(str, Enum):
|
|
13
|
-
pass
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class Hook(StrEnum):
|
|
17
|
-
PRE_DEPLOY = "pre_deploy"
|
|
18
|
-
POST_DEPLOY = "post_deploy"
|
|
19
|
-
PRE_BOOTSTRAP = "pre_bootstrap"
|
|
20
|
-
POST_BOOTSTRAP = "post_bootstrap"
|
|
21
|
-
PRE_TEARDOWN = "pre_teardown"
|
|
22
|
-
POST_TEARDOWN = "post_teardown"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
HooksDict = dict[Hook, dict]
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
@dataclass(frozen=True, slots=True)
|
|
29
|
-
class HookManager:
|
|
30
|
-
app_name: str
|
|
31
|
-
hooks: HooksDict
|
|
32
|
-
conn: Connection
|
|
33
|
-
|
|
34
|
-
def _run_hook(self, type_: Hook) -> None:
|
|
35
|
-
if hooks := self.hooks.get(type_):
|
|
36
|
-
for name, command in hooks.items():
|
|
37
|
-
rich_print(f"[blue]Running {type_} hook {name} [/blue]")
|
|
38
|
-
self.conn.run(command, pty=True)
|
|
39
|
-
|
|
40
|
-
def pre_deploy(self) -> None:
|
|
41
|
-
self._run_hook(Hook.PRE_DEPLOY)
|
|
42
|
-
|
|
43
|
-
def post_deploy(self) -> None:
|
|
44
|
-
self._run_hook(Hook.POST_DEPLOY)
|
|
45
|
-
|
|
46
|
-
def pre_bootstrap(self) -> None:
|
|
47
|
-
self._run_hook(Hook.PRE_BOOTSTRAP)
|
|
48
|
-
|
|
49
|
-
def post_bootstrap(self) -> None:
|
|
50
|
-
self._run_hook(Hook.POST_BOOTSTRAP)
|
|
51
|
-
|
|
52
|
-
def pre_teardown(self) -> None:
|
|
53
|
-
self._run_hook(Hook.PRE_TEARDOWN)
|
|
54
|
-
|
|
55
|
-
def post_teardown(self) -> None:
|
|
56
|
-
self._run_hook(Hook.POST_TEARDOWN)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|