push dev-env

This commit is contained in:
2025-03-29 19:22:58 +01:00
parent e95770bdce
commit 6dd2324624
4 changed files with 155 additions and 0 deletions

72
backend/Dockerfile.dev Normal file
View File

@@ -0,0 +1,72 @@
# Stage 1: Build Dependencies
# Use an official Node.js runtime as a parent image
FROM node:18-alpine AS builder
WORKDIR /app
# Install OS dependencies needed for ping/traceroute
# Using apk add --no-cache reduces layer size
RUN apk add --no-cache iputils-ping traceroute
# Copy package.json and package-lock.json (or yarn.lock)
# Ensure these files include 'oui' as a dependency before building!
COPY package*.json ./
# Install app dependencies using npm ci for faster, reliable builds
# --only=production installs only production dependencies (including 'oui')
RUN npm ci --only=production
# REMOVED: RUN npm i oui (should be installed by npm ci now)
# Stage 2: Production Image
FROM node:18-alpine
WORKDIR /app
# Install only necessary OS dependencies again for the final image
RUN apk add --no-cache iputils-ping traceroute
# Copy dependencies from the builder stage
COPY --from=builder /app/node_modules ./node_modules
# Copy application code
COPY . .
# Copy MaxMind data (assuming it's in ./data)
# Ensure the 'data' directory exists in your project root
COPY ./data ./data
# Create a non-root user and group
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# Optional: Change ownership of app files to the new user
# RUN chown -R appuser:appgroup /app
# Switch to the non-root user
USER appuser
# Make port specified in environment variable available to the world outside this container
# Default to 3000 if not specified
ARG PORT=3000
ENV PORT=${PORT}
EXPOSE ${PORT}
# Define environment variable for Node environment (important for Pino, Express etc.)
ENV NODE_ENV=production
# Define default Log Level if not set externally
ENV LOG_LEVEL=info
# Define default Ping Count if not set externally
ENV PING_COUNT=4
# Define paths to GeoIP DBs (can be overridden by external .env or docker run -e)
ENV GEOIP_CITY_DB=./data/GeoLite2-City.mmdb
ENV GEOIP_ASN_DB=./data/GeoLite2-ASN.mmdb
# Define build argument and environment variable for Git commit SHA
ARG GIT_COMMIT_SHA=unknown
ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA}
# Define build argument and environment variable for Sentry DSN
ARG SENTRY_DSN
ENV SENTRY_DSN=${SENTRY_DSN}
# Run the app when the container launches
CMD ["node", "server.js"]

3
build-dev.sh Normal file
View File

@@ -0,0 +1,3 @@
docker compose down
export GIT_COMMIT_SHA=$(git rev-parse --short HEAD)
docker compose -f compose.dev.yml up -d --build

54
compose.dev.yml Normal file
View File

@@ -0,0 +1,54 @@
services:
# Backend Service (Node.js App)
backend-dev:
build:
context: ./backend # Pfad zum Verzeichnis mit dem Backend-Dockerfile
dockerfile: Dockerfile.dev
args:
# Übergibt den Git Commit Hash als Build-Argument.
# Erwartet, dass GIT_COMMIT_SHA in der Shell-Umgebung gesetzt ist (z.B. export GIT_COMMIT_SHA=$(git rev-parse --short HEAD))
- GIT_COMMIT_SHA=${GIT_COMMIT_SHA:-unknown}
# Übergibt den Sentry DSN als Build-Argument (optional, falls im Code benötigt)
- SENTRY_DSN="https://7ea70caba68f548fb96482a573006a7b@o447623.ingest.us.sentry.io/4509062020333568"
container_name: utools_backend # Eindeutiger Name für den Container
restart: unless-stopped
environment:
# Setze Umgebungsvariablen für das Backend
NODE_ENV: production # Wichtig für Performance und Logging
PORT: 3000 # Port innerhalb des Containers
LOG_LEVEL: info # Oder 'warn' für weniger Logs in Produktion
PING_COUNT: 4
# Die DB-Pfade werden aus dem Backend-Dockerfile ENV genommen,
# könnten hier aber überschrieben werden, falls nötig.
# GEOIP_CITY_DB: ./data/GeoLite2-City.mmdb
# GEOIP_ASN_DB: ./data/GeoLite2-ASN.mmdb
# Sentry DSN aus der Umgebung/ .env Datei übernehmen
SENTRY_DSN: "https://7ea70caba68f548fb96482a573006a7b@o447623.ingest.us.sentry.io/4509062020333568" # Wichtig für die Laufzeit
dns:
- 1.1.1.1 # Cloudflare DNS
- 1.0.0.1 # Cloudflare DNS
- 8.8.8.8 # Google DNS
- 8.8.4.4 # Google DNS
networks:
- utools_network # Verbinde mit unserem benutzerdefinierten Netzwerk
# Frontend Service (Nginx)
frontend-dev:
build:
context: ./frontend # Pfad zum Verzeichnis mit dem Frontend-Dockerfile
dockerfile: Dockerfile.dev
container_name: utools_frontend
restart: unless-stopped
ports:
# Mappe Port 8080 vom Host auf Port 80 im Container (wo Nginx lauscht)
# Zugriff von außen (Browser) erfolgt über localhost:8080
- "8080:80"
depends_on:
- backend # Stellt sicher, dass Backend gestartet wird (aber nicht unbedingt bereit ist)
networks:
- utools_network # Verbinde mit unserem benutzerdefinierten Netzwerk
# Definiere ein benutzerdefiniertes Netzwerk (gute Praxis)
networks:
utools_network:
driver: bridge # Standard-Netzwerktreiber

26
frontend/Dockerfile.dev Normal file
View File

@@ -0,0 +1,26 @@
# Stage 1: Build (falls wir später einen Build-Schritt hätten, z.B. für Tailwind Purge)
# Aktuell nicht nötig, da wir CDN/statische Dateien haben.
# Stage 2: Production Environment using Nginx
FROM nginx:1.25-alpine
# Arbeitsverzeichnis im Container (optional, aber gute Praxis)
WORKDIR /usr/share/nginx/html
# Entferne die Standard Nginx Willkommensseite
RUN rm /etc/nginx/conf.d/default.conf
# Kopiere unsere eigene Nginx Konfiguration
COPY nginx.conf /etc/nginx/conf.d/default.conf
# Kopiere die Frontend-Dateien in das Verzeichnis, das Nginx ausliefert
COPY app/ .
# Falls du später CSS-Dateien oder Bilder hast, kopiere sie auch:
# COPY styles.css .
# COPY images/ ./images
# Nginx lauscht standardmäßig auf Port 80
EXPOSE 80
# Der Basis-Image startet Nginx bereits. Kein CMD nötig, außer wir wollen Optionen ändern.
# CMD ["nginx", "-g", "daemon off;"] # Standard-CMD im Basis-Image