From e462604a8f8aeaa9b88a38f15cb5aa308693d5df Mon Sep 17 00:00:00 2001 From: pyo-sh Date: Wed, 5 Jul 2023 14:34:08 +0900 Subject: [PATCH 1/5] =?UTF-8?q?chore:=20Docker=20Build=20=ED=95=A0=20?= =?UTF-8?q?=EC=88=98=20=EC=9E=88=EB=8A=94=20=ED=8C=8C=EC=9D=BC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=ED=95=98=EA=B8=B0=20(#75)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 4 ++++ Dockerfile | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..671d42d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +node_modules +/.git +/.github +/dist \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..da3e556 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM node AS build + +WORKDIR /app + +COPY ["package.json", "package-lock.json", "./"] +RUN ["npm", "install"] + +COPY ["tsconfig.build.json", "tsconfig.json", "./"] +COPY ["nest-cli.json", "./"] +COPY ["src/", "./src/"] +COPY [".env", "./"] +RUN ["npm", "run", "build"] + +RUN ["/bin/sh", "-c", "find . ! -name dist ! -name node_modules ! -name .env -maxdepth 1 -mindepth 1 -exec rm -rf {} \\;"] + +FROM node + +WORKDIR /app + +COPY --from=build /app . + +ENV NODE_ENV production +EXPOSE 4000/tcp + +ENTRYPOINT ["node", "./dist/main"] \ No newline at end of file From 1d14dde150e6939f8cd6798d1669ccafa241ef76 Mon Sep 17 00:00:00 2001 From: pyo-sh Date: Wed, 5 Jul 2023 14:34:31 +0900 Subject: [PATCH 2/5] =?UTF-8?q?chore:=20=EC=9E=90=EB=8F=99=20=EB=B0=B0?= =?UTF-8?q?=ED=8F=AC=EB=A5=BC=20=ED=95=98=EB=8A=94=20deploy.yml=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#75)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 81 ++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..61d4be9 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,81 @@ +name: deploy + +on: + push: + branches: [deploy] + pull_request: + branches: [deploy] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Create .env file + run: | + jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env + env: + SECRETS_CONTEXT: ${{ toJson(secrets) }} + + - name: Docker Hub Login + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{secrets.DOCKER_HUB_TOKEN}} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ secrets.DOCKER_HUB_NAMESPACE }}/${{ secrets.DOCKER_HUB_REPO }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + push: true + platforms: ${{ vars.DOCKER_SERVER_PLATFORM }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + deploy: + needs: build + runs-on: self-hosted + + steps: + - name: Docker Hub Login + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{secrets.DOCKER_HUB_TOKEN}} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ secrets.DOCKER_HUB_NAMESPACE }}/${{ secrets.DOCKER_HUB_REPO }} + + - name: test + run: echo ${{ steps.meta.outputs.tags }} + + - name: Stop docker container + run: | + docker stop plandar-server-container + docker rm plandar-server-container + + - name: Delete docker images + env: + NAME: ${{ secrets.DOCKER_HUB_NAMESPACE }} + REPO: ${{ secrets.DOCKER_HUB_REPO }} + run: docker images | grep $NAME/$REPO | tr -s ' ' | cut -d ' ' -f 2 | xargs -I {} docker rmi $NAME/$REPO:{} + + - name: Pull docker image + run: docker pull ${{ steps.meta.outputs.tags }} + + - name: Run docker container + run: docker run --name plandar-server -p 4000:4000 -d --link plandar-db-container ${{ steps.meta.outputs.tags }} From 21b19d8256b5e5e6bc164fafe42accea52f676e1 Mon Sep 17 00:00:00 2001 From: pyo-sh Date: Wed, 5 Jul 2023 15:07:24 +0900 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20Build=20=EB=8B=A8=EA=B3=84=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=82=AC=EC=9A=A9=ED=96=88=EB=8D=98=20tag=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=EC=9D=84=20deploy=20=EB=8B=A8=EA=B3=84?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=82=AC=EC=9A=A9=ED=95=A0=20=EC=88=98=20?= =?UTF-8?q?=EC=9E=88=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD=20(#75)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 61d4be9..9d2a9a3 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -9,6 +9,8 @@ on: jobs: build: runs-on: ubuntu-latest + outputs: + tags: ${{ steps.meta.outputs.tags }} steps: - uses: actions/checkout@v2 @@ -48,21 +50,6 @@ jobs: runs-on: self-hosted steps: - - name: Docker Hub Login - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_HUB_USERNAME }} - password: ${{secrets.DOCKER_HUB_TOKEN}} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v4 - with: - images: ${{ secrets.DOCKER_HUB_NAMESPACE }}/${{ secrets.DOCKER_HUB_REPO }} - - - name: test - run: echo ${{ steps.meta.outputs.tags }} - - name: Stop docker container run: | docker stop plandar-server-container @@ -75,7 +62,7 @@ jobs: run: docker images | grep $NAME/$REPO | tr -s ' ' | cut -d ' ' -f 2 | xargs -I {} docker rmi $NAME/$REPO:{} - name: Pull docker image - run: docker pull ${{ steps.meta.outputs.tags }} + run: docker pull ${{ needs.build.outputs.tags }} - name: Run docker container - run: docker run --name plandar-server -p 4000:4000 -d --link plandar-db-container ${{ steps.meta.outputs.tags }} + run: docker run --name plandar-server -p 4000:4000 -d --link plandar-db-container ${{ needs.build.outputs.tags }} From 715984bb670a54d3148127a134d52aea7928a4ec Mon Sep 17 00:00:00 2001 From: pyo-sh Date: Wed, 5 Jul 2023 15:26:49 +0900 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20Env=20secret=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=95=B4=20outputs=EB=A5=BC=20=EB=AA=BB=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EB=8D=98=20=EB=B2=84=EA=B7=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#75)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9d2a9a3..07ebc09 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -10,7 +10,7 @@ jobs: build: runs-on: ubuntu-latest outputs: - tags: ${{ steps.meta.outputs.tags }} + version: ${{ steps.meta.outputs.version }} steps: - uses: actions/checkout@v2 @@ -62,7 +62,15 @@ jobs: run: docker images | grep $NAME/$REPO | tr -s ' ' | cut -d ' ' -f 2 | xargs -I {} docker rmi $NAME/$REPO:{} - name: Pull docker image - run: docker pull ${{ needs.build.outputs.tags }} + env: + NAME: ${{ secrets.DOCKER_HUB_NAMESPACE }} + REPO: ${{ secrets.DOCKER_HUB_REPO }} + VERS: ${{ needs.build.outputs.version }} + run: docker pull $NAME/$REPO:$VERS - name: Run docker container - run: docker run --name plandar-server -p 4000:4000 -d --link plandar-db-container ${{ needs.build.outputs.tags }} + env: + NAME: ${{ secrets.DOCKER_HUB_NAMESPACE }} + REPO: ${{ secrets.DOCKER_HUB_REPO }} + VERS: ${{ needs.build.outputs.version }} + run: docker run --name plandar-server-container -p 4000:4000 -d --link plandar-db-container $NAME/$REPO:$VERS From 9209eb507ad08f0cd4e8911d4bee288a568146bc Mon Sep 17 00:00:00 2001 From: pyo-sh Date: Wed, 5 Jul 2023 15:31:05 +0900 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20=EC=8B=A4=ED=96=89=EB=90=98=EB=8A=94?= =?UTF-8?q?=20Container=EA=B0=80=20=EC=97=86=EC=96=B4=EB=8F=84=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89=EB=90=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD=20(#7?= =?UTF-8?q?5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 07ebc09..d843cdc 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -51,11 +51,13 @@ jobs: steps: - name: Stop docker container + continue-on-error: true run: | docker stop plandar-server-container docker rm plandar-server-container - name: Delete docker images + continue-on-error: true env: NAME: ${{ secrets.DOCKER_HUB_NAMESPACE }} REPO: ${{ secrets.DOCKER_HUB_REPO }}