From caae0a6815575861a6490793944abd137e940d96 Mon Sep 17 00:00:00 2001 From: kyy Date: Tue, 13 Jan 2026 16:38:59 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B0=B0=ED=8F=AC=EC=9A=A9=20Docker=20compose?= =?UTF-8?q?=20=EB=B0=8F=20=EA=B0=80=EC=9D=B4=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/.env.sample | 39 ++++++++++++++++++ docker/Dockerfile.backend | 33 +++++++++++++++ docker/Dockerfile.frontend | 34 ++++++++++++++++ docker/README.md | 67 +++++++++++++++++++++++++++++++ docker/docker-compose.deploy.yaml | 46 +++++++++++++++++++++ 5 files changed, 219 insertions(+) create mode 100644 docker/.env.sample create mode 100644 docker/Dockerfile.backend create mode 100644 docker/Dockerfile.frontend create mode 100644 docker/README.md create mode 100644 docker/docker-compose.deploy.yaml diff --git a/docker/.env.sample b/docker/.env.sample new file mode 100644 index 00000000..051ac575 --- /dev/null +++ b/docker/.env.sample @@ -0,0 +1,39 @@ +# ========================================== +# Baron SSO - Unified Environment Configuration +# ========================================== + +# --- General System --- +APP_ENV=development +TZ=Asia/Seoul + +# --- Infrastructure Ports --- +DB_PORT=5432 +CLICKHOUSE_PORT_HTTP=8123 +CLICKHOUSE_PORT_NATIVE=9000 +BACKEND_PORT=3000 +FRONTEND_PORT=5000 + +# --- Database Credentials (PostgreSQL) --- +DB_USER=baron +DB_PASSWORD=password +DB_NAME=baron_sso + +# --- Backend Configuration --- +# Must be 32 bytes. Generate with `openssl rand -hex 32` +COOKIE_SECRET=super-secret-key-must-be-32-bytes! +REDIS_ADDR=redis:6379 + +# --- Frontend Configuration --- +# Descope Project ID (Required for Auth) +DESCOPE_PROJECT_ID=P2t...your_descope_project_id +DESCOPE_MANAGEMENT_KEY=your_descope_management_key_here + +# --- Naver Cloud Services --- +NAVER_CLOUD_ACCESS_KEY=ncp_iam_... +NAVER_CLOUD_SECRET_KEY=ncp_iam_... +NAVER_CLOUD_SERVICE_ID=ncp:sms:kr:...:... +NAVER_SENDER_PHONE_NUMBER=... + +# --- URLs for Proxy/Handoff --- +FRONTEND_URL=http://localhost:5000 +BACKEND_URL=http://localhost:3000 \ No newline at end of file diff --git a/docker/Dockerfile.backend b/docker/Dockerfile.backend new file mode 100644 index 00000000..b4d6c5ca --- /dev/null +++ b/docker/Dockerfile.backend @@ -0,0 +1,33 @@ +# 1단계: Go 애플리케이션 빌드 +# 개발 환경과 일치하는 특정 Go 버전 사용 +FROM golang:1.25-alpine AS builder + +# 컨테이너 내부의 현재 작업 디렉토리 설정 +WORKDIR /app + +# go.mod 및 go.sum 파일 복사 +COPY backend/go.mod backend/go.sum ./ + +# 모든 종속성 다운로드. go.mod 및 go.sum 파일이 변경되지 않으면 종속성은 캐시됩니다. +RUN go mod download + +# 소스 코드 복사 +COPY backend/ . + +# Go 앱 빌드 +# -ldflags="-w -s"는 디버그 정보를 제거하여 바이너리 크기를 줄입니다. +# CGO_ENABLED=0은 정적 빌드를 위해 CGO를 비활성화합니다. +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o /go/bin/server ./cmd/server + +# 2단계: 최종 경량 이미지 생성 +# 더 작고 안전한 환경을 위해 distroless 이미지 사용 +FROM gcr.io/distroless/static-debian11 + +# 빌더 스테이지에서 빌드된 실행 파일만 복사 +COPY --from=builder /go/bin/server / + +# 외부 세계에 3000번 포트 노출 +EXPOSE 3000 + +# 실행 파일을 실행하는 명령어 +ENTRYPOINT ["/server"] diff --git a/docker/Dockerfile.frontend b/docker/Dockerfile.frontend new file mode 100644 index 00000000..a4b7534f --- /dev/null +++ b/docker/Dockerfile.frontend @@ -0,0 +1,34 @@ +# 1단계: Flutter 웹 애플리케이션 빌드 +# 신뢰할 수 있는 출처의 특정 Flutter 버전 사용 +FROM ghcr.io/cirruslabs/flutter:stable AS builder + +WORKDIR /app + +# Docker 캐시를 활용하기 위해 pubspec 파일들을 먼저 복사 +COPY frontend/pubspec.yaml frontend/pubspec.lock ./ +RUN flutter pub get + +# 나머지 프론트엔드 소스 코드 복사 +COPY frontend/ . + +# 웹 애플리케이션 빌드 +RUN flutter build web --release + +# 2단계: 빌드된 파일들을 Nginx로 서빙 +# 경량의 공식 Nginx 이미지 사용 +FROM nginx:1.27-alpine + +# 기본 Nginx 설정 파일 제거 +RUN rm /etc/nginx/conf.d/default.conf + +# 사용자 정의 Nginx 설정 (선택 사항이지만 라우팅 등을 위해 권장) +COPY frontend/nginx.conf /etc/nginx/conf.d/default.conf + +# 빌더 스테이지에서 빌드된 웹 파일들을 복사 +COPY --from=builder /app/build/web /usr/share/nginx/html + +# Nginx 서버를 위해 80번 포트 노출 +EXPOSE 80 + +# Nginx를 포그라운드에서 시작 +CMD ["nginx", "-g", "daemon off;"] diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000..bebf3c08 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,67 @@ +# Docker 이미지 빌드 및 배포 가이드 + +이 문서는 Baron SSO 애플리케이션의 Backend와 Frontend Docker 이미지를 빌드하고, Private Registry에 푸시한 뒤, 서버에 배포하는 과정을 안내합니다. + +--- + +### 1. Docker 이미지 빌드 및 태그 + +Backend와 Frontend 애플리케이션을 각각의 Dockerfile을 사용하여 빌드하고, 레지스트리에 푸시할 수 있도록 이미지에 태그를 지정합니다. + +**주의:** 아래 모든 명령어는 **프로젝트 최상위 루트 디렉토리**에서 실행해야 합니다. + +```bash +# Backend 이미지 빌드 +# v1.2601.1-RC1 부분은 실제 배포 버전에 맞게 수정하세요. +docker build -t reg.hmac.kr/baron_sso/backend:v1.2601.1-RC1 -f docker/Dockerfile.backend . + +# Frontend 이미지 빌드 +docker build -t reg.hmac.kr/baron_sso/frontend:v1.2601.1-RC1 -f docker/Dockerfile.frontend . +``` + +--- + +### 2. Private 레지스트리 로그인 + +빌드한 이미지를 푸시하기 위해 Private Docker Registry(`reg.hmac.kr`)에 로그인합니다. +최초 한 번만 인증하면 이후에는 로그인 과정이 필요 없을 수 있습니다. + +```bash +docker login reg.hmac.kr +``` + +--- + +### 3. Docker 이미지 푸시 + +로컬에 빌드된 두 이미지를 Private Registry로 업로드합니다. +이 과정을 통해 배포 서버에서 해당 이미지를 내려받을 수 있게 됩니다. + +```bash +# Backend 이미지 푸시 +docker push reg.hmac.kr/baron_sso/backend:v1.2601.1-RC1 + +# Frontend 이미지 푸시 +docker push reg.hmac.kr/baron_sso/frontend:v1.2601.1-RC1 +``` + +--- + +### 4. 서버 배포 및 서비스 실행 + +배포 서버에서 `docker-compose.deploy.yaml` 파일을 사용하여 이미지를 내려받고 컨테이너를 실행합니다. +로컬 테스트 시에는 `compose.infra.yaml`을 함께 사용하여 전체 인프라를 구동할 수 있습니다. + +```bash +# 로컬 환경에서 전체 서비스(인프라 포함) 실행 +# -d 옵션은 컨테이너를 백그라운드에서 실행합니다. +docker compose -f docker/docker-compose.deploy.yaml -f docker/compose.infra.yaml up -d +``` + +### 서비스 중지 + +실행 중인 모든 서비스를 중지하고 컨테이너를 삭제하려면 아래 명령어를 사용합니다. + +```bash +docker compose -f docker/docker-compose.deploy.yaml -f docker/compose.infra.yaml down +``` diff --git a/docker/docker-compose.deploy.yaml b/docker/docker-compose.deploy.yaml new file mode 100644 index 00000000..48b4671e --- /dev/null +++ b/docker/docker-compose.deploy.yaml @@ -0,0 +1,46 @@ +name: baron-sso + +services: + backend: + image: reg.hmac.kr/baron_sso/backend:v1.2601.1-RC1 + container_name: baron_backend + restart: unless-stopped + env_file: + - .env + environment: + - APP_ENV=${APP_ENV:-production} + - APP_ENV=production + - COOKIE_SECRET=${COOKIE_SECRET} + - DB_HOST=postgres + - CLICKHOUSE_HOST=clickhouse + - CLICKHOUSE_PORT=${CLICKHOUSE_PORT_NATIVE:-9000} + - CLICKHOUSE_USER=${CLICKHOUSE_USER:-baron} + - CLICKHOUSE_PASSWORD=${CLICKHOUSE_PASSWORD:-password} + ports: + - "${BACKEND_PORT:-3000}:3000" + depends_on: + - infra_check + networks: + - baron_net + + frontend: + image: reg.hmac.kr/baron_sso/frontend:v1.2601.1-RC1 + container_name: baron_frontend + restart: unless-stopped + ports: + - "${FRONTEND_PORT:-80}:80" + depends_on: + - backend + networks: + - baron_net + + infra_check: + image: alpine + command: ["echo", "Infrastructure assumed running"] + networks: + - baron_net + +networks: + baron_net: + external: true + name: baron_network