chore: 킹서버 배포 스크립트, 포트 환경변수화, 프론트 nginx 가 /v1 을 백엔드로 전달
This commit is contained in:
1 parent
ebbc21dc0f
commit
64de307995
5 files changed
+48
-4
No files matched your search
@@ -19,3 +19,11 @@ PORT=9810
|
|||||||
# 생성: python -c "import secrets; print(secrets.token_urlsafe(48))"
|
# 생성: python -c "import secrets; print(secrets.token_urlsafe(48))"
|
||||||
JWT_ACCESS_SECRET=
|
JWT_ACCESS_SECRET=
|
||||||
JWT_REFRESH_SECRET=
|
JWT_REFRESH_SECRET=
|
||||||
|
|
||||||
|
# ── 배포(compose): 비우면 로컬 기본값. 킹서버 예: FRONT_PORT=30040, API_BIND=127.0.0.1:9810, PG_BIND=127.0.0.1:5440, REDIS_BIND=127.0.0.1:6390
|
||||||
|
FRONT_PORT=
|
||||||
|
API_BIND=
|
||||||
|
PG_BIND=
|
||||||
|
REDIS_BIND=
|
||||||
|
# 프론트가 부를 API 주소. 비우면 같은 주소의 /v1 (nginx 가 backend 로 넘김)
|
||||||
|
VITE_API_BASE_URL=
|
||||||
+7
-4
@@ -6,8 +6,11 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ./frontend
|
context: ./frontend
|
||||||
target: prod
|
target: prod
|
||||||
|
args:
|
||||||
|
# 비우면 같은 주소의 /v1 로 부르고 nginx 가 backend 로 넘긴다
|
||||||
|
VITE_API_BASE_URL: ${VITE_API_BASE_URL:-}
|
||||||
ports:
|
ports:
|
||||||
- "8080:80"
|
- "${FRONT_PORT:-8080}:80"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
# 개발형: docker compose --profile dev up --build frontend-dev → http://localhost:5173
|
# 개발형: docker compose --profile dev up --build frontend-dev → http://localhost:5173
|
||||||
@@ -36,7 +39,7 @@ services:
|
|||||||
REDIS_HOST: redis
|
REDIS_HOST: redis
|
||||||
REDIS_PORT: "6379"
|
REDIS_PORT: "6379"
|
||||||
ports:
|
ports:
|
||||||
- "9810:9800"
|
- "${API_BIND:-9810}:9800"
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
postgres:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
@@ -70,7 +73,7 @@ services:
|
|||||||
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
||||||
POSTGRES_DB: ${DB_NAME}
|
POSTGRES_DB: ${DB_NAME}
|
||||||
ports:
|
ports:
|
||||||
- "5440:5432"
|
- "${PG_BIND:-5440}:5432"
|
||||||
volumes:
|
volumes:
|
||||||
- pgdata:/var/lib/postgresql/data
|
- pgdata:/var/lib/postgresql/data
|
||||||
- ./backend/postgres-init:/docker-entrypoint-initdb.d:ro
|
- ./backend/postgres-init:/docker-entrypoint-initdb.d:ro
|
||||||
@@ -85,7 +88,7 @@ services:
|
|||||||
image: redis:7-alpine
|
image: redis:7-alpine
|
||||||
command: ["redis-server", "--appendonly", "yes"]
|
command: ["redis-server", "--appendonly", "yes"]
|
||||||
ports:
|
ports:
|
||||||
- "6390:6379"
|
- "${REDIS_BIND:-6390}:6379"
|
||||||
volumes:
|
volumes:
|
||||||
- redisdata:/data
|
- redisdata:/data
|
||||||
healthcheck:
|
healthcheck:
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# 킹서버 배포. 서버의 저장소 폴더에서 실행한다.
|
||||||
|
# ./deploy.sh main 받아서 다시 빌드·재시작
|
||||||
|
# ./deploy.sh --restore-db 덤프.dump 위 작업 후 DB 를 덤프로 덮어쓴다 (pg_dump -Fc 형식)
|
||||||
|
set -euo pipefail
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
|
[ -f .env ] || { echo ".env 가 없습니다. .env.example 을 보고 만드세요." >&2; exit 1; }
|
||||||
|
set -a; . ./.env; set +a
|
||||||
|
|
||||||
|
git pull --ff-only origin main
|
||||||
|
docker compose up -d --build postgres redis backend worker frontend
|
||||||
|
|
||||||
|
if [ "${1:-}" = "--restore-db" ]; then
|
||||||
|
dump="${2:?덤프 파일 경로가 필요합니다}"
|
||||||
|
[ -f "$dump" ] || { echo "덤프 파일이 없습니다: $dump" >&2; exit 1; }
|
||||||
|
docker compose stop backend worker
|
||||||
|
docker compose exec -T postgres pg_restore -U "$DB_USER" -d "$DB_NAME" --clean --if-exists --no-owner < "$dump"
|
||||||
|
docker compose exec -T redis redis-cli FLUSHDB
|
||||||
|
docker compose start backend worker
|
||||||
|
fi
|
||||||
|
|
||||||
|
docker compose ps
|
||||||
@@ -14,6 +14,8 @@ CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0", "--port", "5173"]
|
|||||||
|
|
||||||
# ---- build: 타입체크 후 정적 파일 생성 ----
|
# ---- build: 타입체크 후 정적 파일 생성 ----
|
||||||
FROM deps AS build
|
FROM deps AS build
|
||||||
|
ARG VITE_API_BASE_URL=""
|
||||||
|
ENV VITE_API_BASE_URL=$VITE_API_BASE_URL
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,14 @@ server {
|
|||||||
try_files $uri =404;
|
try_files $uri =404;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# API 는 같은 주소로 받아 backend 컨테이너로 넘긴다
|
||||||
|
location /v1/ {
|
||||||
|
proxy_pass http://backend:9800;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
}
|
||||||
|
|
||||||
# SPA: /indices, /sky 같은 주소로 새로고침해도 index.html을 돌려준다
|
# SPA: /indices, /sky 같은 주소로 새로고침해도 index.html을 돌려준다
|
||||||
location / {
|
location / {
|
||||||
add_header Cache-Control "no-cache";
|
add_header Cache-Control "no-cache";
|
||||||
|
|||||||
Reference in new issue
Block a user