-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuserland-helpers.stack.js
More file actions
91 lines (73 loc) · 2.73 KB
/
userland-helpers.stack.js
File metadata and controls
91 lines (73 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Example: Create your own custom helper functions in JavaScript
// This shows how to implement domain helpers (or any other patterns)
// without needing them built into Comet
const opts = {
org: 'myorg',
common_name: 'myapp',
base_domain: 'example.io' // Your domain structure, your choice
}
stack('demo', { opts })
metadata({
description: 'Userland patterns: custom helpers and domain functions',
tags: ['example', 'patterns', 'userland']
})
backend('gcs', {
bucket: 'my-state',
prefix: `${opts.org}/{{ .stack }}/{{ .component }}`
})
// ============================================================================
// USERLAND HELPERS - Define your own patterns!
// ============================================================================
// Example 1: Your own domain helpers (if you want them)
function subdomain(name) {
// Your team's specific pattern
return `${name}.{{ .stack }}.${opts.base_domain}`
}
function fqdn(name) {
return `${name}.${opts.base_domain}`
}
// Example 2: Or use template strings directly (even simpler)
const domainFor = (name) => `${name}.{{ .stack }}.${opts.base_domain}`
// Example 3: Different domain pattern - preview branches
function previewDomain(name, branch) {
return `${name}-${branch}.preview.${opts.base_domain}`
}
// Example 4: Component factory pattern
function k8sApp(name, config) {
return component(name, 'modules/k8s-app', {
namespace: 'default',
domain: domainFor(name),
...config
})
}
// ============================================================================
// USE YOUR HELPERS
// ============================================================================
// Use your custom helpers
const admin = k8sApp('admin', {
replicas: 2,
image: 'admin:latest'
})
const api = component('api', 'modules/api', {
domain_name: fqdn('api'), // api.example.io
database_url: 'postgres://...'
})
const webapp = component('webapp', 'modules/frontend', {
domain_name: subdomain('app'), // app.demo.example.io
api_url: api.endpoint
})
const preview = component('preview', 'modules/frontend', {
domain_name: previewDomain('webapp', 'feature-123'), // webapp-feature-123.preview.example.io
api_url: api.endpoint
})
// ============================================================================
// OR JUST USE TEMPLATE STRINGS DIRECTLY
// ============================================================================
const monitoring = component('grafana', 'modules/grafana', {
// No helper needed - just do it directly
domain_name: `grafana.{{ .stack }}.${opts.base_domain}`,
replicas: 1
})
print('✅ Custom userland helpers work perfectly!')
print(' No need to build every pattern into Comet.')
print(' JavaScript is flexible enough to create your own abstractions.')