Compare commits

..

22 Commits

Author SHA1 Message Date
15107cdc63 removed routing 2025-10-22 23:31:38 +02:00
22266c765b api endpoints changed 2025-10-22 22:21:44 +02:00
a66609a40c pm2 not in home directory -> /app/ 2025-10-22 21:57:26 +02:00
87dda38bc3 updated user to have a home laufwerk 2025-10-22 21:42:47 +02:00
9de501c7eb changed user creation into debian style 2025-10-22 21:28:48 +02:00
5c6a50ddcf changed alpine production build to debian prod build 2025-10-22 21:22:09 +02:00
017f5fb2e0 copy database files manually 2025-10-22 21:01:46 +02:00
527954befd fix database paht 2025-10-22 20:50:36 +02:00
e7d30151b7 copy database files manually 2025-10-22 20:30:08 +02:00
4a006a2e69 copy database files manually 2025-10-22 20:27:01 +02:00
4b699b05d3 changed production stage from debian to alpine 2025-10-22 20:16:45 +02:00
dcac0307a2 copying no database folder seperate 2025-10-22 20:11:43 +02:00
a0cc859935 Merge branch 'staging' of https://github.com/donpat1to/Schichtenplaner into staging 2025-10-22 20:01:03 +02:00
49afd75ed3 copying database folder seperate 2025-10-22 19:21:13 +02:00
ebb9e3f4fe copying database folder seperate 2025-10-22 19:17:46 +02:00
48f140f930 changed docker.yml only triggering workflow on push 2025-10-22 15:08:52 +02:00
b6b31659e3 changed ecosystem file type as well in Dockerfile 2025-10-22 14:42:25 +02:00
42e343777a changed ecosystem file type as well in Dockerfile 2025-10-22 14:42:01 +02:00
aa7af272d8 moved js file to es module compatible cjs file type 2025-10-22 14:39:15 +02:00
a0d96925c5 added id-token: write 2025-10-22 10:46:15 +02:00
donpat1to
28283fa8bc Update docker.yml 2025-10-22 09:28:41 +02:00
donpat1to
fdff2853bd Update docker.yml 2025-10-22 09:19:37 +02:00
8 changed files with 68 additions and 68 deletions

View File

@@ -1,10 +1,10 @@
name: CI/CD Pipeline name: CI/CD Pipeline
on: on:
workflow_dispatch:
push: push:
branches: [ main, master, development ] branches: [ "development", "main", "staging" ]
pull_request: tags: [ "v*.*.*" ]
branches: [ main, master, development ]
env: env:
REGISTRY: ghcr.io REGISTRY: ghcr.io
@@ -110,8 +110,9 @@ jobs:
if: github.event_name == 'push' if: github.event_name == 'push'
permissions: permissions:
contents: read contents: write
packages: write packages: write
id-token: write
steps: steps:
- name: Checkout code - name: Checkout code
@@ -163,7 +164,7 @@ jobs:
- name: Display pushed images - name: Display pushed images
run: | run: |
echo "Docker images pushed successfully!" echo "Docker images pushed successfully!"
echo "📦 Image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" echo "- Image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
echo "🏷️ Tags: ${{ steps.meta.outputs.tags }}" echo "- Tags: ${{ steps.meta.outputs.tags }}"
echo "🚀 New version: ${{ needs.set-tag.outputs.tag_name }}" echo "- New version: ${{ needs.set-tag.outputs.tag_name }}"

View File

