reflex-hosting-cli 0.1.26__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 (28) hide show
  1. reflex_hosting_cli-0.1.26/LICENSE +201 -0
  2. reflex_hosting_cli-0.1.26/PKG-INFO +35 -0
  3. reflex_hosting_cli-0.1.26/README.md +2 -0
  4. reflex_hosting_cli-0.1.26/pyproject.toml +76 -0
  5. reflex_hosting_cli-0.1.26/reflex_cli/__init__.py +1 -0
  6. reflex_hosting_cli-0.1.26/reflex_cli/cli.py +362 -0
  7. reflex_hosting_cli-0.1.26/reflex_cli/constants/__init__.py +8 -0
  8. reflex_hosting_cli-0.1.26/reflex_cli/constants/base.py +48 -0
  9. reflex_hosting_cli-0.1.26/reflex_cli/constants/compiler.py +31 -0
  10. reflex_hosting_cli-0.1.26/reflex_cli/constants/hosting.py +46 -0
  11. reflex_hosting_cli-0.1.26/reflex_cli/deployments.py +354 -0
  12. reflex_hosting_cli-0.1.26/reflex_cli/utils/__init__.py +1 -0
  13. reflex_hosting_cli-0.1.26/reflex_cli/utils/console.py +155 -0
  14. reflex_hosting_cli-0.1.26/reflex_cli/utils/dependency.py +132 -0
  15. reflex_hosting_cli-0.1.26/reflex_cli/utils/hosting.py +1908 -0
  16. reflex_hosting_cli-0.1.26/reflex_cli/v2/__init__.py +1 -0
  17. reflex_hosting_cli-0.1.26/reflex_cli/v2/cli.py +246 -0
  18. reflex_hosting_cli-0.1.26/reflex_cli/v2/constants/__init__.py +8 -0
  19. reflex_hosting_cli-0.1.26/reflex_cli/v2/constants/base.py +48 -0
  20. reflex_hosting_cli-0.1.26/reflex_cli/v2/constants/compiler.py +31 -0
  21. reflex_hosting_cli-0.1.26/reflex_cli/v2/constants/hosting.py +51 -0
  22. reflex_hosting_cli-0.1.26/reflex_cli/v2/consts.py +38 -0
  23. reflex_hosting_cli-0.1.26/reflex_cli/v2/deployments.py +888 -0
  24. reflex_hosting_cli-0.1.26/reflex_cli/v2/utils/__init__.py +1 -0
  25. reflex_hosting_cli-0.1.26/reflex_cli/v2/utils/console.py +160 -0
  26. reflex_hosting_cli-0.1.26/reflex_cli/v2/utils/dependency.py +121 -0
  27. reflex_hosting_cli-0.1.26/reflex_cli/v2/utils/exceptions.py +9 -0
  28. reflex_hosting_cli-0.1.26/reflex_cli/v2/utils/hosting.py +1393 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ https://www.apache.org/licenses/LICENSE-2.0
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2023, Pynecone, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,35 @@
1
+ Metadata-Version: 2.1
2
+ Name: reflex-hosting-cli
3
+ Version: 0.1.26
4
+ Summary: Reflex Hosting CLI
5
+ Home-page: https://reflex.dev
6
+ License: Apache-2.0
7
+ Keywords: web,framework
8
+ Author: Nikhil Rao
9
+ Author-email: nikhil@reflex.dev
10
+ Requires-Python: >=3.8,<4.0
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Requires-Dist: charset-normalizer (>=3.3.2,<4.0.0)
20
+ Requires-Dist: httpx (>=0.25.1,<1.0)
21
+ Requires-Dist: pipdeptree (>=2.13.1,<2.17.0)
22
+ Requires-Dist: platformdirs (>=3.10.0,<5.0)
23
+ Requires-Dist: pydantic (>=1.10.2,<3.0)
24
+ Requires-Dist: python-dateutil (>=2.8.1)
25
+ Requires-Dist: rich (>=13.0.0,<14.0)
26
+ Requires-Dist: tabulate (>=0.9.0,<0.10.0)
27
+ Requires-Dist: typer (>=0.15.0,<1)
28
+ Requires-Dist: websockets (>=10.4)
29
+ Project-URL: Documentation, https://reflex.dev/docs/getting-started/introduction
30
+ Project-URL: Repository, https://github.com/reflex-dev/reflex
31
+ Description-Content-Type: text/markdown
32
+
33
+ # reflex-hosting-cli
34
+ Hosting CLI for Reflex.
35
+
@@ -0,0 +1,2 @@
1
+ # reflex-hosting-cli
2
+ Hosting CLI for Reflex.
@@ -0,0 +1,76 @@
1
+ [tool.poetry]
2
+ name = "reflex-hosting-cli"
3
+ version = "0.1.26"
4
+ description = "Reflex Hosting CLI"
5
+ license = "Apache-2.0"
6
+ authors = [
7
+ "Nikhil Rao <nikhil@reflex.dev>",
8
+ "Alek Petuskey <alek@reflex.dev>",
9
+ ]
10
+ readme = "README.md"
11
+ homepage = "https://reflex.dev"
12
+ repository = "https://github.com/reflex-dev/reflex"
13
+ documentation = "https://reflex.dev/docs/getting-started/introduction"
14
+ keywords = ["web", "framework"]
15
+ classifiers = ["Development Status :: 4 - Beta"]
16
+ packages = [{ include = "reflex_cli" }]
17
+
18
+ [tool.poetry.dependencies]
19
+ python = "^3.8"
20
+ typer = ">=0.15.0,<1"
21
+ tabulate = "^0.9.0"
22
+ platformdirs = ">=3.10.0,<5.0"
23
+ pydantic = ">=1.10.2,<3.0"
24
+ websockets = ">=10.4"
25
+ httpx = ">=0.25.1,<1.0"
26
+ rich = ">=13.0.0,<14.0"
27
+ pipdeptree = ">=2.13.1,<2.17.0"
28
+ charset-normalizer = ">=3.3.2,<4.0.0"
29
+ python-dateutil = ">=2.8.1"
30
+
31
+ [tool.poetry.group.dev.dependencies]
32
+ pytest = "^7.1.2"
33
+ pyright = ">=1.1.229,<1.1.335"
34
+ darglint = "^1.8.1"
35
+ pytest-cov = "^4.0.0"
36
+ black = "^22.10.0"
37
+ ruff = "^0.0.244"
38
+ pre-commit = { version = "^3.2.1", python = ">=3.8,<4.0" }
39
+ types-tabulate = "^0.9.0.3"
40
+ pytest-benchmark = "^4.0.0"
41
+ pytest-mock = "^3.10.0"
42
+ packaging = "^23.2"
43
+ coverage = "^7.3.2"
44
+
45
+ [build-system]
46
+ requires = ["poetry-core>=1.5.1"]
47
+ build-backend = "poetry.core.masonry.api"
48
+
49
+ [tool.pyright]
50
+
51
+ [tool.ruff]
52
+
53
+ select = ["B", "D", "E", "F", "I", "SIM", "W"]
54
+
55
+ ignore = [
56
+ "B008",
57
+ "D203",
58
+ "D205",
59
+ "D213",
60
+ "D401",
61
+ "D406",
62
+ "D407",
63
+ "E501",
64
+ "F403",
65
+ "F405",
66
+ "F541",
67
+ ]
68
+
69
+ target-version = "py37"
70
+
71
+ [tool.ruff.per-file-ignores]
72
+
73
+ "__init__.py" = ["F401"]
74
+ "tests/*.py" = ["D100", "D103", "D104"]
75
+ "reflex/.templates/*.py" = ["D100", "D103", "D104"]
76
+ "*.pyi" = ["ALL"]
@@ -0,0 +1 @@
1
+ """CLI library for the hosting service."""
@@ -0,0 +1,362 @@
1
+ """CLI for the hosting service."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import shutil
7
+ import tempfile
8
+ from datetime import datetime
9
+ from typing import Callable
10
+
11
+ from reflex_cli import constants
12
+ from reflex_cli.utils import console
13
+
14
+
15
+ def login(
16
+ loglevel: str = constants.LogLevel.INFO.value,
17
+ ):
18
+ """Authenticate with Reflex hosting service.
19
+
20
+ Args:
21
+ loglevel: The log level to use.
22
+
23
+ Raises:
24
+ SystemExit: If the command fails.
25
+ """
26
+ from reflex_cli.utils import hosting
27
+
28
+ # Set the log level.
29
+ console.set_log_level(constants.LogLevel(loglevel))
30
+
31
+ access_token, invitation_code = hosting.authenticated_token()
32
+ if access_token:
33
+ console.print("You already logged in.")
34
+ return
35
+
36
+ # If not already logged in, open a browser window/tab to the login page.
37
+ access_token = hosting.authenticate_on_browser(invitation_code)
38
+
39
+ if not access_token:
40
+ console.error(f"Unable to authenticate. Please try again or contact support.")
41
+ raise SystemExit(1)
42
+
43
+ console.print("Successfully logged in.")
44
+
45
+
46
+ def logout(
47
+ loglevel: str = constants.LogLevel.INFO.value,
48
+ ):
49
+ """Log out of access to Reflex hosting service.
50
+
51
+ Args:
52
+ loglevel: The log level to use.
53
+ """
54
+ from reflex_cli.utils import hosting
55
+
56
+ console.set_log_level(constants.LogLevel(loglevel))
57
+
58
+ hosting.log_out_on_browser()
59
+ console.debug("Deleting access token from config locally")
60
+ hosting.delete_token_from_config(include_invitation_code=True)
61
+
62
+
63
+ def deploy(
64
+ app_name: str,
65
+ export_fn: Callable[[str, str, str, bool, bool, bool], None],
66
+ regions: list[str] | None = None,
67
+ key: str | None = None,
68
+ envs: list[str] | None = None,
69
+ cpus: int | None = None,
70
+ memory_mb: int | None = None,
71
+ auto_start: bool | None = None,
72
+ auto_stop: bool | None = None,
73
+ frontend_hostname: str | None = None,
74
+ interactive: bool = True,
75
+ with_metrics: str | None = None,
76
+ with_tracing: str | None = None,
77
+ share_deployment: bool | None = None,
78
+ loglevel: str = constants.LogLevel.INFO.value,
79
+ ):
80
+ """Deploy the app to the Reflex hosting service.
81
+
82
+ Args:
83
+ app_name: The name of the app.
84
+ export_fn: The function from the reflex main framework to export the app.
85
+ regions: The regions to deploy to.
86
+ key: The deployment key.
87
+ envs: The environment variables to set.
88
+ cpus: The number of CPUs to allocate.
89
+ memory_mb: The amount of memory to allocate in MB.
90
+ auto_start: Whether to automatically start the deployment.
91
+ auto_stop: Whether to automatically stop the deployment.
92
+ frontend_hostname: The hostname to use for the frontend.
93
+ interactive: Whether to use interactive mode.
94
+ with_metrics: The metrics prefix to use if enabling metrics.
95
+ with_tracing: The tracing prefix to use if enabling tracing.
96
+ share_deployment: Whether to share the deployment. If None, prompt the user when in interactive mode.
97
+ loglevel: The log level to use.
98
+
99
+ Raises:
100
+ SystemExit: If the command fails.
101
+ """
102
+ from reflex_cli.utils import hosting
103
+
104
+ # Set the log level.
105
+ console.set_log_level(constants.LogLevel(loglevel))
106
+
107
+ envs = envs or []
108
+ api_url = ""
109
+ deploy_url = ""
110
+
111
+ if not interactive and not key:
112
+ console.error(
113
+ "Please provide a name for the deployed instance when not in interactive mode."
114
+ )
115
+ raise SystemExit(1)
116
+
117
+ if interactive and share_deployment is None:
118
+ if (
119
+ console.ask(
120
+ "Do you want to share your app in the Gallery?",
121
+ choices=["y", "n"],
122
+ default="y",
123
+ )
124
+ == "y"
125
+ ):
126
+ share_deployment = True
127
+ console.print(
128
+ "We will ask for more information later. Let's proceed to deploy."
129
+ )
130
+ else:
131
+ share_deployment = False
132
+ console.print(
133
+ "No worries. You can do this later by running `reflex deployments share`."
134
+ )
135
+
136
+ enabled_regions = None
137
+ # If there is already a key, then it is passed in from CLI option in the non-interactive mode
138
+ if key is not None and not hosting.is_valid_deployment_key(key):
139
+ console.error(
140
+ f"Deployment key {key} is not valid. Please use only domain name safe characters."
141
+ )
142
+ raise SystemExit(1)
143
+ try:
144
+ # Send a request to server to obtain necessary information
145
+ # in preparation of a deployment. For example,
146
+ # server can return confirmation of a particular deployment key,
147
+ # is available, or suggest a new key, or return an existing deployment.
148
+ # Some of these are used in the interactive mode.
149
+ pre_deploy_response = hosting.prepare_deploy(
150
+ app_name, key=key, frontend_hostname=frontend_hostname
151
+ )
152
+ # Note: we likely won't need to fetch this twice
153
+ if pre_deploy_response.enabled_regions is not None:
154
+ enabled_regions = pre_deploy_response.enabled_regions
155
+
156
+ except Exception as ex:
157
+ console.error(f"Unable to prepare deployment")
158
+ raise SystemExit(1) from ex
159
+
160
+ # The app prefix should not change during the time of preparation
161
+ app_prefix = pre_deploy_response.app_prefix
162
+ if not interactive:
163
+ # in this case, the key was supplied for the pre_deploy call, at this point the reply is expected
164
+ if (reply := pre_deploy_response.reply) is None:
165
+ console.error(f"Unable to deploy at this name {key}.")
166
+ raise SystemExit(1)
167
+ api_url = reply.api_url
168
+ deploy_url = reply.deploy_url
169
+ else:
170
+ (
171
+ key_candidate,
172
+ api_url,
173
+ deploy_url,
174
+ ) = hosting.interactive_get_deployment_key_from_user_input(
175
+ pre_deploy_response, app_name, frontend_hostname=frontend_hostname
176
+ )
177
+ if not key_candidate or not api_url or not deploy_url:
178
+ console.error("Unable to find a suitable deployment key.")
179
+ raise SystemExit(1)
180
+
181
+ # Now copy over the candidate to the key
182
+ key = key_candidate
183
+
184
+ regions = hosting.prompt_for_regions(
185
+ enabled_regions=enabled_regions, regions_args=regions
186
+ )
187
+
188
+ # process the envs
189
+ envs = hosting.interactive_prompt_for_envs()
190
+
191
+ # Check the required params are valid
192
+ console.debug(
193
+ f"{key=}, {regions=}, {app_name=}, {app_prefix=}, {api_url=}, {deploy_url=}"
194
+ )
195
+ if (
196
+ not key
197
+ or not regions
198
+ or not app_name
199
+ or not app_prefix
200
+ or not api_url
201
+ or not deploy_url
202
+ ):
203
+ console.error("Please provide all the required parameters.")
204
+ raise SystemExit(1)
205
+ # Note: if the user uses --no-interactive mode, there was no prepare_deploy call
206
+ # so we do not check the regions until the call to hosting server
207
+
208
+ processed_envs = hosting.process_envs(envs) if envs else None
209
+
210
+ # Compile the app in production mode: backend first then frontend.
211
+ tmp_dir = tempfile.mkdtemp()
212
+
213
+ # Try zipping backend first
214
+ try:
215
+ export_fn(tmp_dir, api_url, deploy_url, False, True, True)
216
+ except Exception as ex:
217
+ console.error(f"Unable to export due to: {ex}")
218
+ if os.path.exists(tmp_dir):
219
+ shutil.rmtree(tmp_dir)
220
+ raise SystemExit(1) from ex
221
+
222
+ backend_file_name = constants.ComponentName.BACKEND.zip()
223
+
224
+ console.print("Uploading Backend code and sending request ...")
225
+ backend_deploy_requested_at = datetime.now().astimezone()
226
+ console.debug(f"{backend_deploy_requested_at=}")
227
+ try:
228
+ backend_deploy_response = hosting.deploy_backend(
229
+ backend_file_name=backend_file_name,
230
+ export_dir=tmp_dir,
231
+ key=key,
232
+ app_name=app_name,
233
+ regions=regions,
234
+ app_prefix=app_prefix,
235
+ cpus=cpus,
236
+ memory_mb=memory_mb,
237
+ auto_start=auto_start,
238
+ auto_stop=auto_stop,
239
+ envs=processed_envs,
240
+ with_metrics=with_metrics,
241
+ with_tracing=with_tracing,
242
+ )
243
+ except Exception as ex:
244
+ console.error(f"Unable to deploy due to: {ex}")
245
+ if os.path.exists(tmp_dir):
246
+ shutil.rmtree(tmp_dir)
247
+ raise SystemExit(1) from ex
248
+
249
+ if backend_deploy_response.sidecar_url is None:
250
+ console.error(
251
+ "Deploy backend response from server missing sidecar_url. This is unexpected. Contact support."
252
+ )
253
+ raise SystemExit(1)
254
+
255
+ # Deployment will actually start when data plane reconciles this request
256
+ console.debug(f"deploy_response: {backend_deploy_response}")
257
+ console.print("[bold]Backend deployment will start shortly.")
258
+
259
+ # Zip frontend
260
+ try:
261
+ export_fn(tmp_dir, api_url, deploy_url, True, False, True)
262
+ except ImportError as ie:
263
+ console.error(
264
+ f"Encountered ImportError, did you install all the dependencies? {ie}"
265
+ )
266
+ if os.path.exists(tmp_dir):
267
+ shutil.rmtree(tmp_dir)
268
+ raise SystemExit(1) from ie
269
+ except Exception as ex:
270
+ console.error(f"Unable to export due to: {ex}")
271
+ if os.path.exists(tmp_dir):
272
+ shutil.rmtree(tmp_dir)
273
+ raise SystemExit(1) from ex
274
+
275
+ frontend_file_name = constants.ComponentName.FRONTEND.zip()
276
+
277
+ console.print("Uploading Frontend code and sending request ...")
278
+ frontend_deploy_requested_at = datetime.now().astimezone()
279
+ console.debug(f"{frontend_deploy_requested_at=}")
280
+ try:
281
+ frontend_deploy_response = hosting.deploy_frontend(
282
+ frontend_file_name=frontend_file_name,
283
+ export_dir=tmp_dir,
284
+ initiator_event_id=backend_deploy_response.event_id,
285
+ app_prefix=app_prefix,
286
+ frontend_hostname=frontend_hostname,
287
+ )
288
+ except Exception as ex:
289
+ console.error(f"Unable to deploy due to: {ex}")
290
+ raise SystemExit(1) from ex
291
+ finally:
292
+ if os.path.exists(tmp_dir):
293
+ shutil.rmtree(tmp_dir)
294
+ console.debug(f"deploy_response: {frontend_deploy_response}")
295
+ console.print("[bold]Frontend deployment will start shortly.")
296
+
297
+ console.rule("[bold]Deploying production app.")
298
+ console.print(
299
+ f"[bold]Deployment will start shortly: {frontend_deploy_response.url} \nClosing this command now will not affect your deployment."
300
+ )
301
+
302
+ # If user elected to share the deployment, instead of just waiting, collect information from them.
303
+ if share_deployment:
304
+ hosting.collect_deployment_info_interactive(
305
+ demo_url=frontend_deploy_response.url
306
+ )
307
+ else:
308
+ # It takes a few seconds for the deployment request to be picked up by server
309
+ hosting.wait_for_server_to_pick_up_request()
310
+
311
+ console.print("Waiting for server to report progress ...")
312
+ # Display the key events such as build, deploy, etc based on the deploy event IDs from hosting service
313
+ server_report_deploy_success = hosting.poll_deploy_milestones(
314
+ key,
315
+ from_iso_timestamp=backend_deploy_requested_at,
316
+ deploy_event_ids=[
317
+ backend_deploy_response.event_id,
318
+ frontend_deploy_response.event_id,
319
+ ],
320
+ )
321
+
322
+ if server_report_deploy_success is None:
323
+ console.warn("The deployment may still be in progress. Proceeding ...")
324
+ elif not server_report_deploy_success:
325
+ console.error("Hosting server reports failure.")
326
+ console.error(
327
+ f"Check for more server logs using `reflex deployments build-logs {key}`"
328
+ )
329
+ raise SystemExit(1)
330
+
331
+ console.print("Waiting for the new deployment to come up")
332
+ backend_reachable, backend_poll_err = hosting.poll_backend_with_retries(
333
+ key=key,
334
+ from_iso_timestamp=datetime.now().astimezone(),
335
+ backend_url=backend_deploy_response.url,
336
+ sidecar_url=backend_deploy_response.sidecar_url,
337
+ )
338
+ if not backend_reachable:
339
+ if backend_poll_err is not None:
340
+ print(backend_poll_err)
341
+ console.error("Backend unreachable")
342
+ console.warn(
343
+ f"Check for more logs in your App, using `reflex deployments logs {key}`"
344
+ )
345
+ raise SystemExit(1)
346
+
347
+ if not (
348
+ frontend_reachable := hosting.poll_frontend_with_retries(
349
+ frontend_url=frontend_deploy_response.url
350
+ )
351
+ ):
352
+ console.error("Frontend unreachable")
353
+ raise SystemExit(1)
354
+
355
+ if backend_reachable and frontend_reachable:
356
+ console.print(
357
+ f"Your site [ {key} ] at {regions} is up: {frontend_deploy_response.url}"
358
+ )
359
+ return
360
+ console.warn(f"Your deployment is taking unusually long.")
361
+ console.warn(f"Check back later on its status: `reflex deployments status {key}`")
362
+ console.warn(f"For logs: `reflex deployments logs {key}`")
@@ -0,0 +1,8 @@
1
+ """The constants package."""
2
+
3
+
4
+ from .base import LogLevel, Reflex
5
+ from .compiler import ComponentName
6
+ from .hosting import Hosting, ReflexHostingCli, RequirementsTxt
7
+
8
+ __ALL__ = [Hosting, LogLevel, Reflex, ComponentName, ReflexHostingCli, RequirementsTxt]