1
1
#! /usr/bin/env bash
2
2
# create environment variables
3
3
createEnv (){
4
- sudo echo "
5
- export SITE=davidessien.com
6
- export GIT_REPO=https://github.com/andela/selene-ah-frontend.git
7
- export SITES_AVAILABLE=/etc/nginx/sites-available
8
- export SITES_ENABLED=/etc/nginx/sites-enabled
9
- export SITES_ENABLED_CONFIG=/etc/nginx/sites-enabled/selene
10
- export SITES_AVAILABLE_CONFIG=/etc/nginx/sites-available/selene
11
- export REPOSITORY_FOLDER=selene-ah-frontend
12
-
13
- export GREEN='\033[0;32m'
14
- export RED='\033[0;31m'
15
- " > .env
16
-
17
4
# add enviroment variables to OS
18
5
source .env
19
6
}
@@ -36,24 +23,23 @@ installNode(){
36
23
# Clone the repository
37
24
cloneRepository (){
38
25
output " Checking if repository exists..." $GREEN
39
- if [ ! -d selene-ah-frontend ]
26
+ if [ ! -d $REPOSITORY_FOLDER ]
40
27
then
41
28
output " Cloning repository..." $GREEN
42
- git clone -b aws-deploy https://github.com/andela/selene-ah-frontend.git
43
- else
29
+ git clone -b $GIT_BRANCH $GIT_REPO
44
30
output " Repository already exists..." $RED
45
31
output " Removing repository..." $GREEN
46
- sudo rm -r selene-ah-frontend
32
+ sudo rm -r $REPOSITORY_FOLDER
47
33
output " Cloning repository..." $GREEN
48
- git clone -b aws-deploy https://github.com/andela/selene-ah-frontend.git
34
+ git clone -b $GIT_BRANCH $GIT_REPO
49
35
fi
50
36
output " Repository cloned successfully" $GREEN
51
37
}
52
38
53
39
# Setup the project
54
40
setupProject (){
55
41
output " installing node modules" $GREEN
56
- cd selene-ah-frontend
42
+ cd $REPOSITORY_FOLDER
57
43
sudo npm install -y
58
44
sudo npm audit fix --force
59
45
sudo npm run build
@@ -99,8 +85,8 @@ setupNginx(){
99
85
100
86
setupSSL (){
101
87
output " installing and setting up SSL" $GREEN
102
- site=davidessien.com
103
-
88
+ site=$SITE
89
+ email=$EMAIL
104
90
sudo apt-get update -y
105
91
106
92
# Get and install the SSL certificate
@@ -110,7 +96,7 @@ setupSSL(){
110
96
sudo apt-get install python-certbot-nginx -y
111
97
112
98
# Configure the ngix proxy file to use the SSL certificate
113
- sudo certbot --nginx -n --agree-tos --email $email --redirect --expand -d $site -d " www.$site "
99
+ sudo certbot --nginx -n --agree-tos --email $EMAIL --redirect --expand -d $SITE -d " www.$SITE "
114
100
115
101
output " successfuly setup SSL" $GREEN
116
102
}
@@ -120,11 +106,11 @@ createAppService(){
120
106
output " Creating a service for the app..." $GREEN
121
107
sudo bash -c " cat > /etc/systemd/system/selene.service <<EOF
122
108
[Unit]
123
- Description=Selene ah Service - Service to start the selene-ah frontend app
109
+ Description=Selene ah Service - Service to start the app
124
110
After=network.target
125
111
126
112
[Service]
127
- ExecStart=/usr/bin/node /home/ubuntu/selene-ah-frontend /server.js
113
+ ExecStart=/usr/bin/node /home/ubuntu/$REPOSITORY_FOLDER /server.js
128
114
Restart=on-failure
129
115
Type=simple
130
116
User=ubuntu
0 commit comments