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"
|
IMAGE_NAME="myp-rp:latest"
|
||||||
CONTAINER_NAME="myp-rp"
|
CONTAINER_NAME="myp-rp"
|
||||||
DB_VOLUME_DIR="/srv/MYP-DB"
|
DB_VOLUME_DIR="/srv/MYP-DB"
|
||||||
|
ENV_FILE_PATH="/srv/myp-env/github.env"
|
||||||
|
|
||||||
# Prüfen, ob wir im Root des Projektverzeichnisses sind
|
# Prüfen, ob wir im Root des Projektverzeichnisses sind
|
||||||
if [ ! -d "packages/reservation-platform" ]; then
|
if [ ! -d "packages/reservation-platform" ]; then
|
||||||
@ -81,6 +82,30 @@ else
|
|||||||
log "Datenbankverzeichnis existiert bereits: $DB_VOLUME_DIR"
|
log "Datenbankverzeichnis existiert bereits: $DB_VOLUME_DIR"
|
||||||
fi
|
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
|
# Funktion zum Konfigurieren der Backend-URL
|
||||||
configure_backend_url() {
|
configure_backend_url() {
|
||||||
local backend_url="${1:-$DEFAULT_BACKEND_URL}"
|
local backend_url="${1:-$DEFAULT_BACKEND_URL}"
|
||||||
@ -88,6 +113,9 @@ configure_backend_url() {
|
|||||||
header "Backend-URL konfigurieren"
|
header "Backend-URL konfigurieren"
|
||||||
log "Konfiguriere Backend-URL für Frontend: $backend_url"
|
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
|
# Prüfen, ob setup-backend-url.sh existiert
|
||||||
if [ -f "$FRONTEND_DIR/setup-backend-url.sh" ]; then
|
if [ -f "$FRONTEND_DIR/setup-backend-url.sh" ]; then
|
||||||
chmod +x "$FRONTEND_DIR/setup-backend-url.sh"
|
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
|
# Explizite OAuth Callback URL für GitHub
|
||||||
NEXT_PUBLIC_OAUTH_CALLBACK_URL=${OAUTH_URL}
|
NEXT_PUBLIC_OAUTH_CALLBACK_URL=${OAUTH_URL}
|
||||||
|
|
||||||
# OAuth Konfiguration (falls nötig)
|
# OAuth Konfiguration aus /srv/myp-env/github.env
|
||||||
OAUTH_CLIENT_ID=client_id
|
OAUTH_CLIENT_ID=${OAUTH_CLIENT_ID}
|
||||||
OAUTH_CLIENT_SECRET=client_secret
|
OAUTH_CLIENT_SECRET=${OAUTH_CLIENT_SECRET}
|
||||||
EOL
|
EOL
|
||||||
|
|
||||||
if [ ! -f "$FRONTEND_DIR/.env.local" ]; then
|
if [ ! -f "$FRONTEND_DIR/.env.local" ]; then
|
||||||
@ -251,6 +279,11 @@ start_container_compose() {
|
|||||||
# Erstellen der vereinfachten docker-compose.yml-Datei
|
# Erstellen der vereinfachten docker-compose.yml-Datei
|
||||||
local compose_file="$DOCKER_DIR/compose.simple.yml"
|
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"
|
log "Erstelle vereinfachte Docker-Compose-Datei: $compose_file"
|
||||||
cat > "$compose_file" << EOL
|
cat > "$compose_file" << EOL
|
||||||
services:
|
services:
|
||||||
@ -261,8 +294,9 @@ services:
|
|||||||
- NEXT_PUBLIC_API_URL=${BACKEND_URL}
|
- NEXT_PUBLIC_API_URL=${BACKEND_URL}
|
||||||
- NEXT_PUBLIC_FRONTEND_URL=http://${FRONTEND_HOSTNAME}
|
- NEXT_PUBLIC_FRONTEND_URL=http://${FRONTEND_HOSTNAME}
|
||||||
- NEXT_PUBLIC_OAUTH_CALLBACK_URL=${OAUTH_URL}
|
- NEXT_PUBLIC_OAUTH_CALLBACK_URL=${OAUTH_URL}
|
||||||
- OAUTH_CLIENT_ID=client_id
|
- OAUTH_CLIENT_ID=${OAUTH_CLIENT_ID}
|
||||||
- OAUTH_CLIENT_SECRET=client_secret
|
- OAUTH_CLIENT_SECRET=${OAUTH_CLIENT_SECRET}
|
||||||
|
env_file: "${ENV_FILE_PATH}"
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
volumes:
|
volumes:
|
||||||
@ -316,6 +350,11 @@ start_container_run() {
|
|||||||
docker rm "$CONTAINER_NAME" &>/dev/null || true
|
docker rm "$CONTAINER_NAME" &>/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Lade OAuth-Konfiguration aus /srv, falls noch nicht geschehen
|
||||||
|
if [ -z "$OAUTH_CLIENT_ID" ]; then
|
||||||
|
load_env_from_srv
|
||||||
|
fi
|
||||||
|
|
||||||
# Container starten
|
# Container starten
|
||||||
log "Starte Container mit 'docker run'..."
|
log "Starte Container mit 'docker run'..."
|
||||||
|
|
||||||
@ -324,8 +363,9 @@ start_container_run() {
|
|||||||
-e "NEXT_PUBLIC_API_URL=$BACKEND_URL" \
|
-e "NEXT_PUBLIC_API_URL=$BACKEND_URL" \
|
||||||
-e "NEXT_PUBLIC_FRONTEND_URL=http://${FRONTEND_HOSTNAME}" \
|
-e "NEXT_PUBLIC_FRONTEND_URL=http://${FRONTEND_HOSTNAME}" \
|
||||||
-e "NEXT_PUBLIC_OAUTH_CALLBACK_URL=${OAUTH_URL}" \
|
-e "NEXT_PUBLIC_OAUTH_CALLBACK_URL=${OAUTH_URL}" \
|
||||||
-e "OAUTH_CLIENT_ID=client_id" \
|
-e "OAUTH_CLIENT_ID=${OAUTH_CLIENT_ID}" \
|
||||||
-e "OAUTH_CLIENT_SECRET=client_secret" \
|
-e "OAUTH_CLIENT_SECRET=${OAUTH_CLIENT_SECRET}" \
|
||||||
|
--env-file "$ENV_FILE_PATH" \
|
||||||
-v "$DB_VOLUME_DIR:/app/db" \
|
-v "$DB_VOLUME_DIR:/app/db" \
|
||||||
--restart unless-stopped \
|
--restart unless-stopped \
|
||||||
"$IMAGE_NAME"; then
|
"$IMAGE_NAME"; then
|
||||||
@ -365,7 +405,8 @@ start_without_docker() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
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
|
if ! configure_backend_url "$BACKEND_URL"; then
|
||||||
error_log "Fehler beim Konfigurieren der Backend-URL."
|
error_log "Fehler beim Konfigurieren der Backend-URL."
|
||||||
return 1
|
return 1
|
||||||
@ -380,13 +421,30 @@ start_without_docker() {
|
|||||||
# Starte im Screen-Session, damit die Anwendung im Hintergrund läuft
|
# Starte im Screen-Session, damit die Anwendung im Hintergrund läuft
|
||||||
if command -v screen &> /dev/null; then
|
if command -v screen &> /dev/null; then
|
||||||
log "Starte Anwendung in Screen-Session..."
|
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"
|
success_log "Anwendung im Hintergrund gestartet. Verbinden mit: screen -r myp-frontend"
|
||||||
else
|
else
|
||||||
log "${YELLOW}Screen ist nicht installiert. Starte Anwendung im Vordergrund...${NC}"
|
log "${YELLOW}Screen ist nicht installiert. Starte Anwendung im Vordergrund...${NC}"
|
||||||
log "${YELLOW}Beenden mit Strg+C. Die Anwendung wird dann beendet.${NC}"
|
log "${YELLOW}Beenden mit Strg+C. Die Anwendung wird dann beendet.${NC}"
|
||||||
sleep 3
|
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
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user