Skip to content

Commit 528b635

Browse files
committed
feat: update Dockerfile to use Python 3.12 and improve bashrc for virtual environment activation; enhance execute_command example with error handling and log streaming
1 parent 135d133 commit 528b635

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

.devcontainer/Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
ARG VARIANT="3.9"
2-
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}
1+
FROM mcr.microsoft.com/devcontainers/python:3.12
32

43
USER vscode
54

65
RUN curl -sSf https://rye.astral.sh/get | RYE_VERSION="0.35.0" RYE_INSTALL_OPTION="--yes" bash
76
ENV PATH=/home/vscode/.rye/shims:$PATH
87

9-
RUN echo "[[ -d .venv ]] && source .venv/bin/activate" >> /home/vscode/.bashrc
8+
RUN echo "[[ -d .venv ]] && source .venv/bin/activate || export PATH=\$PATH" >> /home/vscode/.bashrc

examples/execute_command.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def main() -> None:
2828
reference = "hello-world"
2929
task = client.environments.automations.tasks.create(
3030
spec={
31-
"command": "echo 'Hello, World!'"
31+
"command": "echo 'Hello, World!' && false",
3232
},
3333
environment_id=environment_id,
3434
metadata={
@@ -54,7 +54,6 @@ def main() -> None:
5454

5555
log_url = None
5656
for event in event_stream:
57-
print(f"Received event: {event}")
5857
if event.resource_type == "RESOURCE_TYPE_ENVIRONMENT" and event.resource_id == environment_id:
5958
check_environment_status(client, environment_id)
6059
elif event.resource_type == "RESOURCE_TYPE_TASK_EXECUTION" and event.resource_id == execution.id:
@@ -63,15 +62,23 @@ def main() -> None:
6362
if execution.status.log_url:
6463
log_url = execution.status.log_url
6564
break
65+
66+
event_stream.http_response.close()
6667

6768
if not log_url:
6869
raise RuntimeError("Task logs are not available.")
6970

7071
print(f"Task logs are available at: {log_url}")
72+
print("")
73+
print("Streaming logs:")
7174

72-
# Stream the log URL and print the logs
7375
asyncio.run(stream_logs(log_url, logs_access_token))
7476

77+
execution = client.environments.automations.tasks.executions.retrieve(id=execution.id).task_execution
78+
print(f"Task execution status: {execution.status.phase}")
79+
if execution.status.phase == "TASK_EXECUTION_PHASE_FAILED":
80+
print(f"Task execution failed: {execution.status.failure_message}")
81+
7582
finally:
7683
client.environments.delete(environment_id=environment_id)
7784
print(f"Deleted environment: {environment_id}")

0 commit comments

Comments
 (0)