@crossdelta/infrastructure 0.1.38 → 0.1.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -71
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,45 +1,23 @@
|
|
|
1
|
-
# @crossdelta/infrastructure
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/@crossdelta/infrastructure)To install dependencies:
|
|
1
|
+
# @crossdelta/infrastructure
|
|
6
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@crossdelta/infrastructure)
|
|
7
4
|
[](https://opensource.org/licenses/MIT)
|
|
8
5
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
> 🏗️ Infrastructure-as-Code helpers for deploying microservices to DigitalOcean App Platform with Pulumi```bash
|
|
12
|
-
|
|
13
|
-
curl -fsSL https://get.pulumi.com | sh
|
|
14
|
-
|
|
15
|
-
## Features```
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
Infrastructure-as-Code helpers for deploying microservices to DigitalOcean App Platform with Pulumi.
|
|
18
7
|
|
|
19
|
-
|
|
8
|
+
## Features
|
|
20
9
|
|
|
21
|
-
-
|
|
10
|
+
- **Service Discovery** - Auto-discover service configs from `infra/services/*.ts`
|
|
11
|
+
- **Type-safe Config** - Full TypeScript support with `ServiceConfig` type
|
|
12
|
+
- **Smart Routing** - Automatic ingress rules for public services
|
|
13
|
+
- **Internal Services** - Support for internal-only ports (no public exposure)
|
|
14
|
+
- **Multi-Registry** - Docker Hub, GHCR, and DOCR image support
|
|
15
|
+
- **URL Generation** - Auto-generate service URLs and port env vars
|
|
22
16
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
- 🔒 **Internal Services** - Support for internal-only ports (no public exposure)
|
|
26
|
-
|
|
27
|
-
- 📦 **Multi-Registry** - Docker Hub, GHCR, and DOCR image supportTo run:
|
|
28
|
-
|
|
29
|
-
- 🔗 **URL Generation** - Auto-generate service URLs and port env vars
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
|
|
33
|
-
## Installationbun run index.ts
|
|
34
|
-
|
|
35
|
-
```
|
|
17
|
+
## Installation
|
|
36
18
|
|
|
37
19
|
```bash
|
|
38
|
-
|
|
39
|
-
npm install @crossdelta/infrastructureThis project was created using `bun init` in bun v1.3.3. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
|
|
40
|
-
|
|
41
|
-
# or
|
|
42
|
-
bun add @crossdelta/infrastructure
|
|
20
|
+
npm install @crossdelta/infrastructure
|
|
43
21
|
```
|
|
44
22
|
|
|
45
23
|
## Quick Start
|
|
@@ -84,15 +62,15 @@ const app = new App('my-app', {
|
|
|
84
62
|
...buildServiceUrlEnvs(serviceConfigs),
|
|
85
63
|
...buildServicePortEnvs(serviceConfigs),
|
|
86
64
|
],
|
|
87
|
-
services: buildServices({ serviceConfigs
|
|
65
|
+
services: buildServices({ serviceConfigs }),
|
|
88
66
|
ingress: { rules: buildIngressRules(serviceConfigs) },
|
|
89
67
|
},
|
|
90
68
|
})
|
|
91
69
|
```
|
|
92
70
|
|
|
93
|
-
## Service Configuration
|
|
71
|
+
## Service Configuration Examples
|
|
94
72
|
|
|
95
|
-
### Public Service
|
|
73
|
+
### Public Service
|
|
96
74
|
|
|
97
75
|
```typescript
|
|
98
76
|
const config: ServiceConfig = {
|
|
@@ -103,7 +81,7 @@ const config: ServiceConfig = {
|
|
|
103
81
|
}
|
|
104
82
|
```
|
|
105
83
|
|
|
106
|
-
### Internal
|
|
84
|
+
### Internal Service
|
|
107
85
|
|
|
108
86
|
```typescript
|
|
109
87
|
const config: ServiceConfig = {
|
|
@@ -113,61 +91,70 @@ const config: ServiceConfig = {
|
|
|
113
91
|
}
|
|
114
92
|
```
|
|
115
93
|
|
|
116
|
-
###
|
|
94
|
+
### TCP Service
|
|
117
95
|
|
|
118
96
|
```typescript
|
|
119
97
|
const config: ServiceConfig = {
|
|
120
98
|
name: 'nats',
|
|
121
|
-
internalPorts: [4222,
|
|
122
|
-
|
|
123
|
-
image: dockerHubImage('nats', '2.10-alpine'),
|
|
99
|
+
internalPorts: [{ port: 4222, protocol: 'TCP' }],
|
|
100
|
+
instanceSizeSlug: 'apps-s-1vcpu-1gb',
|
|
124
101
|
}
|
|
125
102
|
```
|
|
126
103
|
|
|
127
|
-
##
|
|
104
|
+
## CLI: generate-env
|
|
128
105
|
|
|
129
|
-
|
|
106
|
+
Generate `.env.local` for local development from your Pulumi config and service definitions.
|
|
130
107
|
|
|
131
|
-
|
|
132
|
-
import { getServicePort, getServiceUrl } from '@crossdelta/infrastructure/env'
|
|
108
|
+
### Setup
|
|
133
109
|
|
|
134
|
-
|
|
135
|
-
|
|
110
|
+
Add a script to your workspace `package.json`:
|
|
111
|
+
|
|
112
|
+
```json
|
|
113
|
+
{
|
|
114
|
+
"scripts": {
|
|
115
|
+
"generate-env": "npx tsx node_modules/@crossdelta/infrastructure/cli/commands/generate-env.ts"
|
|
116
|
+
}
|
|
117
|
+
}
|
|
136
118
|
```
|
|
137
119
|
|
|
138
|
-
|
|
120
|
+
Then run:
|
|
139
121
|
|
|
140
|
-
|
|
122
|
+
```bash
|
|
123
|
+
npm run generate-env
|
|
124
|
+
```
|
|
141
125
|
|
|
142
|
-
|
|
143
|
-
|----------|-------------|
|
|
144
|
-
| `discoverServices(dir)` | Auto-discover all `*.ts` service configs in a directory |
|
|
126
|
+
### What it does
|
|
145
127
|
|
|
146
|
-
|
|
128
|
+
1. Loads secrets from Pulumi config (dev stack)
|
|
129
|
+
2. Discovers services from `infra/services/*.ts`
|
|
130
|
+
3. Generates `SERVICE_URL` and `SERVICE_PORT` env vars for localhost
|
|
131
|
+
4. Writes `.env.local` to your workspace root
|
|
132
|
+
5. Generates a `ServiceName` TypeScript type
|
|
147
133
|
|
|
148
|
-
|
|
149
|
-
|----------|-------------|
|
|
150
|
-
| `buildServices(opts)` | Build DO App spec services array |
|
|
151
|
-
| `buildIngressRules(configs)` | Build ingress rules for public services |
|
|
152
|
-
| `buildServiceUrlEnvs(configs)` | Generate `<SERVICE>_URL` env vars |
|
|
153
|
-
| `buildServicePortEnvs(configs)` | Generate `<SERVICE>_PORT` env vars |
|
|
154
|
-
| `buildInternalUrls(configs)` | Get internal URLs for all services |
|
|
155
|
-
| `buildExternalUrls(configs, baseUrl)` | Get external URLs for public services |
|
|
134
|
+
### Example output
|
|
156
135
|
|
|
157
|
-
|
|
136
|
+
`.env.local`:
|
|
137
|
+
```bash
|
|
138
|
+
# Service URLs (localhost for local development)
|
|
139
|
+
API_GATEWAY_URL=http://localhost:4000
|
|
140
|
+
STOREFRONT_URL=http://localhost:3000
|
|
158
141
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
142
|
+
# Service Ports
|
|
143
|
+
API_GATEWAY_PORT=4000
|
|
144
|
+
STOREFRONT_PORT=3000
|
|
145
|
+
```
|
|
163
146
|
|
|
164
|
-
|
|
147
|
+
## API
|
|
165
148
|
|
|
166
149
|
| Function | Description |
|
|
167
150
|
|----------|-------------|
|
|
168
|
-
| `
|
|
169
|
-
| `
|
|
151
|
+
| `discoverServices(dir)` | Auto-discover service configs from directory |
|
|
152
|
+
| `buildServices(options)` | Build App Platform service specs |
|
|
153
|
+
| `buildIngressRules(configs)` | Generate ingress rules |
|
|
154
|
+
| `buildServiceUrlEnvs(configs)` | Create SERVICE_NAME_URL env vars |
|
|
155
|
+
| `buildServicePortEnvs(configs)` | Create SERVICE_NAME_PORT env vars |
|
|
156
|
+
| `buildLocalUrls(configs)` | Generate localhost URLs for local dev |
|
|
170
157
|
|
|
171
158
|
## License
|
|
172
159
|
|
|
173
|
-
MIT
|
|
160
|
+
MIT
|