tinybird 0.0.1.dev212__py3-none-any.whl → 0.0.1.dev213__py3-none-any.whl
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 tinybird might be problematic. Click here for more details.
- tinybird/tb/__cli__.py +2 -2
- tinybird/tb/modules/local.py +8 -237
- tinybird/tb/modules/local_common.py +5 -1
- {tinybird-0.0.1.dev212.dist-info → tinybird-0.0.1.dev213.dist-info}/METADATA +1 -1
- {tinybird-0.0.1.dev212.dist-info → tinybird-0.0.1.dev213.dist-info}/RECORD +8 -8
- {tinybird-0.0.1.dev212.dist-info → tinybird-0.0.1.dev213.dist-info}/WHEEL +0 -0
- {tinybird-0.0.1.dev212.dist-info → tinybird-0.0.1.dev213.dist-info}/entry_points.txt +0 -0
- {tinybird-0.0.1.dev212.dist-info → tinybird-0.0.1.dev213.dist-info}/top_level.txt +0 -0
tinybird/tb/__cli__.py
CHANGED
|
@@ -4,5 +4,5 @@ __description__ = 'Tinybird Command Line Tool'
|
|
|
4
4
|
__url__ = 'https://www.tinybird.co/docs/forward/commands'
|
|
5
5
|
__author__ = 'Tinybird'
|
|
6
6
|
__author_email__ = 'support@tinybird.co'
|
|
7
|
-
__version__ = '0.0.1.
|
|
8
|
-
__revision__ = '
|
|
7
|
+
__version__ = '0.0.1.dev213'
|
|
8
|
+
__revision__ = '36a1e58'
|
tinybird/tb/modules/local.py
CHANGED
|
@@ -1,249 +1,20 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import os
|
|
3
|
-
import re
|
|
4
1
|
import subprocess
|
|
5
|
-
import time
|
|
6
|
-
from typing import Optional
|
|
7
2
|
|
|
8
|
-
import boto3
|
|
9
3
|
import click
|
|
10
4
|
import requests
|
|
11
5
|
|
|
12
|
-
import docker
|
|
13
6
|
from docker.client import DockerClient
|
|
14
|
-
from docker.models.containers import Container
|
|
15
7
|
from tinybird.tb.modules.cli import cli
|
|
16
8
|
from tinybird.tb.modules.common import coro
|
|
17
|
-
from tinybird.tb.modules.exceptions import CLIException
|
|
9
|
+
from tinybird.tb.modules.exceptions import CLIException
|
|
18
10
|
from tinybird.tb.modules.feedback_manager import FeedbackManager
|
|
19
|
-
from tinybird.tb.modules.local_common import
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
) -> None:
|
|
27
|
-
"""Start the Tinybird container."""
|
|
28
|
-
pull_show_prompt = False
|
|
29
|
-
pull_required = False
|
|
30
|
-
try:
|
|
31
|
-
local_image = docker_client.images.get(TB_IMAGE_NAME)
|
|
32
|
-
local_image_id = local_image.attrs["RepoDigests"][0].split("@")[1]
|
|
33
|
-
remote_image = docker_client.images.get_registry_data(TB_IMAGE_NAME)
|
|
34
|
-
pull_show_prompt = local_image_id != remote_image.id
|
|
35
|
-
except Exception:
|
|
36
|
-
pull_show_prompt = False
|
|
37
|
-
pull_required = True
|
|
38
|
-
|
|
39
|
-
if pull_show_prompt and click.confirm(
|
|
40
|
-
FeedbackManager.warning(message="△ New version detected, download? [y/N]:"),
|
|
41
|
-
show_default=False,
|
|
42
|
-
prompt_suffix="",
|
|
43
|
-
):
|
|
44
|
-
click.echo(FeedbackManager.info(message="* Downloading latest version of Tinybird Local..."))
|
|
45
|
-
pull_required = True
|
|
46
|
-
|
|
47
|
-
if pull_required:
|
|
48
|
-
docker_client.images.pull(TB_IMAGE_NAME, platform="linux/amd64")
|
|
49
|
-
|
|
50
|
-
environment = get_use_aws_creds() if use_aws_creds else {}
|
|
51
|
-
|
|
52
|
-
container = get_existing_container_with_matching_env(docker_client, TB_CONTAINER_NAME, environment)
|
|
53
|
-
|
|
54
|
-
if container and not pull_required:
|
|
55
|
-
# Container `start` is idempotent. It's safe to call it even if the container is already running.
|
|
56
|
-
container.start()
|
|
57
|
-
else:
|
|
58
|
-
if container:
|
|
59
|
-
container.remove(force=True)
|
|
60
|
-
|
|
61
|
-
container = docker_client.containers.run(
|
|
62
|
-
TB_IMAGE_NAME,
|
|
63
|
-
name=TB_CONTAINER_NAME,
|
|
64
|
-
detach=True,
|
|
65
|
-
ports={"7181/tcp": TB_LOCAL_PORT},
|
|
66
|
-
remove=False,
|
|
67
|
-
platform="linux/amd64",
|
|
68
|
-
environment=environment,
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
click.echo(FeedbackManager.info(message="* Waiting for Tinybird Local to be ready..."))
|
|
72
|
-
while True:
|
|
73
|
-
container.reload() # Refresh container attributes
|
|
74
|
-
health = container.attrs.get("State", {}).get("Health", {}).get("Status")
|
|
75
|
-
if health == "healthy":
|
|
76
|
-
break
|
|
77
|
-
if health == "unhealthy":
|
|
78
|
-
raise CLILocalException(
|
|
79
|
-
FeedbackManager.error(
|
|
80
|
-
message="Tinybird Local is unhealthy. Try running `tb local restart` in a few seconds."
|
|
81
|
-
)
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
time.sleep(5)
|
|
85
|
-
|
|
86
|
-
# Remove tinybird-local dangling images to avoid running out of disk space
|
|
87
|
-
images = docker_client.images.list(name=re.sub(r":.*$", "", TB_IMAGE_NAME), all=True, filters={"dangling": True})
|
|
88
|
-
for image in images:
|
|
89
|
-
image.remove(force=True)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
def get_existing_container_with_matching_env(
|
|
93
|
-
docker_client: DockerClient, container_name: str, required_env: dict[str, str]
|
|
94
|
-
) -> Optional[Container]:
|
|
95
|
-
"""
|
|
96
|
-
Checks if a container with the given name exists and has matching environment variables.
|
|
97
|
-
If it exists but environment doesn't match, it returns None.
|
|
98
|
-
|
|
99
|
-
Args:
|
|
100
|
-
docker_client: The Docker client instance
|
|
101
|
-
container_name: The name of the container to check
|
|
102
|
-
required_env: Dictionary of environment variables that must be present
|
|
103
|
-
|
|
104
|
-
Returns:
|
|
105
|
-
The container if it exists with matching environment, None otherwise
|
|
106
|
-
"""
|
|
107
|
-
container = None
|
|
108
|
-
containers = docker_client.containers.list(all=True, filters={"name": container_name})
|
|
109
|
-
if containers:
|
|
110
|
-
container = containers[0]
|
|
111
|
-
|
|
112
|
-
if container and required_env:
|
|
113
|
-
container_info = container.attrs
|
|
114
|
-
container_env = container_info.get("Config", {}).get("Env", [])
|
|
115
|
-
env_missing = False
|
|
116
|
-
for key, value in required_env.items():
|
|
117
|
-
env_var = f"{key}={value}"
|
|
118
|
-
if env_var not in container_env:
|
|
119
|
-
env_missing = True
|
|
120
|
-
break
|
|
121
|
-
|
|
122
|
-
if env_missing:
|
|
123
|
-
container.remove(force=True)
|
|
124
|
-
container = None
|
|
125
|
-
|
|
126
|
-
return container
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
def get_docker_client() -> DockerClient:
|
|
130
|
-
"""Check if Docker is installed and running."""
|
|
131
|
-
try:
|
|
132
|
-
docker_host = os.getenv("DOCKER_HOST")
|
|
133
|
-
if not docker_host:
|
|
134
|
-
# Try to get docker host from docker context
|
|
135
|
-
try:
|
|
136
|
-
try:
|
|
137
|
-
output = subprocess.check_output(["docker", "context", "inspect"], text=True)
|
|
138
|
-
except Exception as e:
|
|
139
|
-
add_telemetry_event(
|
|
140
|
-
"docker_error",
|
|
141
|
-
error=f"docker_context_inspect_error: {str(e)}",
|
|
142
|
-
)
|
|
143
|
-
raise e
|
|
144
|
-
try:
|
|
145
|
-
context = json.loads(output)
|
|
146
|
-
except Exception as e:
|
|
147
|
-
add_telemetry_event(
|
|
148
|
-
"docker_error",
|
|
149
|
-
error=f"docker_context_inspect_parse_output_error: {str(e)}",
|
|
150
|
-
data={
|
|
151
|
-
"docker_context_inspect_output": output,
|
|
152
|
-
},
|
|
153
|
-
)
|
|
154
|
-
raise e
|
|
155
|
-
if context and len(context) > 0:
|
|
156
|
-
try:
|
|
157
|
-
docker_host = context[0].get("Endpoints", {}).get("docker", {}).get("Host")
|
|
158
|
-
if docker_host:
|
|
159
|
-
os.environ["DOCKER_HOST"] = docker_host
|
|
160
|
-
except Exception as e:
|
|
161
|
-
add_telemetry_event(
|
|
162
|
-
"docker_error",
|
|
163
|
-
error=f"docker_context_parse_host_error: {str(e)}",
|
|
164
|
-
data={
|
|
165
|
-
"context": json.dumps(context),
|
|
166
|
-
},
|
|
167
|
-
)
|
|
168
|
-
raise e
|
|
169
|
-
except Exception:
|
|
170
|
-
pass
|
|
171
|
-
try:
|
|
172
|
-
client = docker.from_env() # type: ignore
|
|
173
|
-
except Exception as e:
|
|
174
|
-
add_telemetry_event(
|
|
175
|
-
"docker_error",
|
|
176
|
-
error=f"docker_get_client_from_env_error: {str(e)}",
|
|
177
|
-
)
|
|
178
|
-
raise e
|
|
179
|
-
try:
|
|
180
|
-
client.ping()
|
|
181
|
-
except Exception as e:
|
|
182
|
-
client_dict_non_sensitive = {k: v for k, v in client.api.__dict__.items() if "auth" not in k}
|
|
183
|
-
add_telemetry_event(
|
|
184
|
-
"docker_error",
|
|
185
|
-
error=f"docker_ping_error: {str(e)}",
|
|
186
|
-
data={
|
|
187
|
-
"client": repr(client_dict_non_sensitive),
|
|
188
|
-
},
|
|
189
|
-
)
|
|
190
|
-
raise e
|
|
191
|
-
return client
|
|
192
|
-
except Exception:
|
|
193
|
-
docker_location_message = ""
|
|
194
|
-
if docker_host:
|
|
195
|
-
docker_location_message = f"Trying to connect to Docker-compatible runtime at {docker_host}"
|
|
196
|
-
|
|
197
|
-
raise CLILocalException(
|
|
198
|
-
FeedbackManager.error(
|
|
199
|
-
message=(
|
|
200
|
-
f"No container runtime is running. Make sure a Docker-compatible runtime is installed and running. "
|
|
201
|
-
f"{docker_location_message}\n\n"
|
|
202
|
-
"If you're using a custom location, please provide it using the DOCKER_HOST environment variable."
|
|
203
|
-
)
|
|
204
|
-
)
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
def get_use_aws_creds() -> dict[str, str]:
|
|
209
|
-
credentials: dict[str, str] = {}
|
|
210
|
-
try:
|
|
211
|
-
# Get the boto3 session and credentials
|
|
212
|
-
session = boto3.Session()
|
|
213
|
-
creds = session.get_credentials()
|
|
214
|
-
|
|
215
|
-
if creds:
|
|
216
|
-
# Create environment variables for the container based on boto credentials
|
|
217
|
-
credentials["AWS_ACCESS_KEY_ID"] = creds.access_key
|
|
218
|
-
credentials["AWS_SECRET_ACCESS_KEY"] = creds.secret_key
|
|
219
|
-
|
|
220
|
-
# Add session token if it exists (for temporary credentials)
|
|
221
|
-
if creds.token:
|
|
222
|
-
credentials["AWS_SESSION_TOKEN"] = creds.token
|
|
223
|
-
|
|
224
|
-
# Add region if available
|
|
225
|
-
if session.region_name:
|
|
226
|
-
credentials["AWS_DEFAULT_REGION"] = session.region_name
|
|
227
|
-
|
|
228
|
-
click.echo(
|
|
229
|
-
FeedbackManager.success(
|
|
230
|
-
message=f"✓ AWS credentials found and will be passed to Tinybird Local (region: {session.region_name or 'not set'})"
|
|
231
|
-
)
|
|
232
|
-
)
|
|
233
|
-
else:
|
|
234
|
-
click.echo(
|
|
235
|
-
FeedbackManager.warning(
|
|
236
|
-
message="△ No AWS credentials found. S3 operations will not work in Tinybird Local."
|
|
237
|
-
)
|
|
238
|
-
)
|
|
239
|
-
except Exception as e:
|
|
240
|
-
click.echo(
|
|
241
|
-
FeedbackManager.warning(
|
|
242
|
-
message=f"△ Error retrieving AWS credentials: {str(e)}. S3 operations will not work in Tinybird Local."
|
|
243
|
-
)
|
|
244
|
-
)
|
|
245
|
-
|
|
246
|
-
return credentials
|
|
11
|
+
from tinybird.tb.modules.local_common import (
|
|
12
|
+
TB_CONTAINER_NAME,
|
|
13
|
+
TB_LOCAL_ADDRESS,
|
|
14
|
+
get_docker_client,
|
|
15
|
+
get_existing_container_with_matching_env,
|
|
16
|
+
start_tinybird_local,
|
|
17
|
+
)
|
|
247
18
|
|
|
248
19
|
|
|
249
20
|
def stop_tinybird_local(docker_client: DockerClient) -> None:
|
|
@@ -384,11 +384,15 @@ def get_docker_client() -> DockerClient:
|
|
|
384
384
|
raise e
|
|
385
385
|
return client
|
|
386
386
|
except Exception:
|
|
387
|
+
docker_location_message = ""
|
|
388
|
+
if docker_host:
|
|
389
|
+
docker_location_message = f"Trying to connect to Docker-compatible runtime at {docker_host}"
|
|
390
|
+
|
|
387
391
|
raise CLILocalException(
|
|
388
392
|
FeedbackManager.error(
|
|
389
393
|
message=(
|
|
390
394
|
f"No container runtime is running. Make sure a Docker-compatible runtime is installed and running. "
|
|
391
|
-
f"
|
|
395
|
+
f"{docker_location_message}\n\n"
|
|
392
396
|
"If you're using a custom location, please provide it using the DOCKER_HOST environment variable."
|
|
393
397
|
)
|
|
394
398
|
)
|
|
@@ -12,7 +12,7 @@ tinybird/syncasync.py,sha256=IPnOx6lMbf9SNddN1eBtssg8vCLHMt76SuZ6YNYm-Yk,27761
|
|
|
12
12
|
tinybird/tornado_template.py,sha256=jjNVDMnkYFWXflmT8KU_Ssbo5vR8KQq3EJMk5vYgXRw,41959
|
|
13
13
|
tinybird/ch_utils/constants.py,sha256=aYvg2C_WxYWsnqPdZB1ZFoIr8ZY-XjUXYyHKE9Ansj0,3890
|
|
14
14
|
tinybird/ch_utils/engine.py,sha256=X4tE9OrfaUy6kO9cqVEzyI9cDcmOF3IAssRRzsTsfEQ,40781
|
|
15
|
-
tinybird/tb/__cli__.py,sha256=
|
|
15
|
+
tinybird/tb/__cli__.py,sha256=_Rr6Wm1SeYKD1LpPgtsU7XL8grX5YitBreg6jpN2MGU,247
|
|
16
16
|
tinybird/tb/check_pypi.py,sha256=i3l2L8IajeB7sreikR7oPlYJki9MtS3c_M4crnmbByc,760
|
|
17
17
|
tinybird/tb/cli.py,sha256=u3eGOhX0MHkuT6tiwaZ0_3twqLmqKXDAOxF7yV_Nn9Q,1075
|
|
18
18
|
tinybird/tb/client.py,sha256=0zUAi9Lclo2JusQKlQnSnSP1XCiCK9I03XtLqmk8e04,56487
|
|
@@ -37,8 +37,8 @@ tinybird/tb/modules/infra.py,sha256=fve30Gj3mG9zbquGxS2e4ipcOYOxviWQCpNFfEzJN_Q,
|
|
|
37
37
|
tinybird/tb/modules/job.py,sha256=AsUCRNzy7HG5oJ4fyk9NpIm5NtNJgBZSy8MtJdXBe5A,3167
|
|
38
38
|
tinybird/tb/modules/llm.py,sha256=KfsCYmKeW1VQz0iDZhGKCRkQv_Y3kTHh6JuxvofOguE,1076
|
|
39
39
|
tinybird/tb/modules/llm_utils.py,sha256=nS9r4FAElJw8yXtmdYrx-rtI2zXR8qXfi1QqUDCfxvg,3469
|
|
40
|
-
tinybird/tb/modules/local.py,sha256=
|
|
41
|
-
tinybird/tb/modules/local_common.py,sha256=
|
|
40
|
+
tinybird/tb/modules/local.py,sha256=mLSgMMP3H1MdanVLsFZieeqOANSnctPLey3pJ_L1ZBI,5807
|
|
41
|
+
tinybird/tb/modules/local_common.py,sha256=8CSEVygFi0fIISatYxCStcHizugXCA9WNTLO_zDKmXw,17195
|
|
42
42
|
tinybird/tb/modules/login.py,sha256=qfY17J3FryTPl8A0ucQgxiyJ7jLy81qHdlHXgqohi0c,10170
|
|
43
43
|
tinybird/tb/modules/logout.py,sha256=sniI4JNxpTrVeRCp0oGJuQ3yRerG4hH5uz6oBmjv724,1009
|
|
44
44
|
tinybird/tb/modules/materialization.py,sha256=QJX5kCPhhm6IXBO1JsalVfbQdypCe_eOUDZ_WHJZWS8,5478
|
|
@@ -80,8 +80,8 @@ tinybird/tb_cli_modules/config.py,sha256=IsgdtFRnUrkY8-Zo32lmk6O7u3bHie1QCxLwgp4
|
|
|
80
80
|
tinybird/tb_cli_modules/exceptions.py,sha256=pmucP4kTF4irIt7dXiG-FcnI-o3mvDusPmch1L8RCWk,3367
|
|
81
81
|
tinybird/tb_cli_modules/regions.py,sha256=QjsL5H6Kg-qr0aYVLrvb1STeJ5Sx_sjvbOYO0LrEGMk,166
|
|
82
82
|
tinybird/tb_cli_modules/telemetry.py,sha256=Hh2Io8ZPROSunbOLuMvuIFU4TqwWPmQTqal4WS09K1A,10449
|
|
83
|
-
tinybird-0.0.1.
|
|
84
|
-
tinybird-0.0.1.
|
|
85
|
-
tinybird-0.0.1.
|
|
86
|
-
tinybird-0.0.1.
|
|
87
|
-
tinybird-0.0.1.
|
|
83
|
+
tinybird-0.0.1.dev213.dist-info/METADATA,sha256=XQKZmS6Dwt6M9bzsn5-JDiKBMA9DunE-kCMu2pAGkYI,1682
|
|
84
|
+
tinybird-0.0.1.dev213.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
85
|
+
tinybird-0.0.1.dev213.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
|
|
86
|
+
tinybird-0.0.1.dev213.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
|
|
87
|
+
tinybird-0.0.1.dev213.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|