@@ -5,7 +5,7 @@ WORKDIR /app/backend
# Install Python + OR-Tools # Install Python + OR-Tools
RUN apt-get update && apt-get install -y python3 python3-pip build-essential \ RUN apt-get update && apt-get install -y python3 python3-pip build-essential \
&& pip install --no-cache-dir ortools && pip install --no-cache-dir ortools
# Create symlink so python3 is callable as python # Create symlink so python3 is callable as python
RUN ln -sf /usr/bin/python3 /usr/bin/python RUN ln -sf /usr/bin/python3 /usr/bin/python
@@ -23,13 +23,12 @@ COPY backend/src/ ./src/
# Build backend # Build backend
RUN npm run build RUN npm run build
# Copy database files manually
RUN cp -r src/database/ dist/database/
# Verify Python and OR-Tools installation # Verify Python and OR-Tools installation
RUN python -c "from ortools.sat.python import cp_model; print('OR-Tools installed successfully')" RUN python -c "from ortools.sat.python import cp_model; print('OR-Tools installed successfully')"
#RUN python3 -c "from ortools.sat.python import cp_model; print('OR-Tools installed successfully')"
# Frontend build stage # Frontend build stage
FROM node:20-bullseye AS frontend-builder FROM node:20-bullseye AS frontend-builder
@@ -50,45 +49,42 @@ COPY frontend/public/ ./public/
RUN npm run build RUN npm run build
# Production stage # Production stage
FROM node:20-alpine FROM node:20-bookworm
WORKDIR /app WORKDIR /app
# Install Python and OR-Tools for production
#RUN apk add --no-cache \
# python \
# py3-pip \
# && pip3 install ortools
# Install PM2 for process management # Install PM2 for process management
RUN npm install -g pm2 RUN npm install -g pm2
# Create data directory for SQLite database with proper permissions
RUN mkdir -p /app/data
# Copy backend built files # Copy backend built files
COPY --from=backend-builder /app/backend/package*.json ./ COPY --from=backend-builder /app/backend/package*.json ./
COPY --from=backend-builder /app/backend/dist/ ./dist/ COPY --from=backend-builder /app/backend/dist/ ./dist/
COPY --from=backend-builder /app/backend/node_modules/ ./node_modules/ COPY --from=backend-builder /app/backend/node_modules/ ./node_modules/
# COPY --from=backend-builder /app/backend/python-scripts/ ./python-scripts/
# Copy frontend built files # Copy frontend built files
COPY --from=frontend-builder /app/frontend/build/ ./frontend-build/ COPY --from=frontend-builder /app/frontend/build/ ./frontend-build/
# Copy PM2 configuration # Copy PM2 configuration
COPY ecosystem.config.js ./ COPY ecosystem.config.cjs ./
# Create a non-root user # Create a non-root user and group - DEBIAN STYLE
RUN addgroup -g 1001 -S nodejs && \ RUN groupadd -g 1001 nodejs && \
adduser -S schichtplan -u 1001 && \ useradd -m -u 1001 -s /bin/bash -g nodejs schichtplan && \
chown -R schichtplan:nodejs /app chown -R schichtplan:nodejs /app && \
chmod 755 /app && \
chmod 775 /app/data
# Set PM2 to use app directory instead of home directory
ENV PM2_HOME=/app/.pm2
USER schichtplan USER schichtplan
# Verify installations
#RUN python --version && \
# python -c "from ortools.sat.python import cp_model; print('OR-Tools verified')"
EXPOSE 3000 3002 EXPOSE 3000 3002
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3002/api/health || exit 1 CMD wget --no-verbose --tries=1 --spider http://localhost:3002/api/health || exit 1
CMD ["pm2-runtime", "ecosystem.config.js"] CMD ["pm2-runtime", "ecosystem.config.cjs"]

View File

@@ -1,6 +1,7 @@
// backend/src/server.ts // backend/src/server.ts
import express from 'express'; import express from 'express';
import cors from 'cors'; import { fileURLToPath } from 'url';
import path from 'path';
import { initializeDatabase } from './scripts/initializeDatabase.js'; import { initializeDatabase } from './scripts/initializeDatabase.js';
// Route imports // Route imports
@@ -11,13 +12,18 @@ import setupRoutes from './routes/setup.js';
import scheduledShifts from './routes/scheduledShifts.js'; import scheduledShifts from './routes/scheduledShifts.js';
import schedulingRoutes from './routes/scheduling.js'; import schedulingRoutes from './routes/scheduling.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express(); const app = express();
const PORT = 3002; const PORT = 3002;
// CORS und Middleware // Middleware
app.use(cors());
app.use(express.json()); app.use(express.json());
// Serviere statische Frontend-Dateien
app.use(express.static(path.join(__dirname, '../../frontend-build')));
// API Routes // API Routes
app.use('/api/setup', setupRoutes); app.use('/api/setup', setupRoutes);
app.use('/api/auth', authRoutes); app.use('/api/auth', authRoutes);

