Skip to content

Commit

Permalink
Working POC with create config logic
Browse files Browse the repository at this point in the history
  • Loading branch information
darrida committed Jul 2, 2024
1 parent 062c9f1 commit 50b67a5
Show file tree
Hide file tree
Showing 10 changed files with 317 additions and 223 deletions.
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "shinylive_deloy_webserver"
version = "2024.6.29"
name = "shinylive_deloy"
version = "2024.7.1"
authors = [
{name="darrida", email="darrida.py@gmail.com"}
]
Expand All @@ -22,6 +22,9 @@ tests = [
'shinyswatch',
]

[project.scripts]
shinylive_deploy = "shinylive_deploy.app:main"

[project.urls]
Homepage = "https://github.com/darrida/py-shinylive-deploy-webserver"
Issues = "https://github.com/darrida/py-shinylive-deploy-webserver/issues"
Expand Down
2 changes: 1 addition & 1 deletion shiny_deploy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ host = "127.0.0.1"
user = "shinylive"
port = 2222
directory = "shinyapps"
base_url = "http://localhost:5000/"
base_url = "http://localhost:5000"
Empty file removed shinylive_deploy/__init__.py
Empty file.
208 changes: 0 additions & 208 deletions shinylive_deploy/models.py

This file was deleted.

41 changes: 29 additions & 12 deletions shinylive_deploy/main.py → src/shinylive_deploy/app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
import sys
from getpass import getpass
from pathlib import Path

from models import LocalShinyDeploy, ServerShinyDeploy, toml
from pydantic import SecretStr
from shinylive_deploy.data import create_config_file
from shinylive_deploy.models import LocalShinyDeploy, ServerShinyDeploy, toml

if __name__ == "__main__":
# parse arguments

def main():
config_file = Path.cwd() / "shinylive_deploy.toml"
if not config_file.exists():
create_config_file()
return

mode, rollback = _parse_arguments()
shinylive_ = _initialize_configuration(mode)

if rollback is True:
shinylive_.rollback()
else:
shinylive_.deploy()


def _parse_arguments() -> tuple[str, bool]:
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]
Expand All @@ -16,11 +33,13 @@
rollback = True
except IndexError:
rollback = False
return deploy_mode, rollback

# initialize configuration

def _initialize_configuration(deploy_mode: str):
if deploy_mode in ("test", "beta", "prod"):
config = toml["deploy"]["server"]
shinylive_ = ServerShinyDeploy(
return ServerShinyDeploy(
mode=deploy_mode,
base_url=config["base_url"],
dir_deployment=config["directory"],
Expand All @@ -31,14 +50,12 @@
)
else: # local
config = toml["deploy"]["local"]
shinylive_ = LocalShinyDeploy(
return LocalShinyDeploy(
mode=deploy_mode,
base_url=config["base_url"],
dir_deployment=config["directory"]
)

# execute deployment change
if rollback is True:
shinylive_.rollback()
else:
shinylive_.deploy()


if __name__ == "__main__":
main()
33 changes: 33 additions & 0 deletions src/shinylive_deploy/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from pathlib import Path


def create_config_file():
text = """
[general]
app_name = "app1"
[development]
directory = "src_dev/app1"
[deploy.gitbranch]
prod = "main"
beta = "main"
[deploy.staging]
directory = "staging"
[deploy.local]
directory = "src_test_webserver/shinyapps/"
base_url = "localhost:8000/apps"
[deploy.server]
host = "127.0.0.1"
user = "shinylive"
port = 2222
directory = "shinyapps"
base_url = "http://localhost:5000"
"""

with open(Path.cwd() / "shinylive_deploy.toml", "w") as f:
f.write(text)

5 changes: 5 additions & 0 deletions src/shinylive_deploy/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .base import toml
from .local import LocalShinyDeploy
from .server import ServerShinyDeploy

__all__ = [toml, LocalShinyDeploy, ServerShinyDeploy]
Loading

0 comments on commit 50b67a5

Please sign in to comment.