Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions .github/workflows/ci-cd pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: CI/CD Pipeline

# main 브랜치에 대한 Pull request 및 Merge
on:
pull_request :
branches :
pull_request:
branches:
- main
push:
branches:
Expand All @@ -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. 레포지토리 소스 코드 작업 환경으로 가져오기
Expand Down Expand Up @@ -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'
Expand All @@ -89,4 +88,4 @@ jobs:
with:
environment: production
inject: true
sourcemaps: "./dist"
sourcemaps: './dist'
19 changes: 19 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -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"]
29 changes: 7 additions & 22 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
57 changes: 33 additions & 24 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
16 changes: 13 additions & 3 deletions src/modules/auth/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@ import { Observable } from 'rxjs';

@Injectable()
export class AuthGuard implements CanActivate {
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> {
canActivate(
context: ExecutionContext,
): boolean | Promise<boolean> | Observable<boolean> {
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;
}
}
}
Loading