Cole Medin commited on
Commit
349c5d5
·
unverified ·
2 Parent(s): 3cbe207 c116338

Merge pull request #71 from hillct/add-docker-support

Browse files

fix: further enhance Docker and docker-comose support with staged, --target and --profile support, plus Coolify Deployment Support

Files changed (6) hide show
  1. CONTRIBUTING.md +109 -6
  2. Dockerfile +57 -19
  3. docker-compose.yaml +48 -0
  4. docker-compose.yml +0 -24
  5. package.json +7 -2
  6. wrangler.toml +1 -0
CONTRIBUTING.md CHANGED
@@ -8,6 +8,7 @@ First off, thank you for considering contributing to Bolt.new! This fork aims to
8
  - [Pull Request Guidelines](#pull-request-guidelines)
9
  - [Coding Standards](#coding-standards)
10
  - [Development Setup](#development-setup)
 
11
  - [Project Structure](#project-structure)
12
 
13
  ## Code of Conduct
@@ -88,11 +89,113 @@ pnpm run dev
88
 
89
  **Note**: You will need Google Chrome Canary to run this locally if you use Chrome! It's an easy install and a good browser for web development anyway.
90
 
91
- ## Questions?
92
 
93
- For any questions about contributing, please:
94
- 1. Check existing documentation
95
- 2. Search through issues
96
- 3. Create a new issue with the question label
97
 
98
- Thank you for contributing to Bolt.new! 🚀
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  - [Pull Request Guidelines](#pull-request-guidelines)
9
  - [Coding Standards](#coding-standards)
10
  - [Development Setup](#development-setup)
11
+ - [Deploymnt with Docker](#docker-deployment-documentation)
12
  - [Project Structure](#project-structure)
13
 
14
  ## Code of Conduct
 
89
 
90
  **Note**: You will need Google Chrome Canary to run this locally if you use Chrome! It's an easy install and a good browser for web development anyway.
91
 
92
+ ## Testing
93
 
94
+ Run the test suite with:
 
 
 
95
 
96
+ ```bash
97
+ pnpm test
98
+ ```
99
+
100
+ ## Deployment
101
+
102
+ To deploy the application to Cloudflare Pages:
103
+
104
+ ```bash
105
+ pnpm run deploy
106
+ ```
107
+
108
+ Make sure you have the necessary permissions and Wrangler is correctly configured for your Cloudflare account.
109
+
110
+ # Docker Deployment Documentation
111
+
112
+ This guide outlines various methods for building and deploying the application using Docker.
113
+
114
+ ## Build Methods
115
+
116
+ ### 1. Using Helper Scripts
117
+
118
+ NPM scripts are provided for convenient building:
119
+
120
+ ```bash
121
+ # Development build
122
+ npm run dockerbuild
123
+
124
+ # Production build
125
+ npm run dockerbuild:prod
126
+ ```
127
+
128
+ ### 2. Direct Docker Build Commands
129
+
130
+ You can use Docker's target feature to specify the build environment:
131
+
132
+ ```bash
133
+ # Development build
134
+ docker build . --target bolt-ai-development
135
+
136
+ # Production build
137
+ docker build . --target bolt-ai-production
138
+ ```
139
+
140
+ ### 3. Docker Compose with Profiles
141
+
142
+ Use Docker Compose profiles to manage different environments:
143
+
144
+ ```bash
145
+ # Development environment
146
+ docker-compose --profile development up
147
+
148
+ # Production environment
149
+ docker-compose --profile production up
150
+ ```
151
+
152
+ ## Running the Application
153
+
154
+ After building using any of the methods above, run the container with:
155
+
156
+ ```bash
157
+ # Development
158
+ docker run -p 5173:5173 --env-file .env.local bolt-ai:development
159
+
160
+ # Production
161
+ docker run -p 5173:5173 --env-file .env.local bolt-ai:production
162
+ ```
163
+
164
+ ## Deployment with Coolify
165
+
166
+ [Coolify](https://github.com/coollabsio/coolify) provides a straightforward deployment process:
167
+
168
+ 1. Import your Git repository as a new project
169
+ 2. Select your target environment (development/production)
170
+ 3. Choose "Docker Compose" as the Build Pack
171
+ 4. Configure deployment domains
172
+ 5. Set the custom start command:
173
+ ```bash
174
+ docker compose --profile production up
175
+ ```
176
+ 6. Configure environment variables
177
+ - Add necessary AI API keys
178
+ - Adjust other environment variables as needed
179
+ 7. Deploy the application
180
+
181
+ ## VS Code Integration
182
+
183
+ The `docker-compose.yaml` configuration is compatible with VS Code dev containers:
184
+
185
+ 1. Open the command palette in VS Code
186
+ 2. Select the dev container configuration
187
+ 3. Choose the "development" profile from the context menu
188
+
189
+ ## Environment Files
190
+
191
+ Ensure you have the appropriate `.env.local` file configured before running the containers. This file should contain:
192
+ - API keys
193
+ - Environment-specific configurations
194
+ - Other required environment variables
195
+
196
+ ## Notes
197
+
198
+ - Port 5173 is exposed and mapped for both development and production environments
199
+ - Environment variables are loaded from `.env.local`
200
+ - Different profiles (development/production) can be used for different deployment scenarios
201
+ - The configuration supports both local development and production deployment
Dockerfile CHANGED
@@ -1,29 +1,67 @@
1
- # Use an official Node.js runtime as the base image
2
- FROM node:20.15.1
3
 
4
- # Set the working directory in the container
5
  WORKDIR /app
6
 
7
- # Install pnpm
8
- RUN npm install -g [email protected]
9
 
10
- # Copy package.json and pnpm-lock.yaml (if available)
11
- COPY package.json pnpm-lock.yaml* ./
12
 
13
- # Install dependencies
14
- RUN pnpm install
15
-
16
- # Copy the rest of the application code
17
  COPY . .
18
 
19
- # Build the application
20
- RUN pnpm run build
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- # Make sure bindings.sh is executable
23
- RUN chmod +x bindings.sh
 
 
 
 
 
 
24
 
25
- # Expose the port the app runs on (adjust if you specified a different port)
26
- EXPOSE 3000
 
 
 
 
 
27
 
28
- # Start the application
29
- CMD ["pnpm", "run", "start"]
 
1
+ ARG BASE=node:20.18.0
2
+ FROM ${BASE} AS base
3
 
 
4
  WORKDIR /app
5
 
6
+ # Install dependencies (this step is cached as long as the dependencies don't change)
7
+ COPY package.json pnpm-lock.yaml ./
8
 
9
+ RUN corepack enable pnpm && pnpm install
 
10
 
11
+ # Copy the rest of your app's source code
 
 
 
12
  COPY . .
13
 
14
+ # Expose the port the app runs on
15
+ EXPOSE 5173
16
+
17
+ # Production image
18
+ FROM base AS bolt-ai-production
19
+
20
+ # Define environment variables with default values or let them be overridden
21
+ ARG GROQ_API_KEY
22
+ ARG OPENAI_API_KEY
23
+ ARG ANTHROPIC_API_KEY
24
+ ARG OPEN_ROUTER_API_KEY
25
+ ARG GOOGLE_GENERATIVE_AI_API_KEY
26
+ ARG OLLAMA_API_BASE_URL
27
+ ARG VITE_LOG_LEVEL=debug
28
+
29
+ ENV WRANGLER_SEND_METRICS=false \
30
+ GROQ_API_KEY=${GROQ_API_KEY} \
31
+ OPENAI_API_KEY=${OPENAI_API_KEY} \
32
+ ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} \
33
+ OPEN_ROUTER_API_KEY=${OPEN_ROUTER_API_KEY} \
34
+ GOOGLE_GENERATIVE_AI_API_KEY=${GOOGLE_GENERATIVE_AI_API_KEY} \
35
+ OLLAMA_API_BASE_URL=${OLLAMA_API_BASE_URL} \
36
+ VITE_LOG_LEVEL=${VITE_LOG_LEVEL}
37
+
38
+ # Pre-configure wrangler to disable metrics
39
+ RUN mkdir -p /root/.config/.wrangler && \
40
+ echo '{"enabled":false}' > /root/.config/.wrangler/metrics.json
41
+
42
+ RUN npm run build
43
+
44
+ CMD [ "pnpm", "run", "dockerstart"]
45
+
46
+ # Development image
47
+ FROM base AS bolt-ai-development
48
 
49
+ # Define the same environment variables for development
50
+ ARG GROQ_API_KEY
51
+ ARG OPENAI_API_KEY
52
+ ARG ANTHROPIC_API_KEY
53
+ ARG OPEN_ROUTER_API_KEY
54
+ ARG GOOGLE_GENERATIVE_AI_API_KEY
55
+ ARG OLLAMA_API_BASE_URL
56
+ ARG VITE_LOG_LEVEL=debug
57
 
58
+ ENV GROQ_API_KEY=${GROQ_API_KEY} \
59
+ OPENAI_API_KEY=${OPENAI_API_KEY} \
60
+ ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY} \
61
+ OPEN_ROUTER_API_KEY=${OPEN_ROUTER_API_KEY} \
62
+ GOOGLE_GENERATIVE_AI_API_KEY=${GOOGLE_GENERATIVE_AI_API_KEY} \
63
+ OLLAMA_API_BASE_URL=${OLLAMA_API_BASE_URL} \
64
+ VITE_LOG_LEVEL=${VITE_LOG_LEVEL}
65
 
66
+ RUN mkdir -p ${WORKDIR}/run
67
+ CMD pnpm run dev --host
docker-compose.yaml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ services:
2
+ bolt-ai:
3
+ image: bolt-ai:production
4
+ build:
5
+ context: .
6
+ dockerfile: Dockerfile
7
+ target: bolt-ai-production
8
+ ports:
9
+ - "5173:5173"
10
+ env_file: ".env.local"
11
+ environment:
12
+ - NODE_ENV=production
13
+ - COMPOSE_PROFILES=production
14
+ # No strictly neded but serving as hints for Coolify
15
+ - PORT=5173
16
+ - GROQ_API_KEY=${GROQ_API_KEY}
17
+ - OPENAI_API_KEY=${OPENAI_API_KEY}
18
+ - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
19
+ - OPEN_ROUTER_API_KEY=${OPEN_ROUTER_API_KEY}
20
+ - GOOGLE_GENERATIVE_AI_API_KEY=${GOOGLE_GENERATIVE_AI_API_KEY}
21
+ - OLLAMA_API_BASE_URL=${OLLAMA_API_BASE_URL}
22
+ - VITE_LOG_LEVEL=${VITE_LOG_LEVEL:-debug}
23
+ command: pnpm run dockerstart
24
+ profiles:
25
+ - production # This service only runs in the production profile
26
+
27
+ bolt-ai-dev:
28
+ image: bolt-ai:development
29
+ build:
30
+ target: bolt-ai-development
31
+ environment:
32
+ - NODE_ENV=development
33
+ - COMPOSE_PROFILES=development
34
+ - PORT=5173
35
+ - GROQ_API_KEY=${GROQ_API_KEY}
36
+ - OPENAI_API_KEY=${OPENAI_API_KEY}
37
+ - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
38
+ - OPEN_ROUTER_API_KEY=${OPEN_ROUTER_API_KEY}
39
+ - GOOGLE_GENERATIVE_AI_API_KEY=${GOOGLE_GENERATIVE_AI_API_KEY}
40
+ - OLLAMA_API_BASE_URL=${OLLAMA_API_BASE_URL}
41
+ - VITE_LOG_LEVEL=${VITE_LOG_LEVEL:-debug}
42
+ volumes:
43
+ - .:/app
44
+ - /app/node_modules
45
+ ports:
46
+ - "5173:5173" # Same port, no conflict as only one runs at a time
47
+ command: pnpm run dev --host 0.0.0.0
48
+ profiles: ["development", "default"] # Make development the default profile
docker-compose.yml DELETED
@@ -1,24 +0,0 @@
1
- services:
2
- bolt-app:
3
- build:
4
- context: .
5
- dockerfile: Dockerfile
6
- ports:
7
- - "3000:3000"
8
- environment:
9
- - NODE_ENV=production
10
- # Add any other environment variables your app needs
11
- # - OPENAI_API_KEY=${OPENAI_API_KEY}
12
- # - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
13
- # - GROQ_API_KEY=${GROQ_API_KEY}
14
- # - OPEN_ROUTER_API_KEY=${OPEN_ROUTER_API_KEY}
15
- volumes:
16
- # This volume is for development purposes, allowing live code updates
17
- # Comment out or remove for production
18
- - .:/app
19
- # This volume is to prevent node_modules from being overwritten by the above volume
20
- - /app/node_modules
21
- command: pnpm run start
22
-
23
- volumes:
24
- node_modules:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
package.json CHANGED
@@ -13,7 +13,11 @@
13
  "test:watch": "vitest",
14
  "lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
15
  "lint:fix": "npm run lint -- --fix",
16
- "start": "bindings=$(./bindings.sh) && wrangler pages dev ./build/client $bindings --ip 0.0.0.0 --port 3000",
 
 
 
 
17
  "typecheck": "tsc",
18
  "typegen": "wrangler types",
19
  "preview": "pnpm run build && pnpm run start"
@@ -110,5 +114,6 @@
110
  },
111
  "resolutions": {
112
  "@typescript-eslint/utils": "^8.0.0-alpha.30"
113
- }
 
114
  }
 
13
  "test:watch": "vitest",
14
  "lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
15
  "lint:fix": "npm run lint -- --fix",
16
+ "start": "bindings=$(./bindings.sh) && wrangler pages dev ./build/client $bindings",
17
+ "dockerstart": "bindings=$(./bindings.sh) && wrangler pages dev ./build/client $bindings --ip 0.0.0.0 --port 5173 --no-show-interactive-dev-session",
18
+ "dockerrun": "docker run -it -d --name bolt-ai-live -p 5173:5173 --env-file .env.local bolt-ai",
19
+ "dockerbuild:prod": "docker build -t bolt-ai:production bolt-ai:latest --target bolt-ai-production .",
20
+ "dockerbuild": "docker build -t bolt-ai:development -t bolt-ai:latest --target bolt-ai-development .",
21
  "typecheck": "tsc",
22
  "typegen": "wrangler types",
23
  "preview": "pnpm run build && pnpm run start"
 
114
  },
115
  "resolutions": {
116
  "@typescript-eslint/utils": "^8.0.0-alpha.30"
117
+ },
118
+ "packageManager": "[email protected]+sha512.22721b3a11f81661ae1ec68ce1a7b879425a1ca5b991c975b074ac220b187ce56c708fe5db69f4c962c989452eee76c82877f4ee80f474cebd61ee13461b6228"
119
  }
wrangler.toml CHANGED
@@ -3,3 +3,4 @@ name = "bolt"
3
  compatibility_flags = ["nodejs_compat"]
4
  compatibility_date = "2024-07-01"
5
  pages_build_output_dir = "./build/client"
 
 
3
  compatibility_flags = ["nodejs_compat"]
4
  compatibility_date = "2024-07-01"
5
  pages_build_output_dir = "./build/client"
6
+ send_metrics = false