diff --git a/.github/workflows/prod_deploy.sh b/.github/workflows/prod_deploy.sh new file mode 100644 index 0000000..f36fa3e --- /dev/null +++ b/.github/workflows/prod_deploy.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# ubuntu 권한으로 모든 명령어 실행 +sudo -u ubuntu sh < .env.local +npm install +npm run build +pm2 start pm2.config.js +EOF \ No newline at end of file diff --git a/.github/workflows/prod_deploy.yml b/.github/workflows/prod_deploy.yml index 9e23cbc..e261e10 100644 --- a/.github/workflows/prod_deploy.yml +++ b/.github/workflows/prod_deploy.yml @@ -17,8 +17,6 @@ jobs: AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_REGION: ap-northeast-2 EC2_INSTANCE_ID: ${{ secrets.FRONTEND_EC2_INSTANCE_ID }} - # Docker 관련 - CONTAINER_NAME: sulmun2yong-production-client # Next.js 관련 ENV_CONTENT: ${{ secrets.FRONTEND_PRODUCTION_ENV_CONTENT }} @@ -36,10 +34,4 @@ jobs: --document-name "AWS-RunShellScript" \ --targets "Key=instanceIds, Values=${{ env.EC2_INSTANCE_ID}}" \ --parameters '{"workingDirectory": ["/home/ubuntu/Frontend"], - "commands" : ["git pull origin main", - "echo \"${{ env.ENV_CONTENT }}\" | base64 -d > .env.local", - "docker stop ${{ env.CONTAINER_NAME }} || true", - "docker rm ${{ env.CONTAINER_NAME }} || true", - "docker build -t ${{ env.CONTAINER_NAME }}:latest . ", - "docker run -d -p 3000:3000 --name ${{ env.CONTAINER_NAME }} ${{ env.CONTAINER_NAME }}:latest", - "docker image prune -af"]}' + "commands" : ["ENV_CONTENT='${{ env.ENV_CONTENT }}' bash ./.github/workflows/prod_deploy.sh"]}' \ No newline at end of file diff --git a/dockerfile b/dockerfile deleted file mode 100644 index 15b5cf4..0000000 --- a/dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM node:18-alpine as builder -WORKDIR /app -COPY package.json package-lock.json ./ -RUN npm ci -COPY . . -RUN npm run build - -FROM node:18-alpine -WORKDIR /app -COPY --from=builder /app/next.config.mjs ./ -COPY --from=builder /app/public ./public -COPY --from=builder /app/.next ./.next -COPY --from=builder /app/node_modules ./node_modules -COPY --from=builder /app/package.json ./ -ENV PORT 3000 -EXPOSE 3000 -CMD ["npm", "start"] \ No newline at end of file diff --git a/pm2.config.js b/pm2.config.js new file mode 100644 index 0000000..80b8824 --- /dev/null +++ b/pm2.config.js @@ -0,0 +1,11 @@ +module.exports = { + apps: [ + { + name: "sulmun2yong-production-client", + script: "./node_modules/next/dist/bin/next", + args: "start", + instances: "max", + exec_mode: "cluster" + }, + ], +}; \ No newline at end of file