generated from CS3219-AY2324S1/course-assessment-template
-
Notifications
You must be signed in to change notification settings - Fork 1
59 lines (46 loc) · 1.71 KB
/
deploy-production-ec2.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
name: Deploy to Production EC2
on:
workflow_dispatch: {}
jobs:
deploy-production:
name: Deploy to EC2
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up SSH access
env:
PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
run: |
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
echo "SSH access configured."
- name: Run in EC2 instance
env:
USER_NAME: ${{ secrets.USER_NAME }}
HOSTNAME: ${{ secrets.SSH_HOST }}
run: |
ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} '
echo "Entered EC2 instance" &&
echo "Step 1: Set node path..." &&
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
echo "Step 2: Change directory to /app..." &&
cd ~/app &&
echo "Step 3: Shutting down containers..." &&
docker compose down &&
echo "Step 4: Pull and update local production branch to match remote..." &&
git checkout production &&
git fetch --prune &&
git reset --hard origin/production &&
echo "Step 5: Install dependencies for all microservices..." &&
bash install-deps-prod.sh &&
echo "Step 6: Restarting docker containers..." &&
bash start-prod.sh &&
echo "Step 7: Migrating users database to match latest..." &&
cd users-service &&
yarn knex migrate:latest &&
cd ..
echo "Step 8: Migrating history database to match latest..." &&
cd history-service &&
yarn knex migrate:latest &&
cd ..
'