diff --git a/.github/workflows/backend-deploy.yml b/.github/workflows/backend-deploy.yml new file mode 100644 index 0000000..6e566fb --- /dev/null +++ b/.github/workflows/backend-deploy.yml @@ -0,0 +1,51 @@ +name: 🍀 Deploy to Naver Cloud Platform +on: + push: + branches: + - release # Only in release branch + +jobs: + push_to_registry: + name: Push to ncp container registry + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to NCP Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ secrets.NCP_CONTAINER_REGISTRY }} + username: ${{ secrets.NCP_ACCESS_KEY }} + password: ${{ secrets.NCP_SECRET_KEY }} + - name: build and push + uses: docker/build-push-action@v3 + with: + context: . + file: ./backend/Dockerfile + push: true + tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/server:latest + cache-from: type=registry,ref=${{ secrets.NCP_CONTAINER_REGISTRY }}/server:latest + cache-to: type=inline + secrets: | + GIT_AUTH_TOKEN=${{ secrets.GITHUB_TOKEN }} + + pull_from_registry: + name: Connect server ssh and pull from container registry + needs: push_to_registry + runs-on: ubuntu-latest + steps: + - name: connect ssh + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USERNAME }} + password: ${{ secrets.SERVER_PASSWORD }} + port: ${{ secrets.SERVER_PORT }} + script: | + docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/server + docker stop $(docker ps -a -q) + docker rm $(docker ps -a -q) + docker run -d -p 80:3000 --env-file ${{ secrets.ENV_FILE }} ${{ secrets.NCP_CONTAINER_REGISTRY }}/server + docker image prune -f diff --git a/.github/workflows/backend-eslint-ci.yml b/.github/workflows/backend-eslint-ci.yml new file mode 100644 index 0000000..eb5e4ee --- /dev/null +++ b/.github/workflows/backend-eslint-ci.yml @@ -0,0 +1,20 @@ +name: ESLint Check +on: + pull_request: + paths: + - backend/** +jobs: + eslint: + name: runner / eslint + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + steps: + - uses: actions/checkout@v4 + - uses: reviewdog/action-eslint@v1 + with: + eslint_flags: "src/" + filter_mode: file + workdir: "backend" + fail_on_error: true diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..4e08f4a --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,15 @@ +FROM node:lts-alpine + +WORKDIR /usr/src/app + +COPY ./backend/package*.json ./ + +RUN npm install + +COPY ./backend/. . + +RUN npm run build + +EXPOSE 3000 + +CMD ["npm", "start"]