From 1c7c1e954524544547a1ba09e6ed49d0ba31fd36 Mon Sep 17 00:00:00 2001 From: jinddings Date: Mon, 11 Nov 2024 15:01:55 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20chore=20:=20alpha=EC=84=9C?= =?UTF-8?q?=EB=B2=84=20=EB=B0=B0=ED=8F=AC=EC=99=80=20production=EC=9D=84?= =?UTF-8?q?=20=EC=9C=84=ED=95=9C=20=20CI/CD=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{deploy.yml => deploy-production.yml} | 49 ++++---- .github/workflows/deply-alpha.yml | 119 ++++++++++++++++++ FE/Dockerfile | 17 +++ FE/tsconfig.app.tsbuildinfo | 1 + FE/tsconfig.node.tsbuildinfo | 1 + FE/vite.config.ts | 1 + 6 files changed, 167 insertions(+), 21 deletions(-) rename .github/workflows/{deploy.yml => deploy-production.yml} (65%) create mode 100644 .github/workflows/deply-alpha.yml create mode 100644 FE/Dockerfile create mode 100644 FE/tsconfig.app.tsbuildinfo create mode 100644 FE/tsconfig.node.tsbuildinfo diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy-production.yml similarity index 65% rename from .github/workflows/deploy.yml rename to .github/workflows/deploy-production.yml index f1ca50c3..cf0c3cd9 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy-production.yml @@ -2,9 +2,9 @@ name: deploy on: push: - branches: [main, alpha] + branches: [main] pull_request: - branches: [main, alpha] + branches: [main] env: DOCKER_IMAGE: ${{ vars.DOCKERHUB_USERNAME }}/juga-docker @@ -13,6 +13,13 @@ env: jobs: build-and-deploy: runs-on: ubuntu-latest + strategy: + matrix: + app: + [ + { name: 'be', dir: 'BE', port: 3000, container: 'juga-docker-be' }, + { name: 'fe', dir: 'FE', port: 5173, container: 'juga-docker-fe' }, + ] steps: - uses: actions/checkout@v3 @@ -22,29 +29,29 @@ jobs: with: node-version: '20' cache: 'npm' - cache-dependency-path: ./BE/package-lock.json + cache-dependency-path: ./${{matrix.app.dir}}/package-lock.json - name: Create .env file run: | - touch ./BE/.env - echo "${{ secrets.ENV }}" > ./BE/.env + touch ./${{ matrix.app.dir }}/.env + echo "${{ secrets.ENV }}" > ./${{matrix.app.dir}}/.env - name: Install dependencies - working-directory: ./BE + working-directory: ./${{matrix.app.dir}} run: npm ci - name: Run tests - working-directory: ./BE + working-directory: ./${{matrix.app.dir}} run: npm test env: CI: true - name: Run linter - working-directory: ./BE + working-directory: ./${{matrix.app.dir}} run: npm run lint - name: Build application - working-directory: ./BE + working-directory: ./${{matrix.app.dir}} run: npm run build - name: Login to Docker Hub @@ -54,16 +61,16 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and Push Docker Image - working-directory: ./BE + working-directory: ./${{ matrix.app.dir }} env: NCP_ACCESS_KEY: ${{ secrets.NCP_ACCESS_KEY }} NCP_SECRET_KEY: ${{ secrets.NCP_SECRET_KEY }} run: | - docker build -t ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }} . - docker tag ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }} ${{ env.DOCKER_IMAGE }}:latest + docker build -t ${{ env.DOCKER_IMAGE }}-${{ matrix.app.name }}:${{ env.DOCKER_TAG }} . + docker tag ${{ env.DOCKER_IMAGE }}-${{ matrix.app.name }}:${{ env.DOCKER_TAG }} ${{ env.DOCKER_IMAGE }}-${{ matrix.app.name }}:latest - docker push ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }} - docker push ${{ env.DOCKER_IMAGE }}:latest + docker push ${{ env.DOCKER_IMAGE }}-${{ matrix.app.name }}:${{ env.DOCKER_TAG }} + docker push ${{ env.DOCKER_IMAGE }}-${{ matrix.app.name }}:latest - name: Get Github Actions IP id: ip @@ -95,15 +102,15 @@ jobs: script: | docker system prune -af echo "${{ secrets.ENV }}" > .env - - docker pull ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }} - docker stop juga-docker || true - docker rm juga-docker || true + + docker pull ${{ env.DOCKER_IMAGE }}-${{ matrix.app.name }}:${{ env.DOCKER_TAG }} + docker stop ${{ matrix.app.container }} || true + docker rm ${{ matrix.app.container }} || true docker run -d \ - --name juga-docker \ - -p 3000:3000 \ + --name ${{ matrix.app.container }} \ + -p ${{ matrix.app.port }}:${{ matrix.app.port }} \ --env-file .env \ - ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }} + ${{ env.DOCKER_IMAGE }}-${{ matrix.app.name }}:${{ env.DOCKER_TAG }} - name: Remove Github Action Ip to Security group run: | diff --git a/.github/workflows/deply-alpha.yml b/.github/workflows/deply-alpha.yml new file mode 100644 index 00000000..155e349b --- /dev/null +++ b/.github/workflows/deply-alpha.yml @@ -0,0 +1,119 @@ +name: deploy + +on: + push: + branches: [alpha] + pull_request: + branches: [alpha] + +env: + DOCKER_IMAGE: ${{ vars.DOCKERHUB_USERNAME }}/juga-docker + DOCKER_TAG: ${{ github.sha }} + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + strategy: + matrix: + app: + [ + { name: 'be', dir: 'BE', port: 3000, container: 'juga-docker-be' }, + { name: 'fe', dir: 'FE', port: 5173, container: 'juga-docker-fe' }, + ] + + steps: + - uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + cache-dependency-path: ./${{matrix.app.dir}}/package-lock.json + + - name: Create .env file + run: | + touch ./${{ matrix.app.dir }}/.env + echo "${{ secrets.ENV }}" > ./${{matrix.app.dir}}/.env + + - name: Install dependencies + working-directory: ./${{matrix.app.dir}} + run: npm ci + + - name: Run tests + working-directory: ./${{matrix.app.dir}} + run: npm test + env: + CI: true + + - name: Run linter + working-directory: ./${{matrix.app.dir}} + run: npm run lint + + - name: Build application + working-directory: ./${{matrix.app.dir}} + run: npm run build + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and Push Docker Image + working-directory: ./${{ matrix.app.dir }} + env: + NCP_ACCESS_KEY: ${{ secrets.NCP_ACCESS_KEY }} + NCP_SECRET_KEY: ${{ secrets.NCP_SECRET_KEY }} + run: | + docker build -t ${{ env.DOCKER_IMAGE }}-${{ matrix.app.name }}:${{ env.DOCKER_TAG }} . + docker tag ${{ env.DOCKER_IMAGE }}-${{ matrix.app.name }}:${{ env.DOCKER_TAG }} ${{ env.DOCKER_IMAGE }}-${{ matrix.app.name }}:latest + + docker push ${{ env.DOCKER_IMAGE }}-${{ matrix.app.name }}:${{ env.DOCKER_TAG }} + docker push ${{ env.DOCKER_IMAGE }}-${{ matrix.app.name }}:latest + + - name: Get Github Actions IP + id: ip + uses: haythem/public-ip@v1.2 + + - name: Setting NCP CLI & Credentials + run: | + cd ~ + wget https://www.ncloud.com/api/support/download/5/65 + unzip 65 + mkdir ~/.ncloud + echo -e "[DEFAULT]\nncloud_access_key_id = ${{ secrets.NCP_ACCESS_KEY }}\nncloud_secret_access_key = ${{ secrets.NCP_SECRET_KEY }}\nncloud_api_url = ${{ secrets.NCP_API_URI }}" >> ~/.ncloud/configure + + - name: Add Github Action Ip to Security group + run: | + cd ~ + ls -la + chmod -R 777 ~/cli_linux + cd ~/cli_linux + ./ncloud vserver addAccessControlGroupInboundRule --regionCode KR --vpcNo ${{ secrets.NCP_VPC_ID }} --accessControlGroupNo ${{ secrets.NCP_ACG_ID }} --accessControlGroupRuleList "protocolTypeCode='TCP', ipBlock='${{ steps.ip.outputs.ipv4 }}/32', portRange='${{ secrets.SSH_PORT }}'" + + - name: Deploy to NCP Server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.NCP_ALPHA_SERVER_HOST }} + username: ${{ secrets.NCP_ALPHA_SERVER_USERNAME }} + key: ${{ secrets.NCP_ALPHA_SERVER_SSH_KEY }} + port: 22 + script: | + docker system prune -af + echo "${{ secrets.ENV }}" > .env + + docker pull ${{ env.DOCKER_IMAGE }}-${{ matrix.app.name }}:${{ env.DOCKER_TAG }} + docker stop ${{ matrix.app.container }} || true + docker rm ${{ matrix.app.container }} || true + docker run -d \ + --name ${{ matrix.app.container }} \ + -p ${{ matrix.app.port }}:${{ matrix.app.port }} \ + --env-file .env \ + ${{ env.DOCKER_IMAGE }}-${{ matrix.app.name }}:${{ env.DOCKER_TAG }} + + - name: Remove Github Action Ip to Security group + run: | + chmod -R 777 ~/cli_linux + cd ~/cli_linux + ./ncloud vserver removeAccessControlGroupInboundRule --regionCode KR --vpcNo ${{ secrets.NCP_VPC_ID }} --accessControlGroupNo ${{ secrets.NCP_ACG_ID }} --accessControlGroupRuleList "protocolTypeCode='TCP', ipBlock='${{ steps.ip.outputs.ipv4 }}/32', portRange='${{ secrets.SSH_PORT }}'" diff --git a/FE/Dockerfile b/FE/Dockerfile new file mode 100644 index 00000000..6773e6a4 --- /dev/null +++ b/FE/Dockerfile @@ -0,0 +1,17 @@ +FROM node:20 + +RUN mkdir -p /var/app +WORKDIR /var/app + +COPY package*.json ./ +RUN npm install + +COPY . . + +RUN npm run build + +RUN npm install -g serve + +EXPOSE 5173 + +CMD ["serve", "-s", "dist", "-l", "5173"] \ No newline at end of file diff --git a/FE/tsconfig.app.tsbuildinfo b/FE/tsconfig.app.tsbuildinfo new file mode 100644 index 00000000..bbaf2949 --- /dev/null +++ b/FE/tsconfig.app.tsbuildinfo @@ -0,0 +1 @@ +{"root":["./src/app.tsx","./src/main.tsx","./src/vite-env.d.ts","./src/components/header.tsx","./src/page/home.tsx"],"version":"5.6.3"} \ No newline at end of file diff --git a/FE/tsconfig.node.tsbuildinfo b/FE/tsconfig.node.tsbuildinfo new file mode 100644 index 00000000..75ea0011 --- /dev/null +++ b/FE/tsconfig.node.tsbuildinfo @@ -0,0 +1 @@ +{"root":["./vite.config.ts"],"version":"5.6.3"} \ No newline at end of file diff --git a/FE/vite.config.ts b/FE/vite.config.ts index 539e2463..be05188f 100644 --- a/FE/vite.config.ts +++ b/FE/vite.config.ts @@ -6,6 +6,7 @@ import tsconfigPaths from 'vite-tsconfig-paths'; export default defineConfig({ plugins: [react(), tsconfigPaths()], server: { + host: true, open: true, }, });