View File

@@ -1,10 +1,18 @@
import sqlite3 from 'sqlite3'; import sqlite3 from 'sqlite3';
import path from 'path'; import path from 'path';
import { fileURLToPath } from 'url'; import { fileURLToPath } from 'url';
import fs from 'fs';
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename); const __dirname = path.dirname(__filename);
const dbPath = path.join(__dirname, '../../database/schichtplan.db');
const dbPath = process.env.DB_PATH || '/app/data/schichtplan.db';
// Stelle sicher, dass das Verzeichnis existiert
const dbDir = path.dirname(dbPath);
if (!fs.existsSync(dbDir)) {
fs.mkdirSync(dbDir, { recursive: true });
}
class Database { class Database {
private db: sqlite3.Database; private db: sqlite3.Database;

18
ecosystem.config.cjs Normal file
View File

@@ -0,0 +1,18 @@
// ecosystem.config.cjs
module.exports = {
apps: [
{
name: 'schichtplaner',
script: './dist/server.js',
instances: 1,
exec_mode: 'fork',
env: {
NODE_ENV: 'production',
PORT: 3002
},
error_file: './logs/app-err.log',
out_file: './logs/app-out.log',
time: true
}
]
};

View File

@@ -1,30 +0,0 @@
module.exports = {
apps: [
{
name: 'backend',
script: './dist/server.js',
instances: 1,
exec_mode: 'fork',
env: {
NODE_ENV: 'production',
PORT: 3002
},
error_file: './logs/backend-err.log',
out_file: './logs/backend-out.log',
time: true
},
{
name: 'frontend',
script: 'npx',
args: 'serve -s frontend-build -l 3000',
instances: 1,
exec_mode: 'fork',
env: {
NODE_ENV: 'production'
},
error_file: './logs/frontend-err.log',
out_file: './logs/frontend-out.log',
time: true
}
]
};

View File

@@ -20,6 +20,7 @@ interface AuthContextType {
} }
const AuthContext = createContext<AuthContextType | undefined>(undefined); const AuthContext = createContext<AuthContextType | undefined>(undefined);
const API_BASE_URL = process.env.REACT_APP_API_BASE_URL || 'http://localhost:3002/api';
interface AuthProviderProps { interface AuthProviderProps {
children: ReactNode; children: ReactNode;
@@ -48,7 +49,7 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
const checkSetupStatus = async (): Promise<void> => { const checkSetupStatus = async (): Promise<void> => {
try { try {
console.log('🔍 Checking setup status...'); console.log('🔍 Checking setup status...');
const response = await fetch('http://localhost:3002/api/setup/status'); const response = await fetch(`${API_BASE_URL}/setup/status`);
if (!response.ok) { if (!response.ok) {
throw new Error('Setup status check failed'); throw new Error('Setup status check failed');
} }
@@ -72,7 +73,7 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
return; return;
} }
const response = await fetch('http://localhost:3002/api/auth/me', { const response = await fetch(`${API_BASE_URL}/auth/me`, {
headers: { headers: {
'Authorization': `Bearer ${token}` 'Authorization': `Bearer ${token}`
} }
@@ -104,7 +105,7 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
try { try {
console.log('🔐 Attempting login for:', credentials.email); console.log('🔐 Attempting login for:', credentials.email);
const response = await fetch('http://localhost:3002/api/auth/login', { const response = await fetch(`${API_BASE_URL}/auth/login`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',

View File

@@ -1,6 +1,6 @@
// frontend/src/services/authService.ts // frontend/src/services/authService.ts
import { Employee } from '../models/Employee'; import { Employee } from '../models/Employee';
const API_BASE = 'http://localhost:3002/api'; const API_BASE = process.env.REACT_APP_API_BASE_URL || 'http://localhost:3002/api';
export interface LoginRequest { export interface LoginRequest {
email: string; email: string;