From 848ca75e05cd6f740192442981336244c2a96074 Mon Sep 17 00:00:00 2001 From: GeunH Date: Sun, 3 Dec 2023 21:21:16 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20docker=EB=A5=BC=20=EC=9D=B4=EC=9A=A9?= =?UTF-8?q?=ED=95=9C=20=EC=9E=90=EB=8F=99=20=EB=B0=B0=ED=8F=AC=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20#35?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/be-autodeploy.yml | 50 +++++++++++++++++++++++++++++ be/Dockerfile | 23 +++++++++++++ be/dockerignore | 23 +++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 .github/workflows/be-autodeploy.yml create mode 100644 be/Dockerfile create mode 100644 be/dockerignore diff --git a/.github/workflows/be-autodeploy.yml b/.github/workflows/be-autodeploy.yml new file mode 100644 index 00000000..d3c30025 --- /dev/null +++ b/.github/workflows/be-autodeploy.yml @@ -0,0 +1,50 @@ +name: auto deploy + +on: + push: + branches: + - dev + +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: ./Dockerfile + push: true + tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/nibobnebob:latest + cache-from: type=registry,ref=${{ secrets.NCP_CONTAINER_REGISTRY }}/nibobnebob:latest + cache-to: type=inline + + 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 }}/nibobnebob + docker stop $(docker ps -a -q) + docker rm $(docker ps -a -q) + docker run -d -p 8000:80 ${{ secrets.NCP_CONTAINER_REGISTRY }}/nibobnebob + docker image prune -f \ No newline at end of file diff --git a/be/Dockerfile b/be/Dockerfile new file mode 100644 index 00000000..2a17d513 --- /dev/null +++ b/be/Dockerfile @@ -0,0 +1,23 @@ +# 베이스 이미지 선택 +FROM node:20 + +# 작업 디렉토리 설정 +WORKDIR /usr/src/app + +# 종속성 파일 복사 (package.json 및 package-lock.json) +COPY package*.json ./ + +# 종속성 설치 +RUN npm install + +# 애플리케이션 소스 코드 복사 +COPY . . + +# TypeScript 컴파일 +RUN npm run build + +# 애플리케이션 실행 포트 지정 +EXPOSE 8000 + +# 애플리케이션 실행 명령어 +CMD ["node", "dist/src/main"] diff --git a/be/dockerignore b/be/dockerignore new file mode 100644 index 00000000..24cdedf8 --- /dev/null +++ b/be/dockerignore @@ -0,0 +1,23 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* \ No newline at end of file