From 488d419d447bb51cc3469e0461659c86fced7eaf Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 13 Jan 2026 08:13:42 +0000 Subject: [PATCH] feat: Add Dockerfile and GitHub Actions pipeline This commit introduces a multi-stage Dockerfile to containerize the frontend and backend applications. It also adds a GitHub Actions workflow to build the Docker image and validate the build process on every push to the main branch. - A multi-stage Dockerfile is added to build the frontend and backend separately and create a lean production image. - A `start.sh` script is added to run both the frontend and backend servers in the container. - A GitHub Actions workflow is added to automate the Docker build and validation process. - The `.dockerignore` file is updated to exclude unnecessary files from the build context. - The `package.json` file is updated to include the `serve` dependency for serving the frontend. - The `tsconfig.backend.json` file is added to configure the backend TypeScript compilation. - The `vite.config.ts` file is updated to support top-level await during the frontend build. --- .dockerignore | 29 +++++++++++++++++- .github/workflows/docker-build.yml | 25 +++++++++++++++ Dockerfile | 49 ++++++++++++++++++++++++++++++ backend/server.ts | 2 +- package.json | 3 +- start.sh | 14 +++++++++ tsconfig.backend.json | 11 +++++++ vite.config.ts | 3 ++ 8 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/docker-build.yml create mode 100755 start.sh create mode 100644 tsconfig.backend.json diff --git a/.dockerignore b/.dockerignore index f186a23..afb6e0e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,28 @@ -��^�j�W����u�� h�"���ج����K���� \ No newline at end of file +# Dependencies +node_modules/ + +# Git +.git/ +.gitignore + +# GitHub Actions +.github/ + +# Environment files +.env +.env.* + +# Docker +Dockerfile +docker-compose.yml +.dockerignore + +# Build artifacts +dist/ +build/ +.DS_Store + +# Logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..a0a2072 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,25 @@ +name: Docker Image Build + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and export + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: false diff --git a/Dockerfile b/Dockerfile index e69de29..a48266b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -0,0 +1,49 @@ +# Stage 1: Build Frontend +FROM node:20-slim AS frontend-builder +WORKDIR /app + +# Copy package files and install dependencies +COPY package.json package-lock.json* ./ +RUN npm install + +# Copy frontend source and build +COPY App.tsx index.html index.tsx vite.config.ts tsconfig.json ./ +COPY components ./components +COPY services ./services +COPY constants.ts types.ts ./ +RUN npm run build + +# Stage 2: Build Backend +FROM node:20-slim AS backend-builder +WORKDIR /app + +# Copy package files and install dependencies +COPY package.json package-lock.json* ./ +RUN npm install + +# Copy backend source and build +COPY backend ./backend +COPY tsconfig.json . +COPY tsconfig.backend.json . +RUN npx tsc --project tsconfig.backend.json + +# Stage 3: Production Image +FROM node:20-slim +WORKDIR /app + +# Install production dependencies +COPY package.json package-lock.json* ./ +RUN npm install --omit=dev + +# Copy built frontend and backend +COPY --from=frontend-builder /app/dist ./dist/frontend +COPY --from=backend-builder /app/dist ./dist/backend + +# Expose ports +EXPOSE 3000 3001 + +# Start script to run both servers +COPY start.sh . +RUN chmod +x start.sh + +CMD ["./start.sh"] diff --git a/backend/server.ts b/backend/server.ts index 997faf4..92f3fa8 100644 --- a/backend/server.ts +++ b/backend/server.ts @@ -1,7 +1,7 @@ import express from 'express'; import { createClient, AuthType } from 'webdav'; import mammoth from 'mammoth'; -import pdf from 'pdf-parse'; +import * as pdf from 'pdf-parse'; // --- Configuration --- const PORT = process.env.PORT || 3001; diff --git a/package.json b/package.json index 6dae1bf..51ed45c 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "pdfjs-dist": "4.0.379", "express": "^5.2.1", "pdf-parse": "^2.4.5", - "webdav": "^5.8.0" + "webdav": "^5.8.0", + "serve": "^14.2.1" }, "devDependencies": { "@types/node": "^22.14.0", diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..1c72349 --- /dev/null +++ b/start.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -e + +# Start the backend server in the background +node dist/backend/server.js & + +# Start a simple server for the frontend +npx serve -s dist/frontend -l 3000 + +# Wait for any process to exit +wait -n + +# Exit with status of process that exited first +exit $? diff --git a/tsconfig.backend.json b/tsconfig.backend.json new file mode 100644 index 0000000..0c2d04b --- /dev/null +++ b/tsconfig.backend.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "outDir": "dist", + "allowImportingTsExtensions": false + }, + "include": [ + "backend" + ] +} diff --git a/vite.config.ts b/vite.config.ts index ee5fb8d..b5ada48 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -9,6 +9,9 @@ export default defineConfig(({ mode }) => { port: 3000, host: '0.0.0.0', }, + build: { + target: 'esnext' + }, plugins: [react()], define: { 'process.env.API_KEY': JSON.stringify(env.GEMINI_API_KEY),