from servicefoundry import (
Service, Build, GitSource, PythonBuild, Resources,
Port, HealthProbe, BasicAuthCreds, HttpProbe
)
service = Service(
name="my-service",
image=Build(
docker_registry="admin-truefoundry:production-euwe1-ecr", # optional, FQN registry to push the built image to
build_source=GitSource(
repo_url="https://github.com/myorg/myrepo",
branch_name="main", # Optional, by default the default branch configured on the repo
ref="547ea1423267902a6ff98517d4ae205d8f7c47f8", # Optional, by default latest commit on the branch
),
build_spec=PythonBuild(
python_version="3.9",
build_context_path="./",
requirements_path="requirements.txt",
pip_packages=["requests", "numpy==1.20.0"],
apt_packages=["ffmpeg", "curl", "wget"],
command="uvicorn app:app --port 8000 --host 127.0.0.1", # or as a list ["python", "main.py"]
),
),
resources=Resources(
cpu_request=1,
memory_request=1000, # in Megabytes
ephemeral_storage_request=1000, # in Megabytes
cpu_limit=4,
memory_limit=4000,
ephemeral_storage_limit=10000,
instance_family=["c6i", "t3", "m4"],
),
replicas=2,
env={
"NUM_WORKERS": "5",
"VERY_SECRET_API_KEY": "tfy-secret://my-user:my-secret-group:VERY_SECRET_API_KEY"
},
ports=[
Port(
port=8080,
protocol="TCP", # or "UDP"
expose=True,
auth=BasicAuthCreds(
username="admin",
password="supersecretpassword", # Just an example, don't hardcode this!
)
)
],
liveness_probe=HealthProbe(
config=HttpProbe(
path="v2/health/live",
port=8080,
host="0.0.0.0",
scheme="HTTP"
),
initial_delay_seconds=2,
period_seconds=5,
timeout_seconds=5,
success_threshold=1,
failure_threshold=3,
),
readiness_probe=HealthProbe(
config=HttpProbe(
path="v2/health/ready",
port=8080,
host="0.0.0.0",
scheme="HTTP"
),
initial_delay_seconds=2,
period_seconds=5,
timeout_seconds=5,
success_threshold=1,
failure_threshold=3,
),
service_account="my-k8s-service-account",
file_mount = FileMount(
mount_dir="./tmp",
data={"foo":"bar"}
),
)
deployment = service.deploy(workspace_fqn='...')