diff --git a/.github/workflows/BackEnd_CI.yml b/.github/workflows/BackEnd_CI.yml deleted file mode 100644 index 50cd3b44..00000000 --- a/.github/workflows/BackEnd_CI.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: BackEnd-CI - -on: - push: - branches: 'feature/BE/*' - pull_request: - branches: 'develop' - types: [labeled, opened, synchronize, reopened] - -jobs: - test: - if: contains(github.event.pull_request.labels.*.name, 'πŸ’»λ°±μ—”λ“œ') - runs-on: ubuntu-latest - - steps: - - name: μ½”λ“œ 체크아웃 - uses: actions/checkout@v2 - - - name: node μ„ΈνŒ… - uses: actions/setup-node@v1 - with: - node-version: '18' - - - name: μ˜μ‘΄μ„± μ„€μΉ˜ - run: npm ci - working-directory: ./BackEnd - - - name: ν…ŒμŠ€νŠΈ 진행 - run: npm test - working-directory: ./BackEnd diff --git a/.github/workflows/BackEnd_CICD.yml b/.github/workflows/BackEnd_CICD.yml new file mode 100644 index 00000000..8c2fb965 --- /dev/null +++ b/.github/workflows/BackEnd_CICD.yml @@ -0,0 +1,63 @@ +name: BackEnd-CI + +on: + push: + branches: 'feature/BE/*' + pull_request: + branches: 'develop' + types: [labeled, opened, synchronize, reopened] + +jobs: + test: + if: contains(github.event.pull_request.labels.*.name, 'πŸ’»λ°±μ—”λ“œ') + runs-on: ubuntu-latest + + steps: + - name: μ½”λ“œ 체크아웃 + uses: actions/checkout@v2 + + - name: node μ„ΈνŒ… + uses: actions/setup-node@v1 + with: + node-version: '18' + + - name: μ˜μ‘΄μ„± μ„€μΉ˜ + run: npm ci + working-directory: ./BackEnd + + - name: ν…ŒμŠ€νŠΈ 진행 + run: npm test + working-directory: ./BackEnd + + deploy: + needs: test + if: github.ref == 'refs/heads/develop' && github.event_name == 'push' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: docker/setup-buildx-action@v2 + - uses: docker/login-action@v1 + with: + registry: ${{ secrets.NCP_CONTAINER_REGISTRY }} + username: ${{ secrets.NCP_ACCESS_KEY }} + password: ${{ secrets.NCP_SECRET_KEY }} + - uses: docker/build-push-action@v2 + with: + context: . + file: ./BackEnd/Dockerfile + push: true + tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/my-app:latest + - name: SSH Tunneling and Deploy + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.BASTION_HOST }} + username: ${{ secrets.BASTION_USER }} + key: ${{ secrets.BASTION_SSH_KEY }} + script: | + ssh -o StrictHostKeyChecking=no -L 9999:${{ secrets.INTERNAL_SERVER_IP }}:22 ${{ secrets.BASTION_USER }}@localhost -i ${{ secrets.BASTION_SSH_PRIVATE_KEY_PATH }} -fN + ssh -o StrictHostKeyChecking=no -p 9999 ${{ secrets.SERVER_USER }}@localhost -i ${{ secrets.SERVER_SSH_PRIVATE_KEY_PATH }} ' + docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/my-app:latest + docker stop my-app || true + docker rm my-app || true + docker run --name my-app -d -p 3000:3000 --env-file /var/env/.env ${{ secrets.NCP_CONTAINER_REGISTRY }}/my-app:latest + ' \ No newline at end of file diff --git a/BackEnd/Dockerfile b/BackEnd/Dockerfile new file mode 100644 index 00000000..3139c2d3 --- /dev/null +++ b/BackEnd/Dockerfile @@ -0,0 +1,17 @@ +# λΉŒλ“œ 단계 +FROM node:18 AS builder +WORKDIR /app +COPY BackEnd/package*.json ./ +RUN npm install +COPY BackEnd/ . +RUN npm run build + +# μ‹€ν–‰ 단계 +FROM node:18 +WORKDIR /app +COPY --from=builder /app/dist ./dist +COPY --from=builder /app/package*.json ./ +RUN npm install --only=production +RUN npm install pm2 -g +EXPOSE 3000 +CMD ["pm2-runtime", "start", "dist/main.js"]