From 3e296b51318e8a3e556d75671ad95b7e890346d1 Mon Sep 17 00:00:00 2001 From: fhs52267 Date: Thu, 2 Apr 2026 22:03:48 +0200 Subject: [PATCH] Improve dev setup --- .gitea/workflows/build-and-push-images.yaml | 1 + README.md | 58 ++++++++++++++++ src/compose.dev.yml | 28 -------- src/compose.yml | 77 +++++++++------------ src/frontend/Containerfile | 19 ++++- src/frontend/Containerfile.dev | 12 ---- 6 files changed, 109 insertions(+), 86 deletions(-) delete mode 100644 src/compose.dev.yml delete mode 100644 src/frontend/Containerfile.dev diff --git a/.gitea/workflows/build-and-push-images.yaml b/.gitea/workflows/build-and-push-images.yaml index 2a000da..cc085f0 100644 --- a/.gitea/workflows/build-and-push-images.yaml +++ b/.gitea/workflows/build-and-push-images.yaml @@ -65,6 +65,7 @@ jobs: /kaniko/executor --context=$GITHUB_WORKSPACE/src/frontend --dockerfile=$GITHUB_WORKSPACE/src/frontend/Containerfile + --target=prod ${{ steps.meta.outputs.frontend_dests }}" - name: Build and Push Backend diff --git a/README.md b/README.md index e879d43..3d131fe 100644 --- a/README.md +++ b/README.md @@ -46,3 +46,61 @@ docker compose up -d ``` Open `http://localhost:8080`. + +## Development + +### Quick Start with Docker Compose + +Use the development compose file to run the full stack with hot reload: + +```bash +cd src +docker compose up -d +``` + +This will start the backend and frontend, proxied through Nginx at `http://localhost:8080`. Also, a Mailpit instance at `http://localhost:8081` can be used for monitoring outgoing mail. + +### Backend Development + +The backend is a FastAPI application using SQLite and runs on Python 3.12. + +**Dockerfile**: `src/backend/Containerfile` - Production build + +**Development**: + +```bash +cd src/backend +pip install -r requirements.txt +uvicorn app.main:app --reload +``` + +Changes to `app/` are automatically detected when running with `--reload`. + +### Frontend Development + +The frontend is a React + TypeScript application using Vite. + +**Dockerfile**: + +- `src/frontend/Containerfile`: Multi-target build with `dev` and `prod` stages + +Use the `dev` target for hot reload and the `prod` target for the static production image. + +**Development**: + +```bash +cd src/frontend +npm install +npm run dev +``` + +Open `http://localhost:5173` (or the address shown in the terminal). + +## Contributing + +Contributions are welcome! Please follow these guidelines: + +1. **Choose an existing issue** or create one first to discuss your changes +2. **Fork the repository** and create a feature branch +3. **Test your changes** in the development environment using `compose.yml` +4. **Submit a pull request** linking to the related issue diff --git a/src/compose.dev.yml b/src/compose.dev.yml deleted file mode 100644 index 9b01e08..0000000 --- a/src/compose.dev.yml +++ /dev/null @@ -1,28 +0,0 @@ -services: - nginx: - volumes: - - ../nginx.conf:/etc/nginx/conf.d/default.conf:ro - - backend: - build: - context: backend - dockerfile: Containerfile - volumes: - - ../.data:/app/data - - ../config.yaml:/app/config.yaml:ro - - ./backend/app:/app/app - command: uvicorn app.main:app --host 0.0.0.0 --port 5000 --reload - - frontend: - build: - context: frontend - dockerfile: Containerfile.dev - volumes: - - ./frontend/src:/app/src - - ./frontend/public:/app/public - - ./frontend/index.html:/app/index.html - - ./frontend/vite.config.ts:/app/vite.config.ts - - ./frontend/tsconfig.json:/app/tsconfig.json - - ./frontend/tsconfig.node.json:/app/tsconfig.node.json - - /app/node_modules - command: npm run dev -- --host 0.0.0.0 --port 8000 diff --git a/src/compose.yml b/src/compose.yml index 6cbcc9b..36d41cd 100644 --- a/src/compose.yml +++ b/src/compose.yml @@ -1,10 +1,41 @@ services: + backend: + build: + context: backend + dockerfile: Containerfile + volumes: + - ../.data:/app/data + - ../config.yaml:/app/config.yaml:ro + - ./backend/app:/app/app + environment: + - APP_ENV=production + - LOG_LEVEL=info + - DB_PATH=/app/data + - SMTP_HOST=mailpit + - SMTP_PORT=1025 + restart: unless-stopped + command: uvicorn app.main:app --host 0.0.0.0 --port 5000 --reload + + frontend: + build: + context: frontend + dockerfile: Containerfile + target: dev + volumes: + - ./frontend/src:/app/src + - ./frontend/public:/app/public + - ./frontend/index.html:/app/index.html + - ./frontend/vite.config.ts:/app/vite.config.ts + - ./frontend/tsconfig.json:/app/tsconfig.json + - ./frontend/tsconfig.node.json:/app/tsconfig.node.json + - /app/node_modules + command: npm run dev -- --host 0.0.0.0 --port 8000 + mailpit: image: axllent/mailpit:latest container_name: lunchtime-mailpit ports: - - "1025:1025" - - "8025:8025" + - "8081:8081" restart: unless-stopped networks: burger-network: @@ -13,7 +44,6 @@ services: nginx: image: nginx:alpine - container_name: lunchtime-nginx ports: - "8080:8080" volumes: @@ -21,43 +51,4 @@ services: depends_on: - backend - frontend - restart: unless-stopped - networks: - - burger-network - - backend: - build: - context: backend - dockerfile: Containerfile - container_name: lunchtime-backend - volumes: - - ../.data:/app/data - - ../config.yaml:/app/config.yaml:ro - environment: - - APP_ENV=production - - LOG_LEVEL=info - - DB_PATH=/app/data - - SMTP_HOST=mailpit - - SMTP_PORT=1025 - restart: unless-stopped - networks: - burger-network: - aliases: - - backend - depends_on: - - mailpit - - frontend: - build: - context: frontend - dockerfile: Containerfile - container_name: lunchtime-frontend - restart: unless-stopped - networks: - burger-network: - aliases: - - frontend - -networks: - burger-network: - driver: bridge + restart: unless-stopped \ No newline at end of file diff --git a/src/frontend/Containerfile b/src/frontend/Containerfile index 539ec3e..d238fa2 100644 --- a/src/frontend/Containerfile +++ b/src/frontend/Containerfile @@ -1,14 +1,27 @@ -FROM node:20-slim AS build +FROM node:20-slim AS base WORKDIR /app COPY package*.json ./ RUN npm ci + +FROM base AS dev + +COPY . ./ + +EXPOSE 5173 + +CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0", "--port", "5173"] + + +FROM base AS build + COPY . ./ RUN npm run build -FROM node:20-slim + +FROM node:20-slim AS prod WORKDIR /app @@ -19,6 +32,6 @@ COPY --from=build /app/dist ./ EXPOSE 8000 HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD wget -q -O- http://localhost:8000/index.html || exit 1 + CMD node -e "require('http').get('http://localhost:8000/index.html', (res) => process.exit(res.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))" CMD ["http-server", ".", "-p", "8000", "-c-1", "--gzip", "-P", "http://localhost:8000?"] diff --git a/src/frontend/Containerfile.dev b/src/frontend/Containerfile.dev deleted file mode 100644 index d8e67d5..0000000 --- a/src/frontend/Containerfile.dev +++ /dev/null @@ -1,12 +0,0 @@ -FROM node:20-slim - -WORKDIR /app - -COPY package*.json ./ -RUN npm ci - -COPY . ./ - -EXPOSE 5173 - -CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0", "--port", "5173"]