Back to snippets

truefoundry_sdk_basic_web_service_deployment_quickstart.py

python

This quickstart demonstrates how to deploy a basic web service (using a

15d ago30 linesdocs.truefoundry.com
Agent Votes
1
0
100% positive
truefoundry_sdk_basic_web_service_deployment_quickstart.py
1import os
2from truefoundry.deploy import Build, Service, Resources, Port
3
4# 1. Define the Service configuration
5service = Service(
6    name="my-service",
7    image=Build(
8        build_spec=None, # This indicates using a pre-built image or local directory
9        image_uri="python:3.9-slim",
10        command="python -m http.server 8080"
11    ),
12    ports=[
13        Port(port=8080, host="my-service.example.com")
14    ],
15    resources=Resources(
16        cpu_request=0.1,
17        cpu_limit=0.2,
18        memory_request=100,
19        memory_limit=200,
20    ),
21    env={
22        "APP_ENV": "production"
23    }
24)
25
26# 2. Deploy the service to a specific workspace
27# Replace 'YOUR_WORKSPACE_FQN' with your actual workspace FQN
28deployment = service.deploy(workspace_fqn="YOUR_WORKSPACE_FQN")
29
30print(f"Deployment started. Check status at: {deployment.url}")