@crossdelta/infrastructure 0.1.38 → 0.1.41
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 +57 -69
- 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,71 @@ const config: ServiceConfig = {
|
|
|
113
91
|
}
|
|
114
92
|
```
|
|
115
93
|
|
|
116
|
-
### Custom
|
|
94
|
+
### Internal Service with Custom URL (e.g., NATS)
|
|
117
95
|
|
|
118
96
|
```typescript
|
|
119
97
|
const config: ServiceConfig = {
|
|
120
98
|
name: 'nats',
|
|
121
99
|
internalPorts: [4222, 8222],
|
|
122
100
|
internalUrl: 'nats://nats:4222',
|
|
123
|
-
|
|
101
|
+
instanceSizeSlug: 'apps-s-1vcpu-1gb',
|
|
124
102
|
}
|
|
125
103
|
```
|
|
126
104
|
|
|
127
|
-
##
|
|
105
|
+
## CLI: generate-env
|
|
128
106
|
|
|
129
|
-
|
|
107
|
+
Generate `.env.local` for local development from your Pulumi config and service definitions.
|
|
130
108
|
|
|
131
|
-
|
|
132
|
-
import { getServicePort, getServiceUrl } from '@crossdelta/infrastructure/env'
|
|
109
|
+
### Setup
|
|
133
110
|
|
|
134
|
-
|
|
135
|
-
|
|
111
|
+
Add a script to your workspace `package.json`:
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"scripts": {
|
|
116
|
+
"generate-env": "npx tsx node_modules/@crossdelta/infrastructure/cli/commands/generate-env.ts"
|
|
117
|
+
}
|
|
118
|
+
}
|
|
136
119
|
```
|
|
137
120
|
|
|
138
|
-
|
|
121
|
+
Then run:
|
|
139
122
|
|
|
140
|
-
|
|
123
|
+
```bash
|
|
124
|
+
npm run generate-env
|
|
125
|
+
```
|
|
141
126
|
|
|
142
|
-
|
|
143
|
-
|----------|-------------|
|
|
144
|
-
| `discoverServices(dir)` | Auto-discover all `*.ts` service configs in a directory |
|
|
127
|
+
### What it does
|
|
145
128
|
|
|
146
|
-
|
|
129
|
+
1. Loads secrets from Pulumi config (dev stack)
|
|
130
|
+
2. Discovers services from `infra/services/*.ts`
|
|
131
|
+
3. Generates `SERVICE_URL` and `SERVICE_PORT` env vars for localhost
|
|
132
|
+
4. Writes `.env.local` to your workspace root
|
|
133
|
+
5. Generates a `ServiceName` TypeScript type
|
|
147
134
|
|
|
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 |
|
|
135
|
+
### Example output
|
|
156
136
|
|
|
157
|
-
|
|
137
|
+
`.env.local`:
|
|
138
|
+
```bash
|
|
139
|
+
# Service URLs (localhost for local development)
|
|
140
|
+
API_GATEWAY_URL=http://localhost:4000
|
|
141
|
+
STOREFRONT_URL=http://localhost:3000
|
|
158
142
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
143
|
+
# Service Ports
|
|
144
|
+
API_GATEWAY_PORT=4000
|
|
145
|
+
STOREFRONT_PORT=3000
|
|
146
|
+
```
|
|
163
147
|
|
|
164
|
-
|
|
148
|
+
## API
|
|
165
149
|
|
|
166
150
|
| Function | Description |
|
|
167
151
|
|----------|-------------|
|
|
168
|
-
| `
|
|
169
|
-
| `
|
|
152
|
+
| `discoverServices(dir)` | Auto-discover service configs from directory |
|
|
153
|
+
| `buildServices(options)` | Build App Platform service specs |
|
|
154
|
+
| `buildIngressRules(configs)` | Generate ingress rules |
|
|
155
|
+
| `buildServiceUrlEnvs(configs)` | Create SERVICE_NAME_URL env vars |
|
|
156
|
+
| `buildServicePortEnvs(configs)` | Create SERVICE_NAME_PORT env vars |
|
|
157
|
+
| `buildLocalUrls(configs)` | Generate localhost URLs for local dev |
|
|
170
158
|
|
|
171
159
|
## License
|
|
172
160
|
|
|
173
|
-
MIT
|
|
161
|
+
MIT
|