diff --git a/.github/workflows/ci-cd pipeline.yml b/.github/workflows/ci-cd pipeline.yml index 7b3e458..b264203 100644 --- a/.github/workflows/ci-cd pipeline.yml +++ b/.github/workflows/ci-cd pipeline.yml @@ -2,8 +2,8 @@ name: CI/CD Pipeline # main 브랜치에 대한 Pull request 및 Merge on: - pull_request : - branches : + pull_request: + branches: - main push: branches: @@ -13,11 +13,11 @@ on: jobs: build: runs-on: ubuntu-latest - - permissions : - id-token : write - contents : read - pull-requests : write + + permissions: + id-token: write + contents: read + pull-requests: write steps: # 1. 레포지토리 소스 코드 작업 환경으로 가져오기 @@ -67,11 +67,10 @@ jobs: command: | mkdir ./${{ github.repository }} cd ./${{ github.repository }} - ls -al sudo curl -o docker-compose.yml https://raw.githubusercontent.com/${{ github.repository }}/main/docker-compose.yml - sudo docker-compose down - sudo docker-compose up -d ${{ secrets.DOCKER_IMAGE_NAME }} - sudo docker image prune -a -f + cd ../DevOps + chmod 777 ./deploy-node.sh + ./deploy-node.sh # Example of using the output - id: 'debug' @@ -89,4 +88,4 @@ jobs: with: environment: production inject: true - sourcemaps: "./dist" + sourcemaps: './dist' diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..344b532 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,19 @@ +FROM node:20-slim AS base +ENV PNPM_HOME="/pnpm" +ENV PATH="$PNPM_HOME:$PATH" +RUN npm install -g corepack@latest +RUN corepack enable +COPY . /app +WORKDIR /app + +FROM base AS prod-deps +RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile + +FROM base AS build +RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile +RUN pnpm run build + +FROM base +COPY --from=prod-deps /app/node_modules /app/node_modules +COPY --from=build /app/dist /app/dist +CMD [ "pnpm", "start:dev"] \ No newline at end of file diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 3299302..ec4a735 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -1,38 +1,23 @@ x-defaults: &common-settings - image: dongho18/connect-gnu-node:latest - pull_policy: always - restart: always + build: + context: . + dockerfile: Dockerfile.dev # 개발 환경 도커파일 마운트 + volumes: + - ./.env.dev:/app/.env # 개발 환경 변수 마운트 networks: - connect-gnu-network - environment: - TZ: 'Asia/Seoul' - SLACK_WEBHOOK: ${SLACK_WEBHOOK} - SENTRY_NODE_DSN: ${SENTRY_NODE_DSN} - DB_HOST: ${DB_HOST} - DB_PORT: ${DB_PORT} - DB_USERNAME: ${DB_USERNAME} - DB_PASSWORD: ${DB_PASSWORD} - DB_DATABASE: ${DB_DATABASE} - deploy: - resources: - limits: - memory: 256m - cpus: '0.25' - reservations: - memory: 128m - cpus: '0.1' services: connect-gnu-node-blue: <<: *common-settings container_name: connect-gnu-node-blue ports: - - '5200:5200' + - '5200:5001' connect-gnu-node-green: <<: *common-settings container_name: connect-gnu-node-green ports: - - '5201:5200' + - '5201:5001' networks: connect-gnu-network: diff --git a/docker-compose.yml b/docker-compose.yml index 2cdf0fe..64eeea8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,30 +1,39 @@ +x-defaults: &common-settings + image: dongho18/connect-gnu-node:latest + pull_policy: always + restart: always + networks: + - connect-gnu-network + environment: + TZ: 'Asia/Seoul' + SLACK_WEBHOOK: ${SLACK_WEBHOOK} + SENTRY_NODE_DSN: ${SENTRY_NODE_DSN} + DB_HOST: ${DB_HOST} + DB_PORT: ${DB_PORT} + DB_USERNAME: ${DB_USERNAME} + DB_PASSWORD: ${DB_PASSWORD} + DB_DATABASE: ${DB_DATABASE} + deploy: + resources: + limits: + memory: 256m + cpus: '0.25' + reservations: + memory: 128m + cpus: '0.1' + services: - connect-gnu-node: - image: dongho18/connect-gnu-node:latest - pull_policy: always - container_name: connect-gnu-node - restart: always - networks: - - connect-gnu-network + connect-gnu-node-blue: + <<: *common-settings + container_name: connect-gnu-node-blue ports: - '5200:5200' - environment: - TZ: 'Asia/Seoul' - SLACK_WEBHOOK: ${SLACK_WEBHOOK} - SENTRY_NODE_DSN: ${SENTRY_NODE_DSN} - DB_HOST: ${DB_HOST} - DB_PORT: ${DB_PORT} - DB_USERNAME: ${DB_USERNAME} - DB_PASSWORD: ${DB_PASSWORD} - DB_DATABASE: ${DB_DATABASE} - deploy: - resources: - limits: - memory: 256m - cpus: '0.25' - reservations: - memory: 128m - cpus: '0.1' + + connect-gnu-node-green: + <<: *common-settings + container_name: connect-gnu-node-green + ports: + - '5201:5200' networks: connect-gnu-network: diff --git a/src/modules/auth/auth.guard.ts b/src/modules/auth/auth.guard.ts index 165bfa0..4cca930 100644 --- a/src/modules/auth/auth.guard.ts +++ b/src/modules/auth/auth.guard.ts @@ -3,13 +3,23 @@ import { Observable } from 'rxjs'; @Injectable() export class AuthGuard implements CanActivate { - canActivate(context: ExecutionContext): boolean | Promise | Observable { + canActivate( + context: ExecutionContext, + ): boolean | Promise | Observable { const request = context.switchToHttp().getRequest(); - const userId = request.headers['x-user-id'] || request.body.userRequest.user?.id; + const path = request.url; + + // health check 엔드포인트는 인증 제외 + if (path === '/api/node/health') { + return true; + } + + const userId = + request.headers['x-user-id'] || request.body.userRequest.user?.id; if (userId) { request['userId'] = userId; } return !!userId; } -} \ No newline at end of file +}