Skip to content

Commit

Permalink
Merge pull request #240 from woowa-techcamp-2021/feat/prod-server-cd
Browse files Browse the repository at this point in the history
[#239] production 환경 배포 스크립트
  • Loading branch information
Choi-Jinwoo authored Aug 29, 2021
2 parents 81f95cb + 6076e06 commit b601741
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/prod-server-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Production Server CD

on:
push:
branches:
- main
jobs:
backend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v4
with:
PATTERNS: |
src/**/*.+(ts|tsx)
FILES: |
package.json
RELATIVE: "server"
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/production.key
chmod 600 ~/.ssh/production.key
cat >>~/.ssh/config <<END
Host production
HostName $SSH_HOST
User $SSH_USER
IdentityFile ~/.ssh/production.key
StrictHostKeyChecking no
END
env:
SSH_HOST: ${{ secrets.HOSTNAME }}
SSH_USER: ${{ secrets.USERNAME }}
SSH_KEY: ${{ secrets.PRIVATE_KEY }}
- name: Checkout and Pull origin
run: ssh production 'cd ~/store-4 && git checkout main && git pull origin'

- name: if changed dependencies, install dependencies
run: ssh production 'cd ~/store-4/server && npm i'
if: env.MATCHED_FILES

- name: Reload Pm2
run: ssh production 'cd ~/store-4/server && npm run build && sudo pm2 reload store-4'
if: env.GIT_DIFF
frontend:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v4
with:
PATTERNS: |
client/src/**/*.+(ts|tsx)
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/production.key
chmod 600 ~/.ssh/production.key
cat >>~/.ssh/config <<END
Host production
HostName $SSH_HOST
User $SSH_USER
IdentityFile ~/.ssh/production.key
StrictHostKeyChecking no
END
env:
SSH_HOST: ${{ secrets.HOSTNAME }}
SSH_USER: ${{ secrets.USERNAME }}
SSH_KEY: ${{ secrets.PRIVATE_KEY }}
- name: Touch .env file
run: |
cat >>./.env <<END
SERVER_URL=${{ secrets.SERVER_URL }}
END
working-directory: client
- name: Run build script && Sync build files to server
run: cd client && npm i && npm run build && rsync -avz ./dist/ production:~/store-4/client/dist
if: env.GIT_DIFF

0 comments on commit b601741

Please sign in to comment.