For Frontend practice
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
# Copy and edit values for your production/student environment.
|
||||
|
||||
# API
|
||||
PORT=3000
|
||||
NODE_ENV=production
|
||||
DATABASE_URL=postgresql://webstore_user:webstore_password@db:5432/webstore_db?schema=public
|
||||
JWT_SECRET=change-me-in-real-use
|
||||
JWT_EXPIRES_IN=7d
|
||||
COOKIE_NAME=webstore_token
|
||||
COOKIE_SECURE=false
|
||||
|
||||
# Database container bootstrap
|
||||
POSTGRES_DB=webstore_db
|
||||
POSTGRES_USER=webstore_user
|
||||
POSTGRES_PASSWORD=webstore_password
|
||||
|
||||
# Optional: host port overrides
|
||||
API_PORT=3000
|
||||
DB_PORT=5432
|
||||
@@ -0,0 +1,36 @@
|
||||
services:
|
||||
db:
|
||||
image: postgres:16-alpine
|
||||
container_name: webstore_db_prod
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
POSTGRES_USER: ${POSTGRES_USER}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
ports:
|
||||
- "${DB_PORT:-5432}:5432"
|
||||
volumes:
|
||||
- postgres_data_prod:/var/lib/postgresql/data
|
||||
|
||||
api:
|
||||
image: webstore-api:prod
|
||||
container_name: webstore_api_prod
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
- db
|
||||
env_file:
|
||||
- .production.env
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
DATABASE_URL: ${DATABASE_URL}
|
||||
PORT: ${PORT}
|
||||
JWT_SECRET: ${JWT_SECRET}
|
||||
JWT_EXPIRES_IN: ${JWT_EXPIRES_IN}
|
||||
COOKIE_NAME: ${COOKIE_NAME}
|
||||
COOKIE_SECURE: ${COOKIE_SECURE}
|
||||
command: sh -c "npm run prisma:generate && npm run prisma:push && npm run prisma:seed && npm start"
|
||||
ports:
|
||||
- "${API_PORT:-3000}:3000"
|
||||
|
||||
volumes:
|
||||
postgres_data_prod:
|
||||
@@ -0,0 +1,69 @@
|
||||
@echo off
|
||||
setlocal EnableExtensions EnableDelayedExpansion
|
||||
|
||||
set "ROOT_DIR=%~dp0"
|
||||
set "ENV_FILE=%ROOT_DIR%\.production.env"
|
||||
set "COMPOSE_FILE=%ROOT_DIR%\production.compose.yml"
|
||||
set "ARCHIVE_FILE=%ROOT_DIR%\images\webstore-production-images.tar"
|
||||
|
||||
set "API_IMAGE=webstore-api:prod"
|
||||
|
||||
echo [1/7] Checking Docker + Compose...
|
||||
docker --version >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo ERROR: Docker CLI is not available.
|
||||
exit /b 1
|
||||
)
|
||||
docker compose version >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo ERROR: Docker Compose plugin is not available.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo [2/7] Validating required files...
|
||||
if not exist "%ENV_FILE%" (
|
||||
echo ERROR: Missing env file: "%ENV_FILE%"
|
||||
exit /b 1
|
||||
)
|
||||
if not exist "%COMPOSE_FILE%" (
|
||||
echo ERROR: Missing compose file: "%COMPOSE_FILE%"
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo [3/7] Loading prebuilt image archive if present...
|
||||
if exist "%ARCHIVE_FILE%" (
|
||||
docker load -i "%ARCHIVE_FILE%"
|
||||
if errorlevel 1 (
|
||||
echo ERROR: Failed to load image archive.
|
||||
exit /b 1
|
||||
)
|
||||
) else (
|
||||
echo WARN: "%ARCHIVE_FILE%" not found. Assuming images already exist locally.
|
||||
)
|
||||
|
||||
echo [4/7] Ensuring API image exists locally...
|
||||
docker image inspect "%API_IMAGE%" >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo ERROR: API image "%API_IMAGE%" not found.
|
||||
echo Run scripts\build-production-images.bat first or provide the archive in images\.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo [5/7] Starting production stack for students...
|
||||
pushd "%ROOT_DIR%" >nul
|
||||
docker compose --env-file .production.env -f production.compose.yml up -d
|
||||
if errorlevel 1 (
|
||||
popd >nul
|
||||
echo ERROR: Failed to start compose stack.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo [6/7] Showing running services...
|
||||
docker compose --env-file .production.env -f production.compose.yml ps
|
||||
|
||||
echo [7/7] Done.
|
||||
echo API should be available at http://localhost:3000 (or API_PORT in .production.env)
|
||||
echo Stop stack with:
|
||||
echo docker compose --env-file .production.env -f production.compose.yml down
|
||||
popd >nul
|
||||
exit /b 0
|
||||
Binary file not shown.
Reference in New Issue
Block a user