From 66cee2e19e36102b20abb9cf80985e969957b003 Mon Sep 17 00:00:00 2001 From: jokj624 Date: Sun, 1 Sep 2024 16:44:45 +0900 Subject: [PATCH 1/7] =?UTF-8?q?build(dockerfile):=20port=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dockerfile.dev | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dockerfile.dev b/dockerfile.dev index 1d2d86b..5c0f144 100644 --- a/dockerfile.dev +++ b/dockerfile.dev @@ -16,7 +16,7 @@ COPY . . RUN ls -a && yarn build # run node prune - 사용하지 않는 모듈 제거 -RUN /usr/local/bin/node-prune +# RUN /usr/local/bin/node-prune FROM node:20-alpine @@ -25,10 +25,10 @@ COPY --from=dev /usr/src/app/dist/ ./dist/ COPY --from=dev /usr/src/app/node_modules/ ./node_modules/ # port 설정 -EXPOSE 3000 +EXPOSE 8081 # 환경 변수 설정 ENV NODE_ENV=development # start -CMD ["node", "dist/src/main.js"] \ No newline at end of file +CMD ["node", "dist/main.js"] \ No newline at end of file From a34975eb8c66dc9c295a03ad969e5ec4ab3b51a3 Mon Sep 17 00:00:00 2001 From: jokj624 Date: Sun, 1 Sep 2024 16:44:56 +0900 Subject: [PATCH 2/7] =?UTF-8?q?build(dev):=20dev=20=EB=B0=B0=ED=8F=AC=20wo?= =?UTF-8?q?rkflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dev.yml | 98 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 .github/workflows/dev.yml diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 0000000..ddee080 --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,98 @@ +name: fogfog-server-dev + +on: + push: + branches: [feature/83] + +jobs: + build: + env: + # PORT: ${{ secrets.PORT }} + # MONGODB_URI_DEV: ${{ secrets.MONGODB_URI_DEV }} + # MONGODB_URI_PROD: ${{ secrets.MONGODB_URI_PROD }} + # REGION: ${{ secrets.REGION }} + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [20.x] + + steps: + - uses: actions/checkout@v2 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + + - name: Create .env file + run: | + touch .env + echo PORT=8081 >> .env + echo DATABASE_URL=${{ secrets.DATABASE_URL }} >> .env + echo SENTRY_WEBHOOK_URL=${{ secrets.SENTRY_WEBHOOK_URL }} >> .env + echo SENTRY_DSN=${{ secrets.SENTRY_DSN }} >> .env + echo KAKAO_CLIENT_ID=${{ secrets.KAKAO_CLIENT_ID }} >> .env + echo KAKAO_REDIRECT_URL=${{ secrets.KAKAO_REDIRECT_URL }} >> .env + echo KAKAO_ADMIN_KEY=${{ secrets.KAKAO_ADMIN_KEY }} >> .env + echo ACCESS_TOKEN_SECRET=${{ secrets.ACCESS_TOKEN_SECRET }} >> .env + echo REFRESH_TOKEN_SECRET=${{ secrets.REFRESH_TOKEN_SECRET }} >> .env + echo DEFAULT_IMAGE=${{ secrets.DEFAULT_IMAGE }} >> .env + echo APPLE_CLIENTID=${{ secrets.APPLE_CLIENTID }} >> .env + echo APPLE_TEAMID=${{ secrets.APPLE_TEAMID }} >> .env + echo APPLE_KEYFILE_PATH=${{ secrets.APPLE_KEYFILE_PATH }} >> .env + echo APPLE_KEYID=${{ secrets.APPLE_KEYID }} >> .env + cat .env + + - name: Install dependencies + run: yarn + - name: Run build + run: yarn build + + - name: Create apple .p8 + run: | + cd dist + touch ${{ secrets.APPLE_KEYFILE_PATH }} + echo "${{ secrets.APPLE_PRIVATE_KEY }}" > ${{ secrets.APPLE_KEYFILE_PATH }} + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{secrets.DOCKER_HUB_USERNAME}} + password: ${{secrets.DOCKER_HUB_TOKEN}} + + - name: build and tagging release to DockerHub + env: + NAME: ${{secrets.DOCKER_HUB_USERNAME}} + REPO: fogfogdev + run: | + shortHash=$(git rev-parse --short ${{ github.sha }}) + docker build -t $REPO -f Dockerfile.dev . + docker tag $REPO:latest $NAME/$REPO:latest + docker tag $REPO:latest $NAME/$REPO:dev + docker tag $REPO:latest $NAME/$REPO:dev-$shortHash + docker push $NAME/$REPO:latest + docker push $NAME/$REPO:dev + docker push $NAME/$REPO:dev-$shortHash + + # - name: Run Deploy Script + # uses: appleboy/ssh-action@master + # with: + # host: ${{ secrets.REMOTE_IP }} + # username: ${{ secrets.REMOTE_SSH_ID }} + # key: ${{ secrets.REMOTE_SSH_KEY }} + # port: ${{ secrets.REMOTE_SSH_PORT }} + # script: | + # cd /opt/fogfog/docker + # sudo /opt/fogfog/docker/dev-deploy.sh + + - name: action-slack + uses: 8398a7/action-slack@v3 + with: + status: ${{ job.status }} + author_name: Github Action Push Server + fields: repo,message,commit,author,action,eventName,ref,workflow,job,took + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required + if: always() # Pick up events even if the job fails or is canceled. \ No newline at end of file From 94cac0c0795253625d2728cb9e139941d0faedfc Mon Sep 17 00:00:00 2001 From: jokj624 Date: Sun, 1 Sep 2024 16:51:02 +0900 Subject: [PATCH 3/7] =?UTF-8?q?build(dev):=20build/deploy=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dev.yml | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index ddee080..f6fc38b 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -6,13 +6,14 @@ on: jobs: build: - env: + name: build pipeline + # env: # PORT: ${{ secrets.PORT }} # MONGODB_URI_DEV: ${{ secrets.MONGODB_URI_DEV }} # MONGODB_URI_PROD: ${{ secrets.MONGODB_URI_PROD }} # REGION: ${{ secrets.REGION }} - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: matrix: @@ -26,6 +27,21 @@ jobs: with: node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: yarn + - name: Run build + run: yarn build + + deploy: + name: deploy pipeline + runs-on: ubuntu-22.04 + + strategy: + matrix: + node-version: ['20.x'] + needs: build + steps: + - uses: actions/checkout@v2 - name: Create .env file run: | touch .env @@ -45,6 +61,11 @@ jobs: echo APPLE_KEYID=${{ secrets.APPLE_KEYID }} >> .env cat .env + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies run: yarn - name: Run build From f6e2a673003600be87049ae709bcc205b44bc255 Mon Sep 17 00:00:00 2001 From: jokj624 Date: Sun, 1 Sep 2024 16:54:29 +0900 Subject: [PATCH 4/7] =?UTF-8?q?build(dockerfile):=20dockerfile=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dockerfile.dev | 1 - 1 file changed, 1 deletion(-) diff --git a/dockerfile.dev b/dockerfile.dev index 5c0f144..4178a9d 100644 --- a/dockerfile.dev +++ b/dockerfile.dev @@ -1,6 +1,5 @@ FROM node:20-alpine AS base -# node prune 설정 RUN apk add curl bash && curl -sfL https://gobinaries.com/tj/node-prune | bash -s -- -b /usr/local/bin WORKDIR /usr/src/app From 2d1d14f3896c64267899f497ded0ea392fc6cf00 Mon Sep 17 00:00:00 2001 From: Chae Jeong Ah Date: Sun, 1 Sep 2024 16:55:27 +0900 Subject: [PATCH 5/7] rename(Dockerfile): Rename dockerfile.dev to Dockerfile.dev --- dockerfile.dev => Dockerfile.dev | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename dockerfile.dev => Dockerfile.dev (95%) diff --git a/dockerfile.dev b/Dockerfile.dev similarity index 95% rename from dockerfile.dev rename to Dockerfile.dev index 4178a9d..edd6b3e 100644 --- a/dockerfile.dev +++ b/Dockerfile.dev @@ -30,4 +30,4 @@ EXPOSE 8081 ENV NODE_ENV=development # start -CMD ["node", "dist/main.js"] \ No newline at end of file +CMD ["node", "dist/main.js"] From e10aa58db8f66bf986dd0699204d7dcf2e4c38b2 Mon Sep 17 00:00:00 2001 From: jokj624 Date: Sun, 1 Sep 2024 16:59:23 +0900 Subject: [PATCH 6/7] build(Dockerfile): add copy prisma step --- Dockerfile.dev | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile.dev b/Dockerfile.dev index edd6b3e..55cddf3 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -5,6 +5,7 @@ RUN apk add curl bash && curl -sfL https://gobinaries.com/tj/node-prune | bash - WORKDIR /usr/src/app COPY package.json ./ +COPY prisma ./ RUN ls -a && yarn @@ -12,7 +13,7 @@ FROM base AS dev COPY . . -RUN ls -a && yarn build +RUN yarn build # run node prune - 사용하지 않는 모듈 제거 # RUN /usr/local/bin/node-prune From 3b53827a7448710fd2c6ff72cebe2c18860b3dd1 Mon Sep 17 00:00:00 2001 From: jokj624 Date: Sun, 1 Sep 2024 17:48:28 +0900 Subject: [PATCH 7/7] build(Dockerfile): add copy env step --- Dockerfile.dev | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile.dev b/Dockerfile.dev index 55cddf3..4a2ee95 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -6,6 +6,7 @@ WORKDIR /usr/src/app COPY package.json ./ COPY prisma ./ +COPY .env ./ RUN ls -a && yarn @@ -21,6 +22,7 @@ RUN yarn build FROM node:20-alpine COPY --from=base /usr/src/app/package.json ./ +COPY --from=base /usr/src/app/.env ./ COPY --from=dev /usr/src/app/dist/ ./dist/ COPY --from=dev /usr/src/app/node_modules/ ./node_modules/