Lade Umgebungsvariablen aus /srv/myp-env/github.env
- Füge Funktionalität hinzu, um OAuth-Konfiguration aus /srv zu laden - Verwende env-file in Docker-Konfiguration - Übernimm alle Umgebungsvariablen richtig in Container-Umgebung - Behalte Fallback-Werte für fehlende Konfiguration bei - Vereinfache Integration mit vorhandenem System 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
3d576f0642
commit
ef04d7fd0f
@ -38,6 +38,7 @@ DEFAULT_BACKEND_URL="http://192.168.0.105:5000"
|
||||
IMAGE_NAME="myp-rp:latest"
|
||||
CONTAINER_NAME="myp-rp"
|
||||
DB_VOLUME_DIR="/srv/MYP-DB"
|
||||
ENV_FILE_PATH="/srv/myp-env/github.env"
|
||||
|
||||
# Prüfen, ob wir im Root des Projektverzeichnisses sind
|
||||
if [ ! -d "packages/reservation-platform" ]; then
|
||||
@ -81,6 +82,30 @@ else
|
||||
log "Datenbankverzeichnis existiert bereits: $DB_VOLUME_DIR"
|
||||
fi
|
||||
|
||||
# Funktion zum Laden der Umgebungsvariablen aus /srv/myp-env/github.env
|
||||
load_env_from_srv() {
|
||||
if [ -f "$ENV_FILE_PATH" ]; then
|
||||
log "Lade Umgebungsvariablen aus $ENV_FILE_PATH"
|
||||
|
||||
# Versuche, die Variablen aus der Datei zu laden
|
||||
OAUTH_CLIENT_ID=$(grep -oP 'OAUTH_CLIENT_ID=\K.*' "$ENV_FILE_PATH" 2>/dev/null || echo "client_id")
|
||||
OAUTH_CLIENT_SECRET=$(grep -oP 'OAUTH_CLIENT_SECRET=\K.*' "$ENV_FILE_PATH" 2>/dev/null || echo "client_secret")
|
||||
|
||||
# Prüfe, ob die Backend-URL in der Datei definiert ist
|
||||
BACKEND_URL_FROM_FILE=$(grep -oP 'NEXT_PUBLIC_API_URL=\K.*' "$ENV_FILE_PATH" 2>/dev/null)
|
||||
if [ -n "$BACKEND_URL_FROM_FILE" ]; then
|
||||
log "Backend-URL aus $ENV_FILE_PATH geladen: $BACKEND_URL_FROM_FILE"
|
||||
DEFAULT_BACKEND_URL="$BACKEND_URL_FROM_FILE"
|
||||
fi
|
||||
|
||||
success_log "OAuth-Konfiguration aus $ENV_FILE_PATH geladen."
|
||||
else
|
||||
log "${YELLOW}Warnung: $ENV_FILE_PATH nicht gefunden. Verwende Standard-Konfiguration.${NC}"
|
||||
OAUTH_CLIENT_ID="client_id"
|
||||
OAUTH_CLIENT_SECRET="client_secret"
|
||||
fi
|
||||
}
|
||||
|
||||
# Funktion zum Konfigurieren der Backend-URL
|
||||
configure_backend_url() {
|
||||
local backend_url="${1:-$DEFAULT_BACKEND_URL}"
|
||||
@ -88,6 +113,9 @@ configure_backend_url() {
|
||||
header "Backend-URL konfigurieren"
|
||||
log "Konfiguriere Backend-URL für Frontend: $backend_url"
|
||||
|
||||
# Lade OAuth-Konfiguration aus /srv
|
||||
load_env_from_srv
|
||||
|
||||
# Prüfen, ob setup-backend-url.sh existiert
|
||||
if [ -f "$FRONTEND_DIR/setup-backend-url.sh" ]; then
|
||||
chmod +x "$FRONTEND_DIR/setup-backend-url.sh"
|
||||
@ -120,9 +148,9 @@ NEXT_PUBLIC_FRONTEND_URL=http://${FRONTEND_HOSTNAME}
|
||||
# Explizite OAuth Callback URL für GitHub
|
||||
NEXT_PUBLIC_OAUTH_CALLBACK_URL=${OAUTH_URL}
|
||||
|
||||
# OAuth Konfiguration (falls nötig)
|
||||
OAUTH_CLIENT_ID=client_id
|
||||
OAUTH_CLIENT_SECRET=client_secret
|
||||
# OAuth Konfiguration aus /srv/myp-env/github.env
|
||||
OAUTH_CLIENT_ID=${OAUTH_CLIENT_ID}
|
||||
OAUTH_CLIENT_SECRET=${OAUTH_CLIENT_SECRET}
|
||||
EOL
|
||||
|
||||
if [ ! -f "$FRONTEND_DIR/.env.local" ]; then
|
||||
@ -251,6 +279,11 @@ start_container_compose() {
|
||||
# Erstellen der vereinfachten docker-compose.yml-Datei
|
||||
local compose_file="$DOCKER_DIR/compose.simple.yml"
|
||||
|
||||
# Lade OAuth-Konfiguration aus /srv, falls noch nicht geschehen
|
||||
if [ -z "$OAUTH_CLIENT_ID" ]; then
|
||||
load_env_from_srv
|
||||
fi
|
||||
|
||||
log "Erstelle vereinfachte Docker-Compose-Datei: $compose_file"
|
||||
cat > "$compose_file" << EOL
|
||||
services:
|
||||
@ -261,8 +294,9 @@ services:
|
||||
- NEXT_PUBLIC_API_URL=${BACKEND_URL}
|
||||
- NEXT_PUBLIC_FRONTEND_URL=http://${FRONTEND_HOSTNAME}
|
||||
- NEXT_PUBLIC_OAUTH_CALLBACK_URL=${OAUTH_URL}
|
||||
- OAUTH_CLIENT_ID=client_id
|
||||
- OAUTH_CLIENT_SECRET=client_secret
|
||||
- OAUTH_CLIENT_ID=${OAUTH_CLIENT_ID}
|
||||
- OAUTH_CLIENT_SECRET=${OAUTH_CLIENT_SECRET}
|
||||
env_file: "${ENV_FILE_PATH}"
|
||||
ports:
|
||||
- "3000:3000"
|
||||
volumes:
|
||||
@ -316,6 +350,11 @@ start_container_run() {
|
||||
docker rm "$CONTAINER_NAME" &>/dev/null || true
|
||||
fi
|
||||
|
||||
# Lade OAuth-Konfiguration aus /srv, falls noch nicht geschehen
|
||||
if [ -z "$OAUTH_CLIENT_ID" ]; then
|
||||
load_env_from_srv
|
||||
fi
|
||||
|
||||
# Container starten
|
||||
log "Starte Container mit 'docker run'..."
|
||||
|
||||
@ -324,8 +363,9 @@ start_container_run() {
|
||||
-e "NEXT_PUBLIC_API_URL=$BACKEND_URL" \
|
||||
-e "NEXT_PUBLIC_FRONTEND_URL=http://${FRONTEND_HOSTNAME}" \
|
||||
-e "NEXT_PUBLIC_OAUTH_CALLBACK_URL=${OAUTH_URL}" \
|
||||
-e "OAUTH_CLIENT_ID=client_id" \
|
||||
-e "OAUTH_CLIENT_SECRET=client_secret" \
|
||||
-e "OAUTH_CLIENT_ID=${OAUTH_CLIENT_ID}" \
|
||||
-e "OAUTH_CLIENT_SECRET=${OAUTH_CLIENT_SECRET}" \
|
||||
--env-file "$ENV_FILE_PATH" \
|
||||
-v "$DB_VOLUME_DIR:/app/db" \
|
||||
--restart unless-stopped \
|
||||
"$IMAGE_NAME"; then
|
||||
@ -365,7 +405,8 @@ start_without_docker() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Konfiguriere die Backend-URL
|
||||
# Lade OAuth-Konfiguration aus /srv und konfiguriere die Backend-URL
|
||||
load_env_from_srv
|
||||
if ! configure_backend_url "$BACKEND_URL"; then
|
||||
error_log "Fehler beim Konfigurieren der Backend-URL."
|
||||
return 1
|
||||
@ -380,13 +421,30 @@ start_without_docker() {
|
||||
# Starte im Screen-Session, damit die Anwendung im Hintergrund läuft
|
||||
if command -v screen &> /dev/null; then
|
||||
log "Starte Anwendung in Screen-Session..."
|
||||
screen -dmS myp-frontend bash -c "cd $FRONTEND_DIR && NEXT_PUBLIC_API_URL=$BACKEND_URL pnpm start || NEXT_PUBLIC_API_URL=$BACKEND_URL pnpm dev"
|
||||
screen -dmS myp-frontend bash -c "cd $FRONTEND_DIR && \
|
||||
NEXT_PUBLIC_API_URL=$BACKEND_URL \
|
||||
NEXT_PUBLIC_FRONTEND_URL=http://${FRONTEND_HOSTNAME} \
|
||||
NEXT_PUBLIC_OAUTH_CALLBACK_URL=${OAUTH_URL} \
|
||||
OAUTH_CLIENT_ID=${OAUTH_CLIENT_ID} \
|
||||
OAUTH_CLIENT_SECRET=${OAUTH_CLIENT_SECRET} \
|
||||
pnpm start || \
|
||||
NEXT_PUBLIC_API_URL=$BACKEND_URL \
|
||||
NEXT_PUBLIC_FRONTEND_URL=http://${FRONTEND_HOSTNAME} \
|
||||
NEXT_PUBLIC_OAUTH_CALLBACK_URL=${OAUTH_URL} \
|
||||
OAUTH_CLIENT_ID=${OAUTH_CLIENT_ID} \
|
||||
OAUTH_CLIENT_SECRET=${OAUTH_CLIENT_SECRET} \
|
||||
pnpm dev"
|
||||
success_log "Anwendung im Hintergrund gestartet. Verbinden mit: screen -r myp-frontend"
|
||||
else
|
||||
log "${YELLOW}Screen ist nicht installiert. Starte Anwendung im Vordergrund...${NC}"
|
||||
log "${YELLOW}Beenden mit Strg+C. Die Anwendung wird dann beendet.${NC}"
|
||||
sleep 3
|
||||
NEXT_PUBLIC_API_URL="$BACKEND_URL" pnpm start || NEXT_PUBLIC_API_URL="$BACKEND_URL" pnpm dev
|
||||
export NEXT_PUBLIC_API_URL="$BACKEND_URL"
|
||||
export NEXT_PUBLIC_FRONTEND_URL="http://${FRONTEND_HOSTNAME}"
|
||||
export NEXT_PUBLIC_OAUTH_CALLBACK_URL="${OAUTH_URL}"
|
||||
export OAUTH_CLIENT_ID="${OAUTH_CLIENT_ID}"
|
||||
export OAUTH_CLIENT_SECRET="${OAUTH_CLIENT_SECRET}"
|
||||
pnpm start || pnpm dev
|
||||
fi
|
||||
|
||||
return 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user