From 0deb9e0605869a9051a8e860a46a001968513db8 Mon Sep 17 00:00:00 2001 From: EATSTEAK Date: Wed, 5 Feb 2025 10:37:38 +0900 Subject: [PATCH] =?UTF-8?q?ci:=20EC2=EC=97=90=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EB=B0=B0=ED=8F=AC=20(#395)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - resolved #387 EC2에 서비스를 배포합니다. 워크플로 등록을 위해 main에 머지 배포 URL: - (develop) [https://dev.sssupport.shop](https://dev.sssupport.shop) - (production) [https://sssupport.shop](https://sssupport.shop) - 추후 `stu.ssu.ac.kr`에도 연결 예정 @jongse7 프로덕션에서 `VITE_REST_API_KEY` 값 설정이 필요합니다. 나중에 전달 해주시거나 아니면 `prod` environment에 `VITE_REST_API_KEY` 시크릿 업데이트 후 알려주세요. - [x] `develop` 브랜치의 최신 코드를 `pull` 받았나요? --- .github/workflows/deploy-dev.yml | 55 +++++++++++++++++++++ .github/workflows/deploy.yml | 83 +++++++++++++++++--------------- package.json | 5 +- 3 files changed, 104 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/deploy-dev.yml diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml new file mode 100644 index 00000000..eaa97dd9 --- /dev/null +++ b/.github/workflows/deploy-dev.yml @@ -0,0 +1,55 @@ +name: Deployment (Develop) + +on: + push: + branches: + - develop + +jobs: + build: + runs-on: ubuntu-latest + environment: develop + steps: + - name: Repository checkout + uses: actions/checkout@v4 + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version-file: 'package.json' + - name: Retrive caches + uses: actions/cache@v4 + with: + path: node_modules + key: ${{ hashFiles('yarn.lock') }} + - name: Enable corepack + run: corepack enable + - name: Install project + run: yarn install --immutable + - name: Build + run: yarn build + env: + VITE_API_URL: ${{ vars.VITE_API_URL }} + VITE_REDIRECT_URI: ${{ vars.VITE_REDIRECT_URI }} + VITE_REST_API_KEY: ${{ secrets.VITE_REST_API_KEY }} + - name: Compress build artifacts + run: tar -cvf ./dist.tar ./dist + - name: Upload with SCP + uses: appleboy/scp-action@v0.1.7 + with: + username: ubuntu + host: ${{ secrets.SSH_HOST }} + key: ${{ secrets.SSH_KEY }} + source: "dist.tar" + target: "/home/ubuntu/" + - name: Extract artifact with SSH + uses: appleboy/ssh-action@v1.2.0 + with: + username: ubuntu + host: ${{ secrets.SSH_HOST }} + key: ${{ secrets.SSH_KEY }} + script: | + tar -xvf ./dist.tar ./dist + sudo rm -rf /var/www/homepage-frontend + sudo mv ./dist /var/www/homepage-frontend + rm -rf ./dist + rm -f ./dist.tar diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 55aa196c..8e9836d7 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,48 +1,55 @@ -name: Deploy +name: Deployment (Production) on: push: - branches: ['main'] + branches: + - main jobs: build: runs-on: ubuntu-latest - - container: pandoc/latex - + environment: prod steps: - - uses: actions/checkout@v2 - - - name: Install mustache (to update the date) - - run: apk add ruby && gem install mustache - - - name: creates output - - run: sh ./build.sh - - - name: Pushes to another repository - - id: push_directory - - uses: cpina/github-action-push-to-another-repository@main - + - name: Repository checkout + uses: actions/checkout@v4 + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version-file: 'package.json' + - name: Retrive caches + uses: actions/cache@v4 + with: + path: node_modules + key: ${{ hashFiles('yarn.lock') }} + - name: Enable corepack + run: corepack enable + - name: Install project + run: yarn install --immutable + - name: Build + run: yarn build env: - API_TOKEN_GITHUB: ${{ secrets.AUTO_ACTIONS }} - + VITE_API_URL: ${{ vars.VITE_API_URL }} + VITE_REDIRECT_URI: ${{ vars.VITE_REDIRECT_URI }} + VITE_REST_API_KEY: ${{ secrets.VITE_REST_API_KEY }} + - name: Compress build artifacts + run: tar -cvf ./dist.tar ./dist + - name: Upload with SCP + uses: appleboy/scp-action@v0.1.7 with: - source-directory: 'output' - - destination-github-username: ssu-it-support - - destination-repository-name: homepage-frontend - - user-email: ${{ secrets.EMAIL }} - - commit-message: ${{ github.event.commits[0].message }} - - target-branch: main - - - name: Test get variable exported by push-to-another-repository - - run: echo $DESTINATION_CLONED_DIRECTORY + username: ubuntu + host: ${{ secrets.SSH_HOST }} + key: ${{ secrets.SSH_KEY }} + source: "dist.tar" + target: "/home/ubuntu/" + - name: Extract artifact with SSH + uses: appleboy/ssh-action@v1.2.0 + with: + username: ubuntu + host: ${{ secrets.SSH_HOST }} + key: ${{ secrets.SSH_KEY }} + script: | + tar -xvf ./dist.tar ./dist + sudo rm -rf /var/www/homepage-frontend + sudo mv ./dist /var/www/homepage-frontend + rm -rf ./dist + rm -f ./dist.tar diff --git a/package.json b/package.json index f4e7ad31..20195997 100644 --- a/package.json +++ b/package.json @@ -84,5 +84,8 @@ "react": "^18.3.0", "@types/react": "^18.3.0" }, - "packageManager": "yarn@4.5.3" + "packageManager": "yarn@4.5.3", + "engines": { + "node": ">=20" + } }