Skip to content

Commit

Permalink
ci: EC2에 서비스 배포 (#395)
Browse files Browse the repository at this point in the history
- 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` 받았나요?
  • Loading branch information
EATSTEAK authored and jongse7 committed Feb 27, 2025
1 parent 6df84b2 commit 0deb9e0
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 39 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -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
83 changes: 45 additions & 38 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit 0deb9e0

Please sign in to comment.