Skip to content

Commit df612f5

Browse files
committed
feat(envSample): add a sample file for the environment variables
- create a .sample.env file and include descriptions of what is required - remove the environment variables from the main script - edit the readme file
1 parent 52d870f commit df612f5

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

.sample.env

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export SITE=your_domain_name.com
2+
export GIT_REPO=your_repository_url.git
3+
export SITES_AVAILABLE=/etc/nginx/sites-available
4+
export SITES_ENABLED=/etc/nginx/sites-enabled
5+
export SITES_ENABLED_CONFIG=/etc/nginx/sites-enabled/selene
6+
export SITES_AVAILABLE_CONFIG=/etc/nginx/sites-available/selene
7+
export REPOSITORY_FOLDER=the_name_of_your_repository_directory
8+
export EMAIL=your_email_address
9+
export GREEN='\033[0;32m'
10+
export RED='\033[0;31m'
11+
export GIT_BRANCH=the_branch_you_want_to_clone

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# DevopsDemo
2-
Simple scripts to deploy a react project to an AWS instance
2+
A simple bash script to deploy a react project to an AWS instance
33

44
## How to deploy
55
* Create an AWS free tier account

main.sh

+10-24
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
#!/usr/bin/env bash
22
# create environment variables
33
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-
174
# add enviroment variables to OS
185
source .env
196
}
@@ -36,24 +23,23 @@ installNode(){
3623
# Clone the repository
3724
cloneRepository(){
3825
output "Checking if repository exists..." $GREEN
39-
if [ ! -d selene-ah-frontend ]
26+
if [ ! -d $REPOSITORY_FOLDER ]
4027
then
4128
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
4430
output "Repository already exists..." $RED
4531
output "Removing repository..." $GREEN
46-
sudo rm -r selene-ah-frontend
32+
sudo rm -r $REPOSITORY_FOLDER
4733
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
4935
fi
5036
output "Repository cloned successfully" $GREEN
5137
}
5238

5339
# Setup the project
5440
setupProject(){
5541
output "installing node modules" $GREEN
56-
cd selene-ah-frontend
42+
cd $REPOSITORY_FOLDER
5743
sudo npm install -y
5844
sudo npm audit fix --force
5945
sudo npm run build
@@ -99,8 +85,8 @@ setupNginx(){
9985

10086
setupSSL(){
10187
output "installing and setting up SSL" $GREEN
102-
site=davidessien.com
103-
88+
site=$SITE
89+
email=$EMAIL
10490
sudo apt-get update -y
10591

10692
# Get and install the SSL certificate
@@ -110,7 +96,7 @@ setupSSL(){
11096
sudo apt-get install python-certbot-nginx -y
11197

11298
# 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"
114100

115101
output "successfuly setup SSL" $GREEN
116102
}
@@ -120,11 +106,11 @@ createAppService(){
120106
output "Creating a service for the app..." $GREEN
121107
sudo bash -c "cat > /etc/systemd/system/selene.service <<EOF
122108
[Unit]
123-
Description=Selene ah Service - Service to start the selene-ah frontend app
109+
Description=Selene ah Service - Service to start the app
124110
After=network.target
125111
126112
[Service]
127-
ExecStart=/usr/bin/node /home/ubuntu/selene-ah-frontend/server.js
113+
ExecStart=/usr/bin/node /home/ubuntu/$REPOSITORY_FOLDER/server.js
128114
Restart=on-failure
129115
Type=simple
130116
User=ubuntu

0 commit comments

Comments
 (0)