Skip to content

Commit dcde8aa

Browse files
committedJan 24, 2025
feat(web): simplify image building by copying static files from host machine
1 parent f3a139c commit dcde8aa

31 files changed

+100
-67
lines changed
 

‎.dockerignore

-7
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,10 @@
55
.github
66
.vscode
77

8-
# Rush temp files
9-
common/deploy/
10-
common/temp/
11-
common/autoinstallers/*/.npmrc
12-
**/.rush/temp/
13-
*.lock
148
*.log
159
*.chunks.jsonl
1610

1711
# Build dependencies
18-
dist
1912
node_modules
2013
coverage
2114

‎.github/workflows/build-image.yml

+20
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@ jobs:
2020
steps:
2121
- name: Checkout repository
2222
uses: actions/checkout@v4
23+
24+
- uses: pnpm/action-setup@v4
25+
with:
26+
run_install: false
27+
28+
- name: Use Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: 20
32+
cache: 'pnpm'
33+
34+
- name: Install dependencies
35+
run: pnpm install
36+
37+
- name: Build
38+
run: pnpm build:web
39+
env:
40+
NODE_OPTIONS: '--max_old_space_size=8192'
41+
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
42+
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
2343

2444
- name: Set up QEMU
2545
uses: docker/setup-qemu-action@v3
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Upload Web Artifacts
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
environment:
7+
description: 'Environment to build for'
8+
required: true
9+
type: choice
10+
options:
11+
- staging
12+
- production
13+
default: 'staging'
14+
15+
jobs:
16+
build:
17+
name: Build and Upload
18+
uses: ./.github/workflows/build.yml
19+
with:
20+
environment: ${{ inputs.environment }}
21+
secrets: inherit
22+
23+
upload:
24+
name: Upload Artifacts
25+
needs: build
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
31+
- name: Download artifacts
32+
uses: actions/download-artifact@v4
33+
with:
34+
name: web-dist
35+
path: apps/web/dist
36+
37+
- name: Upload artifacts
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: web-dist
41+
path: apps/web/dist
42+
retention-days: 5

‎apps/web/.dockerignore

-24
This file was deleted.

‎apps/web/Dockerfile

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
# Builder stage
2-
FROM node:20-alpine@sha256:b5b9467fe7b33aad47f1ec3f6e0646a658f85f05c18d4243024212a91f3b7554 AS builder
3-
4-
WORKDIR /app
5-
6-
RUN corepack enable
7-
8-
ENV NODE_OPTIONS=--max_old_space_size=8192
9-
ENV VITE_API_URL=http://localhost:5800
10-
ENV VITE_COLLAB_URL=http://localhost:5801
11-
12-
COPY . .
13-
RUN pnpm install
14-
RUN pnpm build:web
15-
161
# Nginx stage
172
FROM nginx:alpine
183

4+
# Install envsubst and bash for environment variable substitution
5+
RUN apk add --no-cache bash
6+
197
# Copy nginx configuration
208
COPY deploy/docker/nginx.conf /etc/nginx/conf.d/default.conf
219

22-
# Copy built files from builder stage
23-
COPY --from=builder /app/dist /usr/share/nginx/html
10+
# Copy static files
11+
WORKDIR /usr/share/nginx/html
12+
COPY ./dist .
13+
14+
# Create config.js template
15+
RUN echo "window.ENV = { \
16+
API_URL: '${API_URL:-http://localhost:5800}', \
17+
COLLAB_URL: '${COLLAB_URL:-http://localhost:5801}' \
18+
};" > config.template.js
19+
20+
# Create entrypoint script
21+
RUN echo '#!/bin/bash\n\
22+
envsubst < config.template.js > config.js\n\
23+
exec nginx -g "daemon off;"' > /docker-entrypoint.sh
24+
25+
RUN chmod +x /docker-entrypoint.sh
2426

2527
# Expose port 80
2628
EXPOSE 80
2729

28-
# Start Nginx
29-
CMD ["nginx", "-g", "daemon off;"]
30+
# Start Nginx with our entrypoint script
31+
ENTRYPOINT ["/docker-entrypoint.sh"]

‎apps/web/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
as="font"
4444
type="font/woff2"
4545
crossorigin="anonymous" />
46+
<!-- Load configuration before the app -->
47+
<script src="/config.js"></script>
4648
</head>
4749
<script
4850
async

‎apps/web/public/config.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
window.ENV = {
2+
API_URL: '',
3+
COLLAB_URL: ''
4+
};
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

‎apps/web/src/assets/menu-icons/abstract.svg

-1
This file was deleted.

‎apps/web/src/assets/menu-icons/close.svg

-1
This file was deleted.

‎apps/web/src/assets/menu-icons/code.svg

-1
This file was deleted.

‎apps/web/src/assets/menu-icons/copy.svg

-1
This file was deleted.

‎apps/web/src/assets/menu-icons/explain.svg

-1
This file was deleted.

‎apps/web/src/assets/menu-icons/extension.svg

-1
This file was deleted.

‎apps/web/src/assets/menu-icons/grammary.svg

-1
This file was deleted.

‎apps/web/src/assets/menu-icons/qa.svg

-1
This file was deleted.

‎apps/web/src/assets/menu-icons/refresh.svg

-1
This file was deleted.

‎apps/web/src/assets/menu-icons/setting.svg

-1
This file was deleted.

‎apps/web/src/assets/menu-icons/tag-hoverd.svg

-1
This file was deleted.

‎apps/web/src/assets/menu-icons/tag-selected.svg

-1
This file was deleted.

‎apps/web/src/assets/menu-icons/tag.svg

-1
This file was deleted.

‎apps/web/src/assets/menu-icons/translate.svg

-1
This file was deleted.

‎apps/web/src/assets/menu-icons/write.svg

-1
This file was deleted.

‎packages/ai-workspace-common/src/utils/env.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,17 @@ export const getEnv = () => {
1313
return env;
1414
};
1515

16-
export const serverOrigin = import.meta.env.VITE_API_URL;
17-
export const wsServerOrigin = import.meta.env.VITE_COLLAB_URL;
16+
declare global {
17+
interface Window {
18+
ENV?: {
19+
API_URL: string;
20+
COLLAB_URL: string;
21+
};
22+
}
23+
}
24+
25+
export const serverOrigin = import.meta.env.VITE_API_URL || window.ENV?.API_URL;
26+
export const wsServerOrigin = import.meta.env.VITE_COLLAB_URL || window.ENV?.COLLAB_URL;
1827

1928
let runtime: IRuntime;
2029

0 commit comments

Comments
 (0)
Please sign in to comment.