diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml new file mode 100644 index 00000000..a1738a65 --- /dev/null +++ b/.github/workflows/deploy-prod.yml @@ -0,0 +1,64 @@ +name: Front Production Server (main) + +on: + push: + branches: + - main # main 브랜치에 push가 발생하면 실행 + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup SSH + run: | + mkdir -p ~/.ssh + echo "${{ secrets.LIGHTSAIL_PROD_SSH_KEY }}" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 + ssh-keyscan -H ${{ secrets.LIGHTSAIL_PROD_HOST }} >> ~/.ssh/known_hosts + echo "SSH 설정 완료" + + - name: Deploy to server + run: | + ssh -i ~/.ssh/id_ed25519 ${{ secrets.LIGHTSAIL_PROD_USER }}@${{ secrets.LIGHTSAIL_PROD_HOST }} << EOF + + # 용량 확보를 위해 도커 컨테이너, 이미지 먼저 정리 + echo "사용하지 않는 컨테이너, 이미지, 네트워크 정리 중 (볼륨제외)..." + sudo docker system prune -a -f + + # 디렉토리 없으면 생성 + if [ ! -d "$HOME/front/study-platform-client-prod" ]; then + mkdir -p "$HOME/front/study-platform-client-prod" + echo "디렉토리 생성 완료" + fi + + cd ~/front/study-platform-client-prod + + # git 저장소 없으면 clone, 있으면 fetch + reset (덮어쓰기) + if [ ! -d ".git" ]; then + git clone git@github.com:code-zero-to-one/study-platform-client.git . + echo "Git clone 완료" + else + git fetch origin + git reset --hard origin/main + echo "Git fetch & reset 완료" + fi + + git fetch origin + git checkout main + git pull origin main + + echo ".env 파일 생성" + echo "NEXT_PUBLIC_API_BASE_URL=${{ secrets.NEXT_PUBLIC_API_PROD_BASE_URL }}" > .env + echo "NEXT_PUBLIC_GTM_ID=${{ secrets.NEXT_PUBLIC_GTM_ID }}" >> .env + + echo "도커 컴포즈 재시작" + sudo docker stop study-platform-client-prod-frontend-1 + sudo docker rm study-platform-client-prod-frontend-1 + sudo docker compose up -d --build + + echo "운영 서버 배포 완료" + EOF diff --git a/.github/workflows/deploy-prod.yml.disabled b/.github/workflows/deploy-prod.yml.disabled deleted file mode 100644 index e65f3685..00000000 --- a/.github/workflows/deploy-prod.yml.disabled +++ /dev/null @@ -1,42 +0,0 @@ -name: Front Production Server (main) - -on: - push: - branches: - - main # main 브랜치에 push가 발생하면 실행 - -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Setup SSH - run: | - mkdir -p ~/.ssh - echo "${{ secrets.LIGHTSAIL_SSH_KEY }}" > ~/.ssh/id_ed25519 - chmod 600 ~/.ssh/id_ed25519 - ssh-keyscan -H ${{ secrets.LIGHTSAIL_HOST }} >> ~/.ssh/known_hosts - echo "SSH 설정 완료" - - - name: Deploy to server - run: | - ssh -i ~/.ssh/id_ed25519 ${{ secrets.LIGHTSAIL_USER }}@${{ secrets.LIGHTSAIL_HOST }} << 'EOF' - cd ~/study-platform-client-prod - - git fetch origin - git checkout main - git pull origin main - - echo "패키지 설치 중" - yarn install - echo "빌드 진행 중" - yarn build - - pm2 delete front-server-prod || true - pm2 start ecosystem.config.js - - echo "운영 서버 배포 완료" - EOF diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..512be29b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +# 운영환경(main branch)에서 사용하는 Dockerfile + +# 1단계: build +FROM node:18-alpine AS builder +WORKDIR /app + +COPY . . + +# 빌드시점에 .env 파일 복사 +COPY .env .env + +RUN yarn install && yarn build + +# 2단계: production +FROM node:18-alpine AS runner +WORKDIR /app + +ENV NODE_ENV=production + +COPY --from=builder /app/.next ./.next +COPY --from=builder /app/public ./public +COPY --from=builder /app/package.json ./package.json +COPY --from=builder /app/yarn.lock ./yarn.lock + +# 런타임시점에도 .env 파일 복사 +COPY --from=builder /app/.env .env + +# devDependencies는 설치하지 않고 dependencies만 설치 +RUN yarn install --production + +EXPOSE 3000 + +CMD ["yarn", "start"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..cc9783e1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +# 운영환경(main branch)에서 사용하는 docker-compose.yml + +version: '3.8' + +services: + frontend: + build: + context: . + dockerfile: Dockerfile + ports: + - '3000:3000' + env_file: + - .env + restart: unless-stopped \ No newline at end of file diff --git a/src/features/auth/ui/login-modal.tsx b/src/features/auth/ui/login-modal.tsx index ae38e734..9b1fd99e 100644 --- a/src/features/auth/ui/login-modal.tsx +++ b/src/features/auth/ui/login-modal.tsx @@ -25,8 +25,8 @@ export default function LoginModal({ // TODO : 실제 백엔드에서 제공하는 URL로 교체필요 const NAVER_LOGIN_URL = ''; - const KAKAO_LOGIN_URL = `https://kauth.kakao.com/oauth/authorize?client_id=3194796599a4325c0223d154319351a4&redirect_uri=https://test-api.zeroone.it.kr/api/v1/auth/kakao/redirect-uri&response_type=code&state=${state}`; - const GOOGLE_LOGIN_URL = `https://accounts.google.com/o/oauth2/v2/auth?scope=openid%20profile&access_type=offline&prompt=consent&include_granted_scopes=true&response_type=code&redirect_uri=https://test-api.zeroone.it.kr/api/v1/auth/google/redirect-uri&client_id=616205933420-b45d510q23togkaqo069j8igmsjhp9v0.apps.googleusercontent.com&state=${state}`; + const KAKAO_LOGIN_URL = `https://kauth.kakao.com/oauth/authorize?client_id=3194796599a4325c0223d154319351a4&redirect_uri=${process.env.NEXT_PUBLIC_API_BASE_URL}/api/v1/auth/kakao/redirect-uri&response_type=code&state=${state}`; + const GOOGLE_LOGIN_URL = `https://accounts.google.com/o/oauth2/v2/auth?scope=openid%20profile&access_type=offline&prompt=consent&include_granted_scopes=true&response_type=code&redirect_uri=${process.env.NEXT_PUBLIC_API_BASE_URL}/api/v1/auth/google/redirect-uri&client_id=616205933420-b45d510q23togkaqo069j8igmsjhp9v0.apps.googleusercontent.com&state=${state}`; return (