-
Notifications
You must be signed in to change notification settings - Fork 2
140 lines (120 loc) · 3.93 KB
/
cd.yaml
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: CD
on:
push:
tags:
- "v*"
jobs:
wait-for-ci:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
registry-url: "https://npm.pkg.github.com"
- name: Wait for CI check to pass
uses: fountainhead/action-wait-for-check@v1.0.0
id: wait-for-ci
with:
token: ${{ secrets.GITHUB_TOKEN }}
checkName: build (16.x)
ref: ${{ github.event.head }}
- name: Stop workflow
if: steps.wait-for-ci.outputs.conclusion != 'success'
run: node -e 'process.exit(1)'
image-push-scp-build-file:
needs: wait-for-ci
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
registry-url: "https://npm.pkg.github.com"
- name: Install dependencies
run: npm install
- name: Run Build
run: npm run build
- name: Generate DB Schema
run: npx prisma generate
- name: Set env
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/v}" >> $GITHUB_ENV
echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: create-json
id: create-json
uses: jsdaniell/create-json@1.1.2
with:
name: "awsconfig.storj.json"
json: ${{ secrets.STORJ_JSON }}
- name: Generate Environment Variables File for Production
run: |
echo "DATABASE_URL=$DATABASE_URL" >> .env
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Build and Push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
target: prod
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/${{env.REPOSITORY_NAME}}:latest
ghcr.io/${{ github.repository_owner }}/${{env.REPOSITORY_NAME}}:${{ env.RELEASE_VERSION }}
- name: Upload build file to ec2
uses: garygrossgarten/github-action-scp@release
with:
local: ./dist
remote: /home/ubuntu/volunteer-server/dist/
host: ${{ secrets.HOST }}
username: ${{ secrets.SSH_USER }}
privateKey: ${{ secrets.SSH_KEY }}
recursive: true
- name: Upload prisma to ec2
uses: garygrossgarten/github-action-scp@release
with:
local: ./prisma
remote: /home/ubuntu/volunteer-server/prisma/
host: ${{ secrets.HOST }}
username: ${{ secrets.SSH_USER }}
privateKey: ${{ secrets.SSH_KEY }}
recursive: true
- name: Upload copy package to ec2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
source: "package*.json"
target: "/home/ubuntu/volunteer-server/"
- name: Update ec2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
script: |
cd /home/ubuntu/volunteer-server
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
npx prisma migrate deploy
npm ci
pm2 kill
nf -e .env run npm run pm2