-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from darrida/dev-click-migration
"remove" and "clean-rollback" commands
- Loading branch information
Showing
18 changed files
with
543 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,36 @@ | ||
import sys | ||
from getpass import getpass | ||
from pathlib import Path | ||
|
||
from pydantic import SecretStr | ||
from shinylive_deploy.models import LocalShinyDeploy, ServerShinyDeploy, toml | ||
|
||
|
||
def main(): | ||
config_file = Path.cwd() / "shinylive_deploy.toml" | ||
if not config_file.exists(): | ||
from shinylive_deploy.data import create_config_file | ||
create_config_file() | ||
return | ||
|
||
mode, rollback = _parse_arguments() | ||
shinylive_ = _initialize_configuration(mode) | ||
|
||
if rollback is True: | ||
shinylive_.rollback() | ||
else: | ||
shinylive_.deploy() | ||
|
||
|
||
def _parse_arguments(test_argvs: list = None) -> tuple[str, bool]: | ||
if test_argvs: | ||
sys.argv = test_argvs | ||
if len(sys.argv) < 2 or sys.argv[1] not in ("test", "beta", "prod", "local"): | ||
raise ValueError("\nERROR: One of the following arguments is required -> [ local | test | beta | prod ]\n") | ||
deploy_mode = sys.argv[1] | ||
try: | ||
rollback = sys.argv[2] | ||
if rollback not in ("-r", "--rollback"): | ||
raise ValueError("2nd optional argument must be `-r` or `--rollback`") | ||
rollback = True | ||
except IndexError: | ||
rollback = False | ||
return deploy_mode, rollback | ||
|
||
|
||
def _initialize_configuration(deploy_mode: str) -> LocalShinyDeploy | ServerShinyDeploy: | ||
if deploy_mode in ("test", "beta", "prod"): | ||
config = toml["deploy"]["server"] | ||
return ServerShinyDeploy( | ||
mode=deploy_mode, | ||
base_url=config["base_url"], | ||
dir_deployment=config["directory"], | ||
host=config["host"], | ||
user=config["user"], | ||
port=config.get("port", 22), | ||
password=SecretStr(value=getpass(f"SSH password for [{config["user"]}]: ")) | ||
) | ||
else: # local | ||
config = toml["deploy"]["local"] | ||
return LocalShinyDeploy( | ||
mode=deploy_mode, | ||
base_url=config["base_url"], | ||
dir_deployment=config["directory"] | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() | ||
import click | ||
|
||
from .process import initialize | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
... | ||
|
||
|
||
@cli.command() | ||
@click.argument("deploy_mode") | ||
def deploy(deploy_mode: str): | ||
shinylive_ = initialize(deploy_mode) | ||
shinylive_.deploy() | ||
|
||
|
||
@cli.command() | ||
@click.argument("deploy_mode") | ||
def rollback(deploy_mode: str): | ||
shinylive_ = initialize(deploy_mode) | ||
shinylive_.rollback() | ||
|
||
|
||
@cli.command() | ||
@click.argument("deploy_mode") | ||
def clean_rollback(deploy_mode: str): | ||
shinylive_ = initialize(deploy_mode) | ||
shinylive_.clean_rollback() | ||
|
||
|
||
@cli.command() | ||
@click.argument("deploy_mode") | ||
def remove(deploy_mode: str): | ||
shinylive_ = initialize(deploy_mode) | ||
shinylive_.remove() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
import tomllib | ||
|
||
CONFIG_FILEPATH = os.environ.get("SHINYLIVE_DEPLOY_CONFIG", Path.cwd() / "shinylive_deploy.toml") | ||
|
||
|
||
toml_text = """ | ||
[general] | ||
app_name = "app1" | ||
[development] | ||
directory = "src" | ||
[deploy.gitbranch] | ||
prod = "main" | ||
beta = "main" | ||
[deploy.staging] | ||
directory = "staging" | ||
[deploy.local] | ||
directory = "src_test_webserver/shinyapps/" | ||
base_url = "http://localhost:8000/apps" | ||
[deploy.server] | ||
host = "127.0.0.1" | ||
user = "shinylive" | ||
port = 2222 | ||
directory = "shinyapps" | ||
base_url = "http://localhost:5000" | ||
""" | ||
|
||
|
||
def create_config(): | ||
if not CONFIG_FILEPATH.exists(): | ||
with open(CONFIG_FILEPATH, "w") as f: | ||
f.write(toml_text) | ||
|
||
|
||
def read_config() -> dict: | ||
if not CONFIG_FILEPATH.exists(): | ||
create_config() | ||
print(f"\n>>> WARNING <<<: {CONFIG_FILEPATH.name} did not yet exist. Default config file created. Please update, then run deploy again.\n") | ||
exit() | ||
with open(CONFIG_FILEPATH, "rb") as f: | ||
return tomllib.load(f) | ||
|
||
|
||
# if not CONFIG_FILEPATH.exists(): | ||
# create_config() | ||
toml = read_config() | ||
|
||
|
||
class Config: | ||
app_name = toml["general"]["app_name"] | ||
deploy_local = toml["deploy"]["local"] | ||
deploy_server = toml["deploy"]["server"] | ||
development: dict = toml.get("development", {}) | ||
staging: dict = toml["deploy"].get("staging", {}) | ||
gitbranch: dict = toml["deploy"].get("gitbranch", {}) | ||
|
||
config = Config() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from getpass import getpass | ||
|
||
from pydantic import SecretStr | ||
from shinylive_deploy.config import CONFIG_FILEPATH, create_config | ||
from shinylive_deploy.config import config as loaded_config | ||
|
||
from .local import LocalShinyDeploy | ||
from .server import ServerShinyDeploy | ||
|
||
|
||
def initialize(deploy_mode: str) -> LocalShinyDeploy | ServerShinyDeploy: | ||
if deploy_mode not in ("local", "test", "beta", "prod"): | ||
raise ValueError('`DEPLOY_MODE` must be on of the following: "local", "test", "beta", "prod"') | ||
|
||
if not CONFIG_FILEPATH.exists(): | ||
create_config() | ||
return | ||
if deploy_mode in ("test", "beta", "prod"): | ||
config = loaded_config.deploy_server | ||
return ServerShinyDeploy( | ||
mode=deploy_mode, | ||
base_url=config["base_url"], | ||
dir_deployment=config["directory"], | ||
host=config["host"], | ||
user=config["user"], | ||
port=config.get("port", 22), | ||
password=SecretStr(value=getpass(f"SSH password for [{config["user"]}]: ")) | ||
) | ||
else: # local | ||
config = loaded_config.deploy_local | ||
return LocalShinyDeploy( | ||
mode=deploy_mode, | ||
base_url=config["base_url"], | ||
dir_deployment=config["directory"] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.