From f97117a2d935a7926e3f0d162092acab2b236ea4 Mon Sep 17 00:00:00 2001 From: YangGwangSeong Date: Sun, 1 Dec 2024 07:58:20 +0900 Subject: [PATCH] feat: ncp deploy init1 (#51) --- .dockerignore | 3 -- .github/workflows/main.yml | 61 ++++++++++++++++++++++++++++++++++++++ package.json | 2 ++ 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/main.yml diff --git a/.dockerignore b/.dockerignore index 0c5b13f..ad1991f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -36,6 +36,3 @@ eslint.config.mjs README.md .github -# Build configs -tsconfig.json -tsconfig.build.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..d745967 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,61 @@ +name: auto deploy + +on: + push: + branches: + - feature/51-ncp-deploy + +jobs: + push_to_registry: + name: Push to ncp container registry + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - 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: ./Dockerfile + push: true + tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/backend:latest + cache-from: type=registry,ref=${{ secrets.NCP_CONTAINER_REGISTRY }}/prv-backend:latest + cache-to: type=inline + secrets: | + GIT_AUTH_TOKEN=${{ secrets.GIT_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.DEV_HOST }} + username: ${{ secrets.DEV_USERNAME }} + password: ${{ secrets.DEV_PASSWORD }} + port: ${{ secrets.DEV_PORT }} + script: | + docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/backend + docker stop $(docker ps -a -q) + docker rm $(docker ps -a -q) + docker run -d -p 3000:80 \ + -e DB_HOST='${{ secrets.DB_HOST }}' \ + -e DB_PORT='${{ secrets.DB_PORT }}' \ + -e DB_USERNAME='${{ secrets.DB_USERNAME }}' \ + -e DB_PASSWORD='${{ secrets.DB_PASSWORD }}' \ + -e DB_DATABASE='${{ secrets.DB_DATABASE }}' \ + -e JWT_SECRET_KEY='${{ secrets.JWT_SECRET_KEY }}' \ + -e API_BASE_URL='${{ secrets.API_BASE_URL }}' \ + ${{ secrets.NCP_CONTAINER_REGISTRY }}/backend + docker image prune -f + \ No newline at end of file diff --git a/package.json b/package.json index 607b9ba..7604c73 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,11 @@ "author": "yanggwangseong", "license": "MIT", "scripts": { + "build": "nest build", "start:dev": "cross-env NODE_ENV=development nest start --watch", "test": "jest", "start:debug": "cross-env NODE_ENV=development nest start --debug --watch", + "start:prod": "cross-env NODE_ENV=production node dist/main", "---------------------------------------------": "", "eslint": "eslint src", "eslint:fix": "eslint src --fix",