Skip to content

Commit f2d71b7

Browse files
dockerfile
1 parent f6007dd commit f2d71b7

File tree

9 files changed

+94
-123
lines changed

9 files changed

+94
-123
lines changed

packages/cli/src/commands/bundle/index.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import path from 'path';
8+
import fs from 'fs-extra';
89
import {
910
createCommandLogger,
1011
createTimer,
@@ -33,6 +34,7 @@ export interface BundleCommandOptions {
3334
verbose?: boolean;
3435
dryRun?: boolean;
3536
silent?: boolean;
37+
dockerfile?: boolean;
3638
}
3739

3840
export async function bundleCommand(
@@ -118,6 +120,15 @@ export async function bundleCommand(
118120
if (!options.json && !options.all && options.stats && stats) {
119121
displayStats(stats, logger);
120122
}
123+
124+
// Generate Dockerfile if requested
125+
if (options.dockerfile && !options.all) {
126+
const dockerfilePath = path.join(
127+
path.dirname(buildOptions.output),
128+
'Dockerfile',
129+
);
130+
await generateDockerfile(dockerfilePath, buildOptions.output, logger);
131+
}
121132
} catch (error) {
122133
const errorMessage = getErrorMessage(error);
123134
results.push({
@@ -264,3 +275,38 @@ export async function bundle(
264275
options.stats ?? false,
265276
);
266277
}
278+
279+
/**
280+
* Generate a Dockerfile for the bundled flow.
281+
*
282+
* Creates a minimal Dockerfile that:
283+
* - Uses walkeros/flow:latest as base image
284+
* - Copies the bundled flow to /app/flow.mjs
285+
* - Sets required environment variables
286+
* - Exposes port 8080
287+
*
288+
* @param dockerfilePath - Path to write the Dockerfile
289+
* @param bundleOutput - Path to the bundled flow file
290+
* @param logger - Logger instance for output
291+
*/
292+
async function generateDockerfile(
293+
dockerfilePath: string,
294+
bundleOutput: string,
295+
logger: ReturnType<typeof createCommandLogger>,
296+
): Promise<void> {
297+
const bundleFilename = path.basename(bundleOutput);
298+
299+
const dockerfile = `# Generated by walkeros CLI
300+
FROM walkeros/flow:latest
301+
302+
COPY ${bundleFilename} /app/flow.mjs
303+
304+
ENV MODE=collect
305+
ENV FLOW=/app/flow.mjs
306+
307+
EXPOSE 8080
308+
`;
309+
310+
await fs.writeFile(dockerfilePath, dockerfile);
311+
logger.log(`Dockerfile: ${dockerfilePath}`);
312+
}

packages/cli/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ program
6767
.option('-v, --verbose', 'verbose output')
6868
.option('--dry-run', 'preview command without executing')
6969
.option('--silent', 'suppress output')
70+
.option('--dockerfile', 'generate Dockerfile alongside bundle')
7071
.action(async (file, options) => {
7172
await bundleCommand({
7273
config: file || 'bundle.config.json',
@@ -78,6 +79,7 @@ program
7879
verbose: options.verbose,
7980
dryRun: options.dryRun,
8081
silent: options.silent,
82+
dockerfile: options.dockerfile,
8183
});
8284
});
8385

packages/server/sources/aws/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fn.addFunctionUrl({
9999

100100
```yaml
101101
# serverless.yml
102-
service: walkeros-collector
102+
service: walkeros-flow
103103

104104
provider:
105105
name: aws

packages/server/sources/aws/examples/serverless.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
service: walkeros-collector
1+
service: walkeros-flow
22

33
provider:
44
name: aws

packages/server/sources/express/README.md

Lines changed: 11 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -432,80 +432,21 @@ This design enables:
432432

433433
## Deployment
434434

435-
### Docker
435+
Use the [walkerOS Docker image](https://hub.docker.com/r/walkeros/flow) for
436+
deployment:
436437

437-
```dockerfile
438-
FROM node:18-alpine
439-
440-
WORKDIR /app
441-
442-
COPY package*.json ./
443-
RUN npm install
444-
445-
COPY . .
446-
447-
ENV PORT=8080
448-
EXPOSE 8080
438+
```bash
439+
# Bundle your flow with a Dockerfile
440+
walkeros bundle flow.json --dockerfile
449441

450-
CMD ["node", "server.js"]
442+
# Build and run
443+
cd dist
444+
docker build -t my-flow .
445+
docker run -p 8080:8080 my-flow
451446
```
452447

453-
**server.js:**
454-
455-
```javascript
456-
import { startFlow } from '@walkeros/collector';
457-
import { sourceExpress } from '@walkeros/server-source-express';
458-
459-
await startFlow({
460-
sources: {
461-
express: {
462-
code: sourceExpress,
463-
config: {
464-
settings: {
465-
port: process.env.PORT || 8080,
466-
},
467-
},
468-
},
469-
},
470-
// Your destinations...
471-
});
472-
```
473-
474-
### Kubernetes
475-
476-
```yaml
477-
apiVersion: apps/v1
478-
kind: Deployment
479-
metadata:
480-
name: walkeros-collector
481-
spec:
482-
replicas: 3
483-
selector:
484-
matchLabels:
485-
app: walkeros-collector
486-
template:
487-
metadata:
488-
labels:
489-
app: walkeros-collector
490-
spec:
491-
containers:
492-
- name: collector
493-
image: your-registry/walkeros-collector:latest
494-
ports:
495-
- containerPort: 8080
496-
livenessProbe:
497-
httpGet:
498-
path: /health
499-
port: 8080
500-
initialDelaySeconds: 10
501-
periodSeconds: 5
502-
readinessProbe:
503-
httpGet:
504-
path: /ready
505-
port: 8080
506-
initialDelaySeconds: 5
507-
periodSeconds: 3
508-
```
448+
See the [Docker documentation](https://www.walkeros.io/docs/apps/docker) for
449+
Cloud Run, Kubernetes, and other deployment options.
509450

510451
## Testing
511452

website/docs/apps/cli.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ The bundle is now ready to deploy!
300300
|--------|-------------|
301301
| `-f, --flow <name>` | Build specific flow (for multi-flow configs) |
302302
| `--all` | Build all flows |
303+
| `--dockerfile` | Generate Dockerfile alongside bundle |
303304
| `-s, --stats` | Show bundle statistics |
304305
| `--json` | Output statistics as JSON (for CI/CD) |
305306
| `--no-cache` | Skip package cache, download fresh |

website/docs/apps/docker.mdx

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ This creates `dist/flow.mjs`.
137137
-v $(pwd)/dist/flow.mjs:/app/flow.mjs \\
138138
-e MODE=collect \\
139139
-e FLOW=/app/flow.mjs \\
140-
--name walkeros-collector \\
140+
--name walkeros-flow \\
141141
walkeros/flow:latest`}
142142
language="bash"
143143
/>
@@ -154,61 +154,42 @@ This creates `dist/flow.mjs`.
154154
**4. View logs**
155155

156156
<CodeSnippet
157-
code={`docker logs -f walkeros-collector`}
157+
code={`docker logs -f walkeros-flow`}
158158
language="bash"
159159
/>
160160

161161
### Workflow 2: Custom Docker Image (Production)
162162

163163
Build a custom Docker image with your bundle baked in.
164164

165-
**1. Build with CLI**
165+
**1. Build with CLI and generate Dockerfile**
166166

167167
<CodeSnippet
168-
code={`walkeros bundle production.json -e production --output flow.mjs`}
168+
code={`walkeros bundle production.json --dockerfile`}
169169
language="bash"
170170
/>
171171

172-
**2. Create Dockerfile**
173-
174-
<CodeSnippet
175-
code={`FROM walkeros/flow:latest
176-
177-
# Copy pre-built bundle
178-
COPY flow.mjs /app/flow.mjs
179-
180-
# Configure runtime
181-
ENV MODE=collect
182-
ENV FLOW=/app/flow.mjs
183-
ENV PORT=8080
184-
185-
# Expose port
186-
EXPOSE 8080
187-
188-
# Health check
189-
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \\
190-
CMD node -e "require('http').get('http://localhost:8080/health', (r) => process.exit(r.statusCode === 200 ? 0 : 1))"`}
191-
language="dockerfile"
192-
/>
172+
This creates `dist/bundle.mjs` and `dist/Dockerfile`.
193173

194-
**3. Build image**
174+
**2. Build image**
195175

196176
<CodeSnippet
197-
code={`docker build -t my-analytics-collector:v1.0.0 .`}
177+
code={`cd dist
178+
docker build -t my-analytics:v1.0.0 .`}
198179
language="bash"
199180
/>
200181

201-
**4. Run it**
182+
**3. Run it**
202183

203184
<CodeSnippet
204-
code={`docker run -d -p 8080:8080 my-analytics-collector:v1.0.0`}
185+
code={`docker run -d -p 8080:8080 my-analytics:v1.0.0`}
205186
language="bash"
206187
/>
207188

208-
**5. Push to registry**
189+
**4. Push to registry**
209190

210191
<CodeSnippet
211-
code={`docker tag my-analytics-collector:v1.0.0 gcr.io/my-project/analytics:v1.0.0
192+
code={`docker tag my-analytics:v1.0.0 gcr.io/my-project/analytics:v1.0.0
212193
docker push gcr.io/my-project/analytics:v1.0.0`}
213194
language="bash"
214195
/>
@@ -598,16 +579,16 @@ Deploy to any Kubernetes cluster:
598579
code={`apiVersion: apps/v1
599580
kind: Deployment
600581
metadata:
601-
name: walkeros-collector
582+
name: walkeros-flow
602583
spec:
603584
replicas: 3
604585
selector:
605586
matchLabels:
606-
app: walkeros-collector
587+
app: walkeros-flow
607588
template:
608589
metadata:
609590
labels:
610-
app: walkeros-collector
591+
app: walkeros-flow
611592
spec:
612593
containers:
613594
- name: collector
@@ -638,10 +619,10 @@ spec:
638619
apiVersion: v1
639620
kind: Service
640621
metadata:
641-
name: walkeros-collector
622+
name: walkeros-flow
642623
spec:
643624
selector:
644-
app: walkeros-collector
625+
app: walkeros-flow
645626
ports:
646627
- protocol: TCP
647628
port: 80
@@ -654,7 +635,7 @@ Apply:
654635

655636
<CodeSnippet
656637
code={`kubectl apply -f deployment.yaml
657-
kubectl get services walkeros-collector`}
638+
kubectl get services walkeros-flow`}
658639
language="bash"
659640
/>
660641

@@ -691,13 +672,13 @@ Use this for:
691672

692673
<CodeSnippet
693674
code={`# Follow logs
694-
docker logs -f walkeros-collector
675+
docker logs -f walkeros-flow
695676
696677
# Last 100 lines
697-
docker logs --tail 100 walkeros-collector
678+
docker logs --tail 100 walkeros-flow
698679
699680
# With timestamps
700-
docker logs -t walkeros-collector`}
681+
docker logs -t walkeros-flow`}
701682
language="bash"
702683
/>
703684

@@ -788,10 +769,10 @@ The container is designed for horizontal scaling:
788769

789770
<CodeSnippet
790771
code={`# Docker Swarm
791-
docker service scale walkeros-collector=5
772+
docker service scale walkeros-flow=5
792773
793774
# Kubernetes
794-
kubectl scale deployment walkeros-collector --replicas=5
775+
kubectl scale deployment walkeros-flow --replicas=5
795776
796777
# Cloud Run (auto-scaling)
797778
gcloud run services update $SERVICE_NAME --max-instances=100`}
@@ -804,7 +785,7 @@ gcloud run services update $SERVICE_NAME --max-instances=100`}
804785

805786
<CodeSnippet
806787
code={`# Check logs
807-
docker logs walkeros-collector
788+
docker logs walkeros-flow
808789
809790
# Common issues:
810791
# - FLOW path doesn't exist
@@ -828,7 +809,7 @@ curl -X POST http://localhost:8080/collect \\
828809
-d '{"name":"test event","data":{}}'
829810
830811
# Check logs for errors
831-
docker logs walkeros-collector`}
812+
docker logs walkeros-flow`}
832813
language="bash"
833814
/>
834815

0 commit comments

Comments
 (0)