From 29d4cef688af7a44ebb3c23f7a0c966fb3c102f0 Mon Sep 17 00:00:00 2001 From: Nils-Johan Gynther Date: Wed, 15 Apr 2026 20:06:20 +0200 Subject: [PATCH] feat: update Docker Compose configuration and add deployment script --- .env.example | 12 ++++++++++++ compose.yml | 12 +++++++++--- deploy.sh | 24 ++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 .env.example create mode 100644 deploy.sh diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..b5c71978 --- /dev/null +++ b/.env.example @@ -0,0 +1,12 @@ +# Kopiera till .env och fyll i riktiga värden +# cp .env.example .env + +# MariaDB +MARIADB_ROOT_PASSWORD=byt-ut-mig +MARIADB_DATABASE=recipe_app +MARIADB_USER=recipe_user +MARIADB_PASSWORD=byt-ut-mig + +# Publik URL (används av frontend) +NEXT_PUBLIC_APP_URL=https://recept.gynther.se +NEXT_PUBLIC_API_URL=https://api.recept.gynther.se diff --git a/compose.yml b/compose.yml index 3e197a64..98c77e6f 100644 --- a/compose.yml +++ b/compose.yml @@ -4,10 +4,15 @@ services: context: ./frontend dockerfile: Dockerfile image: recipe-frontend:local - pull_policy: never + container_name: recipe-frontend restart: unless-stopped environment: - NEXT_PUBLIC_API_URL: "http://recipe-api:8080" + NODE_ENV: "production" + HOSTNAME: "0.0.0.0" + PORT: "3000" + NEXT_PUBLIC_APP_URL: "${NEXT_PUBLIC_APP_URL}" + NEXT_PUBLIC_API_URL: "${NEXT_PUBLIC_API_URL}" + NEXT_PUBLIC_API_URL_INTERNAL: "http://recipe-api:8080" volumes: - recipe_images:/app/public/images depends_on: @@ -28,9 +33,10 @@ services: context: ./backend dockerfile: Dockerfile image: recipe-api:local - pull_policy: never + container_name: recipe-api restart: unless-stopped environment: + NODE_ENV: "production" DATABASE_URL: "mysql://root:${MARIADB_ROOT_PASSWORD}@recipe-db:3306/${MARIADB_DATABASE}" volumes: - recipe_images:/app/recipe-images diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 00000000..cb2ff2c9 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# deploy.sh – Bygg och starta om recipe-app +# Kör från: /opt/containers/recipe-app/ +# Kräver: .env-fil i samma mapp + +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$SCRIPT_DIR" + +if [ ! -f ".env" ]; then + echo "Fel: .env saknas. Kopiera .env.example och fyll i värdena:" + echo " cp .env.example .env && nano .env" + exit 1 +fi + +echo "Bygger images..." +docker compose build + +echo "Startar tjänster..." +docker compose up -d + +echo "Status:" +docker compose ps