Skip to content

Commit 15fc7e5

Browse files
Updated template build documentation with new background build methods (#57)
Co-authored-by: mintlify[bot] <109931778+mintlify[bot]@users.noreply.github.com> Co-authored-by: Jakub Dobry <[email protected]>
1 parent bf04b5c commit 15fc7e5

File tree

1 file changed

+140
-3
lines changed

1 file changed

+140
-3
lines changed

docs/template/build.mdx

Lines changed: 140 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ title: "Build"
33
description: "How to build the template"
44
---
55

6-
Configure the build process:
6+
## Build and wait for completion
7+
8+
The `build` method builds the template and waits for the build to complete. It returns build information including the template ID and build ID.
79

810
<CodeGroup>
911

1012
```typescript JavaScript & TypeScript wrap
11-
Template.build(template, {
13+
const buildInfo = await Template.build(template, {
1214
alias: 'my-template', // Template alias (required)
1315
cpuCount: 2, // CPU cores
1416
memoryMB: 2048, // Memory in MB
@@ -17,10 +19,12 @@ Template.build(template, {
1719
apiKey: 'your-api-key', // Override API key
1820
domain: 'your-domain', // Override domain
1921
})
22+
23+
// buildInfo contains: { alias, templateId, buildId }
2024
```
2125

2226
```python Python wrap
23-
Template.build(
27+
build_info = Template.build(
2428
template,
2529
alias="my-template", # Template alias (required)
2630
cpu_count=2, # CPU cores
@@ -30,6 +34,139 @@ Template.build(
3034
api_key="your-api-key", # Override API key
3135
domain="your-domain", # Override domain
3236
)
37+
38+
# build_info contains: BuildInfo(alias, template_id, build_id)
39+
```
40+
41+
</CodeGroup>
42+
43+
## Build in background
44+
45+
The `buildInBackground` method starts the build process and returns immediately without waiting for completion. This is useful when you want to trigger a build and check its status later.
46+
47+
<CodeGroup>
48+
49+
```typescript JavaScript & TypeScript wrap
50+
const buildInfo = await Template.buildInBackground(template, {
51+
alias: 'my-template',
52+
cpuCount: 2,
53+
memoryMB: 2048,
54+
})
55+
56+
// Returns immediately with: { alias, templateId, buildId }
57+
```
58+
59+
```python Python wrap
60+
build_info = Template.build_in_background(
61+
template,
62+
alias="my-template",
63+
cpu_count=2,
64+
memory_mb=2048,
65+
)
66+
67+
# Returns immediately with: BuildInfo(alias, template_id, build_id)
68+
```
69+
70+
</CodeGroup>
71+
72+
## Check build status
73+
74+
Use `getBuildStatus` to check the status of a build started with `buildInBackground`.
75+
76+
<CodeGroup>
77+
78+
```typescript JavaScript & TypeScript wrap
79+
const status = await Template.getBuildStatus(buildInfo, {
80+
logsOffset: 0, // Optional: offset for fetching logs
81+
})
82+
83+
// status contains: { status: 'building' | 'ready' | 'error', logEntries: [...] }
84+
```
85+
86+
```python Python wrap
87+
status = Template.get_build_status(
88+
build_info,
89+
logs_offset=0, # Optional: offset for fetching logs
90+
)
91+
92+
# status contains build status and logs
93+
```
94+
95+
</CodeGroup>
96+
97+
## Example: Background build with status polling
98+
99+
<CodeGroup>
100+
101+
```typescript JavaScript & TypeScript wrap
102+
// Start build in background
103+
const buildInfo = await Template.buildInBackground(template, {
104+
alias: 'my-template',
105+
cpuCount: 2,
106+
memoryMB: 2048,
107+
})
108+
109+
// Poll for build status
110+
let logsOffset = 0
111+
let status = 'building'
112+
113+
while (status === 'building') {
114+
const buildStatus = await Template.getBuildStatus(buildInfo, {
115+
logsOffset,
116+
})
117+
118+
logsOffset += buildStatus.logEntries.length
119+
status = buildStatus.status
120+
121+
buildStatus.logEntries.forEach(
122+
(logEntry) => console.log(logEntry.toString())
123+
)
124+
125+
// Wait for a short period before checking the status again
126+
await new Promise(resolve => setTimeout(resolve, 2000))
127+
}
128+
129+
if (status === 'ready') {
130+
console.log('Build completed successfully')
131+
} else {
132+
console.error('Build failed')
133+
}
134+
```
135+
136+
```python Python wrap
137+
# Start build in background
138+
build_info = Template.build_in_background(
139+
template,
140+
alias="my-template",
141+
cpu_count=2,
142+
memory_mb=2048,
143+
)
144+
145+
# Poll for build status
146+
import time
147+
148+
logs_offset = 0
149+
status = "building"
150+
151+
while status == "building":
152+
build_status = Template.get_build_status(
153+
build_info,
154+
logs_offset=logs_offset,
155+
)
156+
157+
logs_offset += len(build_status.log_entries)
158+
status = build_status.status.value
159+
160+
for log_entry in build_status.log_entries:
161+
print(log_entry)
162+
163+
# Wait for a short period before checking the status again
164+
time.sleep(2)
165+
166+
if status == "ready":
167+
print("Build completed successfully")
168+
else:
169+
print("Build failed")
33170
```
34171

35172
</CodeGroup>

0 commit comments

Comments
 (0)