-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (111 loc) · 4.33 KB
/
main.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
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
# This is a basic workflow to help you get started with Actions
name: CI/CD
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
API_URL: "https://rentx.devluiz.me"
API_PATH: "/home/app/app/api-rentx"
FORGOT_MAIL_URL: "https://rentx.devluiz.me/password/reset?token="
STORAGE_DRIVER: amazonS3
MAIL_DRIVER: amazonSES
AWS_REGION: sa-east-1
AWS_S3_BUCKET_NAME: api-myown-rentx
PM2_SERVICE_NAME: rentx_api
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
name: Build API Artifact
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Setup Node.js environment
uses: actions/setup-node@v2.5.1
with:
node-version: 16.x
- name: Install Dependencies
run: yarn
- name: Build
run: yarn build:babel
- name: Copy Additional Files
run: |
cp docker-compose.yml dist
cp package.json dist
ls -A dist
- name: Upload a Build Artifact
uses: actions/upload-artifact@v2.3.1
with:
# Artifact name
name: artifact
# A file, directory or wildcard pattern that describes what to upload
path: dist
deploy-ec2:
name: Deploy to Amazon EC2 Instance
needs: build
runs-on: ubuntu-latest
environment: production
steps:
- name: Download a Build Artifact
uses: actions/download-artifact@v2.1.0
with:
name: artifact
- name: Create ENV File
run: |
touch .env
echo "AWS_REGION=${{ env.AWS_REGION }}" >> .env
echo "AWS_S3_BUCKET_NAME=${{ env.AWS_S3_BUCKET_NAME }}" >> .env
echo "AWS_S3_ACCESS_KEY_ID=${{ secrets.AWS_S3_ACCESS_KEY_ID }}" >> .env
echo "AWS_S3_SECRET_ACCESS_KEY=${{ secrets.AWS_S3_SECRET_ACCESS_KEY }}" >> .env
echo "AWS_SES_ACCESS_KEY_ID=${{ secrets.AWS_SES_ACCESS_KEY_ID }}" >> .env
echo "AWS_SES_SECRET_ACCESS_KEY=${{ secrets.AWS_SES_SECRET_ACCESS_KEY }}" >> .env
echo "PSQL_PORT=${{ secrets.PSQL_PORT }}" >> .env
echo "PSQL_PASSWORD='${{ secrets.PSQL_PASSWORD }}'" >> .env
echo "REDIS_PORT=${{ secrets.REDIS_PORT }}" >> .env
echo "REDIS_PASSWORD='${{ secrets.REDIS_PASSWORD }}'" >> .env
echo "API_URL=${{ env.API_URL }}" >> .env
echo "FORGOT_MAIL_URL=${{ env.FORGOT_MAIL_URL }}" >> .env
echo "STORAGE_DRIVER=${{ env.STORAGE_DRIVER }}" >> .env
echo "MAIL_DRIVER=${{ env.MAIL_DRIVER }}" >> .env
echo "SENTRY_DSN=${{ env.SENTRY_DSN }}" >> .env
- name: Create ORM JSON
id: create-json
uses: jsdaniell/create-json@master
with:
name: "ormconfig.json"
json: ${{ secrets.PSQL_CONFIG_JSON }}
- name: Create ORM MIGRATIONS JSON
id: create-migrations-json
uses: jsdaniell/create-json@master
with:
name: "ormconfig.migrations.json"
json: ${{ secrets.PSQL_MIGRATIONS_CONFIG_JSON }}
- name: SCP Files
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
target: ${{ env.API_PATH }}
source: ".,.env"
rm: true
- name: Install Production Dependencies | Run Migrations | Restart API
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
script: |
cd ${{ env.API_PATH }}
yarn --production
node ./node_modules/typeorm/cli --config ormconfig.migrations.json migration:run
pm2 restart ${{ env.PM2_SERVICE_NAME }}