-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (112 loc) · 5.95 KB
/
deploy.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
name: Deploy
on:
push:
branches:
- development
- production
env:
DOCKER_PROJECT_NAME_DEV: dev-orgatrips-back
PROJECT_PATH_DEV: ${{ secrets.DEVELOPMENT_DOCKER_IMAGES_PATH }}/dev-orgatrips-back
DOCKER_PROJECT_NAME_PROD: orgatrips-back
PROJECT_PATH_PROD: ${{ secrets.PRODUCTION_DOCKER_IMAGES_PATH }}/orgatrips-back
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/} | tr a-z A-Z)"
id: extract_branch
- name: Create .env
run: |
touch .env
echo "APP_SECRET=${{ secrets.APP_SECRET }}" >> .env
echo "APP_MAILJET_PUBLIC_KEY=${{ secrets.APP_MAILJET_PUBLIC_KEY }}" >> .env
echo "APP_MAILJET_PRIVATE_KEY=${{ secrets.APP_MAILJET_PRIVATE_KEY }}" >> .env
echo "APP_MAILJET_SENDER_MAIL=${{ secrets.APP_MAILJET_SENDER_MAIL }}" >> .env
echo "APP_KIWI_PUBLIC_KEY=${{ secrets.APP_KIWI_PUBLIC_KEY }}" >> .env
echo "APP_CORS_ORIGIN=${{ secrets.APP_CORS_ORIGIN }}" >> .env
- name: Add .env variable based on branch development
if: ${{ steps.extract_branch.outputs.branch == 'DEVELOPMENT' }}
run: |
echo "APP_DB_HOST=${{ secrets.DEVELOPMENT_APP_DB_HOST }}" >> .env
echo "APP_DB_USER=${{ secrets.DEVELOPMENT_APP_DB_USER }}" >> .env
echo "APP_DB_PASSWORD=${{ secrets.DEVELOPMENT_APP_DB_PASSWORD }}" >> .env
echo "APP_DB_NAME=${{ secrets.DEVELOPMENT_APP_DB_NAME }}" >> .env
echo "APP_BACKEND_PUBLIC_URL=${{ secrets.DEVELOPMENT_APP_BACKEND_PUBLIC_URL }}" >> .env
echo "APP_FRONTEND_PUBLIC_URL=${{ secrets.DEVELOPMENT_APP_FRONTEND_PUBLIC_URL }}" >> .env
echo "APP_TRANSPORTATION_BUDGET_PERCENTAGE=${{ secrets.DEVELOPMENT_APP_TRANSPORTATION_BUDGET_PERCENTAGE }}" >> .env
echo "APP_ACCOMODATION_BUDGET_PERCENTAGE=${{ secrets.DEVELOPMENT_APP_ACCOMODATION_BUDGET_PERCENTAGE }}" >> .env
echo "APP_OTHER_BUDGET_PER_DAY=${{ secrets.DEVELOPMENT_APP_OTHER_BUDGET_PER_DAY }}" >> .env
- name: Add .env variable based on branch development
if: ${{ steps.extract_branch.outputs.branch == 'PRODUCTION' }}
run: |
echo "APP_DB_HOST=${{ secrets.PRODUCTION_APP_DB_HOST }}" >> .env
echo "APP_DB_USER=${{ secrets.PRODUCTION_APP_DB_USER }}" >> .env
echo "APP_DB_PASSWORD=${{ secrets.PRODUCTION_APP_DB_PASSWORD }}" >> .env
echo "APP_DB_NAME=${{ secrets.PRODUCTION_APP_DB_NAME }}" >> .env
echo "APP_BACKEND_PUBLIC_URL=${{ secrets.PRODUCTION_APP_BACKEND_PUBLIC_URL }}" >> .env
echo "APP_FRONTEND_PUBLIC_URL=${{ secrets.PRODUCTION_APP_FRONTEND_PUBLIC_URL }}" >> .env
echo "APP_TRANSPORTATION_BUDGET_PERCENTAGE=${{ secrets.PRODUCTION_APP_TRANSPORTATION_BUDGET_PERCENTAGE }}" >> .env
echo "APP_ACCOMODATION_BUDGET_PERCENTAGE=${{ secrets.PRODUCTION_APP_ACCOMODATION_BUDGET_PERCENTAGE }}" >> .env
echo "APP_OTHER_BUDGET_PER_DAY=${{ secrets.PRODUCTION_APP_OTHER_BUDGET_PER_DAY }}" >> .env
- name: Use Node.js 14.x
uses: actions/setup-node@v3
with:
node-version: "14.x"
cache: "yarn"
- name: Install dependencies
run: yarn install
# DEVELOPMENT
- name: Copy repository contents via scp
if: ${{ steps.extract_branch.outputs.branch == 'DEVELOPMENT' }}
uses: appleboy/scp-action@master
with:
HOST: ${{ secrets.DEVELOPMENT_HOST }}
USERNAME: ${{ secrets.DEVELOPMENT_USERNAME }}
PORT: ${{ secrets.DEVELOPMENT_PORT }}
KEY: ${{ secrets.DEVELOPMENT_SSHKEY }}
source: "."
target: ${{ env.PROJECT_PATH_DEV }}
- name: Executing remote command
if: ${{ steps.extract_branch.outputs.branch == 'DEVELOPMENT' }}
uses: appleboy/ssh-action@master
with:
HOST: ${{ secrets.DEVELOPMENT_HOST }}
USERNAME: ${{ secrets.DEVELOPMENT_USERNAME }}
PORT: ${{ secrets.DEVELOPMENT_PORT }}
KEY: ${{ secrets.DEVELOPMENT_SSHKEY }}
envs: PROJECT_PATH_DEV,DOCKER_PROJECT_NAME_DEV
script: |
cd $PROJECT_PATH_DEV
git clean -df
docker ps -q --filter "name=$DOCKER_PROJECT_NAME_DEV" | grep -q . && docker stop $DOCKER_PROJECT_NAME_DEV && docker container rm $DOCKER_PROJECT_NAME_DEV
docker build -t $DOCKER_PROJECT_NAME_DEV $PROJECT_PATH_DEV
docker run -d --network reverse-proxy --ip ${{ secrets.DEVELOPMENT_DOCKER_LOCAL_IP }} --name $DOCKER_PROJECT_NAME_DEV -t $DOCKER_PROJECT_NAME_DEV
# PRODUCTION
- name: Copy repository contents via scp PRODUCTION
if: ${{ steps.extract_branch.outputs.branch == 'PRODUCTION' }}
uses: appleboy/scp-action@master
with:
HOST: ${{ secrets.PRODUCTION_HOST }}
USERNAME: ${{ secrets.PRODUCTION_USERNAME }}
PORT: ${{ secrets.PRODUCTION_PORT }}
KEY: ${{ secrets.PRODUCTION_SSHKEY }}
source: "."
target: ${{ env.PROJECT_PATH_PROD }}
- name: Executing remote command PRODUCTION
if: ${{ steps.extract_branch.outputs.branch == 'PRODUCTION' }}
uses: appleboy/ssh-action@master
with:
HOST: ${{ secrets.PRODUCTION_HOST }}
USERNAME: ${{ secrets.PRODUCTION_USERNAME }}
PORT: ${{ secrets.PRODUCTION_PORT }}
KEY: ${{ secrets.PRODUCTION_SSHKEY }}
envs: PROJECT_PATH_PROD,DOCKER_PROJECT_NAME_PROD
script: |
cd $PROJECT_PATH_PROD
git clean -df
docker ps -q --filter "name=$DOCKER_PROJECT_NAME_PROD" | grep -q . && docker stop $DOCKER_PROJECT_NAME_PROD && docker container rm $DOCKER_PROJECT_NAME_PROD
docker build -t $DOCKER_PROJECT_NAME_PROD $PROJECT_PATH_PROD
docker run -d --network reverse-proxy --ip ${{ secrets.PRODUCTION_DOCKER_LOCAL_IP }} --name $DOCKER_PROJECT_NAME_PROD -t $DOCKER_PROJECT_NAME_PROD