From 3c85808b698a2e3bcaf80f8caf5e1df198a0b738 Mon Sep 17 00:00:00 2001 From: Pattisier Date: Sun, 17 Aug 2025 05:16:36 -0400 Subject: [PATCH] docker stuff --- apps/server/Dockerfile | 40 +++++++++++++++++++++++++++++++++++++++ apps/web/Dockerfile | 38 +++++++++++++++++++++++++++++++++++++ apps/web/nginx.conf | 42 +++++++++++++++++++++++++++++++++++++++++ apps/web/vite.config.ts | 19 ++++++++++++++++--- 4 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 apps/server/Dockerfile create mode 100644 apps/web/Dockerfile create mode 100644 apps/web/nginx.conf diff --git a/apps/server/Dockerfile b/apps/server/Dockerfile new file mode 100644 index 0000000..d51803a --- /dev/null +++ b/apps/server/Dockerfile @@ -0,0 +1,40 @@ +FROM oven/bun:1.1.8-alpine AS base + +WORKDIR /app + +# Copy package files +COPY package.json bun.lockb ./ +COPY apps/server/package.json ./apps/server/ +COPY packages/ ./packages/ + +# Install dependencies +RUN bun install --frozen-lockfile + +# Copy source code +COPY apps/server/ ./apps/server/ +COPY turbo.json ./ + +# Build the application +RUN bun run build + +# Production stage +FROM oven/bun:1.1.8-alpine AS production + +WORKDIR /app + +# Copy built application +COPY --from=base /app/apps/server/dist ./dist +COPY --from=base /app/node_modules ./node_modules +COPY --from=base /app/apps/server/package.json ./ + +# Create non-root user +RUN addgroup -g 1001 -S nodejs +RUN adduser -S bun -u 1001 +USER bun + +EXPOSE 3000 + +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD curl -f http://localhost:3000/health || exit 1 + +CMD ["bun", "run", "dist/index.js"] \ No newline at end of file diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile new file mode 100644 index 0000000..e586ef6 --- /dev/null +++ b/apps/web/Dockerfile @@ -0,0 +1,38 @@ +FROM oven/bun:1.1.8-alpine AS base + +WORKDIR /app + +# Copy package files +COPY package.json bun.lockb ./ +COPY apps/web/package.json ./apps/web/ +COPY packages/ ./packages/ + +# Install dependencies +RUN bun install --frozen-lockfile + +# Copy source code +COPY apps/web/ ./apps/web/ +COPY turbo.json ./ + +# Build the application +RUN bun run build + +# Production stage +FROM nginx:alpine AS production + +# Copy built application +COPY --from=base /app/apps/web/dist /usr/share/nginx/html + +# Copy custom nginx config +COPY apps/web/nginx.conf /etc/nginx/conf.d/default.conf + +# Create non-root user +RUN addgroup -g 1001 -S nodejs +RUN adduser -S nginx -u 1001 + +EXPOSE 3001 + +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD curl -f http://localhost:3001 || exit 1 + +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/apps/web/nginx.conf b/apps/web/nginx.conf new file mode 100644 index 0000000..a56e4b0 --- /dev/null +++ b/apps/web/nginx.conf @@ -0,0 +1,42 @@ +server { + listen 3001; + server_name _; + root /usr/share/nginx/html; + index index.html; + + # Security headers + add_header X-Frame-Options DENY; + add_header X-Content-Type-Options nosniff; + add_header X-XSS-Protection "1; mode=block"; + + # Gzip compression + gzip on; + gzip_vary on; + gzip_min_length 1024; + gzip_types + text/plain + text/css + text/xml + text/javascript + application/javascript + application/xml+rss + application/json; + + # Handle client-side routing + location / { + try_files $uri $uri/ /index.html; + } + + # Cache static assets + location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { + expires 1y; + add_header Cache-Control "public, immutable"; + } + + # Health check + location /health { + access_log off; + return 200 "healthy\n"; + add_header Content-Type text/plain; + } +} \ No newline at end of file diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.ts index d3bad29..7cc7db4 100644 --- a/apps/web/vite.config.ts +++ b/apps/web/vite.config.ts @@ -10,15 +10,28 @@ export default defineConfig({ react(), tanstackRouter({}), ], + build: { + minify: 'esbuild', // lightweight minifier + sourcemap: false, + chunkSizeWarningLimit: 10000, // avoid large chunk warnings + rollupOptions: { + output: { + // Only manually chunk large external dependencies + manualChunks(id) { + if (id.includes('node_modules/starknetkit')) return 'starknetkit'; + }, + }, + }, + }, optimizeDeps: { - include: ['@dynamic-labs/sdk-react-core'] + exclude: ['@dynamic-labs/sdk-react-core'], // avoid pre-bundling issues }, ssr: { - noExternal: ['@dynamic-labs/sdk-react-core'] + noExternal: ['@dynamic-labs/sdk-react-core'], // keep SSR-friendly }, resolve: { alias: { - "@": path.resolve(__dirname, "./src"), + '@': path.resolve(__dirname, './src'), // alias for src }, }, });