Skip to content

Commit f103726

Browse files
committed
Changed build scripts to build from a clean Ubuntu instance.
1 parent d3a29d1 commit f103726

7 files changed

Lines changed: 118 additions & 92 deletions

File tree

appspec.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,11 @@ version: 0.0
22
os: linux
33
files:
44
- source: /wise.war
5-
destination: /home/ubuntu/build
6-
permissions:
7-
- object: /
8-
pattern: "**"
9-
owner: ubuntu
10-
group: ubuntu
5+
destination: /home/ubuntu/build-folder
116
hooks:
127
BeforeInstall:
138
- location: beforeInstall.sh
14-
runas: ubuntu
9+
runas: root
1510
AfterInstall:
1611
- location: afterInstall.sh
17-
runas: ubuntu
18-
ApplicationStart:
19-
- location: applicationStart.sh
20-
runas: ubuntu
12+
runas: root

buildspec.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ artifacts:
1212
- appspec.yml
1313
- scripts/beforeInstall.sh
1414
- scripts/afterInstall.sh
15-
- scripts/applicationStart.sh
1615
- target/wise.war
17-
discard-paths: yes
16+
discard-paths: yes

scripts/afterInstall.sh

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
#!/bin/bash
22

33
export HOME=/home/ubuntu
4-
export CATALINA_HOME=/opt/tomcat
5-
export BUILD_DIR=$HOME/build
6-
export QA_BUILD_DIR=$BUILD_DIR/qa
7-
export PROD_BUILD_DIR=$BUILD_DIR/prod
4+
export BUILD_DIR=$HOME/build-folder
5+
export BUILD_FILES=$HOME/wise-build-files
6+
export CATALINA_HOME=/var/lib/tomcat9
87

98
exec &>> $HOME/deploy.log
109

11-
if [[ $DEPLOYMENT_GROUP_NAME == "qa-deployment-group" ]]; then
12-
echo "Moving $BUILD_DIR/wise.war to $QA_BUILD_DIR"
13-
mv $BUILD_DIR/wise.war $QA_BUILD_DIR
10+
echo "Changing to $BUILD_DIR directory"
11+
cd $BUILD_DIR
1412

15-
echo "Changing directory to $QA_BUILD_DIR"
16-
cd $QA_BUILD_DIR
17-
elif [[ $DEPLOYMENT_GROUP_NAME == "prod-deployment-group" ]]; then
18-
echo "Moving $BUILD_DIR/wise.war to $PROD_BUILD_DIR"
19-
mv $BUILD_DIR/wise.war $PROD_BUILD_DIR
20-
21-
echo "Changing directory to $PROD_BUILD_DIR"
22-
cd $PROD_BUILD_DIR
23-
fi
24-
25-
echo "Adding application.properties to wise.war"
13+
echo "Injecting application.properties into wise.war"
2614
zip -g wise.war WEB-INF/classes/application.properties
2715

2816
echo "Moving wise.war to $CATALINA_HOME/webapps/ROOT.war"
2917
mv wise.war $CATALINA_HOME/webapps/ROOT.war
18+
chown tomcat:tomcat $CATALINA_HOME/webapps/ROOT.war
19+
20+
echo "Copying legacy.war to $BUILD_DIR"
21+
cp $BUILD_FILES/legacy.war $BUILD_DIR
22+
23+
echo "Injecting application.properties into legacy.war"
24+
zip -g legacy.war WEB-INF/classes/application.properties
25+
26+
echo "Moving legacy.war to $CATALINA_HOME/webapps/legacy.war"
27+
mv legacy.war $CATALINA_HOME/webapps/legacy.war
28+
chown tomcat:tomcat $CATALINA_HOME/webapps/legacy.war
29+
30+
echo "Deleting build-folder"
31+
rm -rf $BUILD_DIR
3032

31-
echo "Copying application.properties to $CATALINA_HOME/webapps/legacy/WEB-INF/classes/application.properties"
32-
cp WEB-INF/classes/application.properties $CATALINA_HOME/webapps/legacy/WEB-INF/classes/application.properties
33+
echo "Finishing deployment at $(date)"

scripts/applicationStart.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

scripts/beforeInstall.sh

Lines changed: 93 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,103 @@
11
#!/bin/bash
22

33
export HOME=/home/ubuntu
4-
export CATALINA_HOME=/opt/tomcat
4+
export BUILD_DIR=$HOME/build-folder
5+
export BUILD_FILES=$HOME/wise-build-files
6+
export CATALINA_HOME=/var/lib/tomcat9
57

8+
sudo -u ubuntu -g ubuntu touch $HOME/deploy.log
69
exec &>> $HOME/deploy.log
710

811
echo "Starting deployment at $(date)"
912

10-
echo "Stopping Tomcat"
11-
sudo service tomcat stop
13+
if [[ $DEPLOYMENT_GROUP_NAME == "qa-deployment-group" ]]; then
14+
env="qa"
15+
elif [[ $DEPLOYMENT_GROUP_NAME == "prod-deployment-group" ]]; then
16+
env="prod"
17+
fi
1218

13-
echo "Deleting $CATALINA_HOME/webapps/ROOT.war"
14-
rm -rf $CATALINA_HOME/webapps/ROOT.war
19+
echo "Updating Ubuntu"
20+
apt-get update
21+
apt-get upgrade -y
1522

16-
echo "Deleting $CATALINA_HOME/webapps/ROOT"
17-
rm -rf $CATALINA_HOME/webapps/ROOT
23+
echo "Setting server timezone to Los Angeles"
24+
timedatectl set-timezone America/Los_Angeles
25+
26+
echo "Installing AWS CLI"
27+
apt-get install awscli -y
28+
29+
echo "Downloading files from wise-build-files S3 bucket"
30+
sudo -u ubuntu -g ubuntu mkdir $HOME/wise-build-files
31+
sudo -u ubuntu -g ubuntu aws s3 sync s3://wise-build-files $HOME/wise-build-files
32+
chmod u+x $HOME/wise-build-files/sync.sh
33+
34+
echo "Installing Java 11"
35+
apt-get install openjdk-11-jdk-headless -y
36+
37+
echo "Create tomcat group"
38+
groupadd -g 1001 tomcat
39+
40+
echo "Create tomcat user"
41+
useradd -u 1001 -g tomcat -c "Apache Tomcat" -d / -s /usr/sbin/nologin tomcat
42+
43+
echo "Adding ubuntu user to tomcat group"
44+
usermod -a -G tomcat ubuntu
45+
46+
echo "Installing Tomcat 9"
47+
apt-get install tomcat9 -y
48+
49+
echo "Removing Tomcat ROOT folder"
50+
rm -rf $CATALINA_HOME/webapps/ROOT
51+
52+
echo "Add https to Tomcat server.xml"
53+
sed 's/<Connector port="8080"/<Connector port="8080" scheme="https"/' -i $CATALINA_HOME/conf/server.xml
54+
55+
echo "Downlading setenv.sh Tomcat file"
56+
cp $BUILD_FILES/setenv.sh /usr/share/tomcat9/bin/setenv.sh
57+
58+
echo "Restarting Tomcat"
59+
service tomcat9 restart
60+
61+
echo "Creating Tomcat curriculum and studentuploads folders"
62+
sudo -u ubuntu -g tomcat mkdir $CATALINA_HOME/webapps/curriculum
63+
sudo -u ubuntu -g tomcat mkdir $CATALINA_HOME/webapps/studentuploads
64+
65+
echo "Installing Nginx"
66+
apt-get install nginx -y
67+
68+
echo "Adding Nginx www-data user to tomcat group"
69+
usermod -a -G tomcat www-data
70+
71+
echo "Downloading WISE Nginx config file"
72+
rm -f /etc/nginx/sites-enabled/*
73+
cp $BUILD_FILES/$env/wise.conf /etc/nginx/sites-enabled/wise.conf
74+
systemctl restart nginx
75+
76+
echo "Creating additional folders for WISE"
77+
mkdir -p $HOME/build-folder/WEB-INF/classes
78+
sudo -u ubuntu -g ubuntu mkdir $HOME/backup
79+
sudo -u ubuntu -g tomcat mkdir $HOME/googleTokens
80+
81+
echo "Downloading application.properties file"
82+
cp $BUILD_FILES/$env/application.properties $BUILD_DIR/WEB-INF/classes/application.properties
83+
84+
echo "Installing network drive package"
85+
apt-get install nfs-common -y
86+
87+
echo "Mounting network drive folders"
88+
cp $BUILD_FILES/$env/fstab /etc/fstab
89+
mount -a
90+
91+
echo "Downloading .vimrc file"
92+
sudo -u ubuntu -g ubuntu cp $BUILD_FILES/.vimrc $HOME/.vimrc
93+
94+
echo "Downloading text to append to .bashrc"
95+
cat $BUILD_FILES/append-to-bashrc.txt >> ~/.bashrc
96+
source ~/.bashrc
97+
98+
echo "Installing tree"
99+
apt-get install tree -y
100+
101+
echo "Downloading message of the day script to display notes"
102+
cp $BUILD_FILES/99-notes /etc/update-motd.d/99-notes
103+
chmod 755 /etc/update-motd.d/99-notes

scripts/setupWISE.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

scripts/updateWISE.sh

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)