From e8867f2ac71e9ee12d3def70483507721e0da63a Mon Sep 17 00:00:00 2001 From: Sneha Tilak Date: Wed, 25 Jan 2017 16:29:28 -0500 Subject: [PATCH] Adding script files --- appspec.yml | 14 +++++++++++ scripts/before-install.sh | 51 +++++++++++++++++++++++++++++++++++++++ scripts/install.sh | 5 ++++ 3 files changed, 70 insertions(+) create mode 100644 appspec.yml create mode 100644 scripts/before-install.sh create mode 100644 scripts/install.sh diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 0000000..b0cd890 --- /dev/null +++ b/appspec.yml @@ -0,0 +1,14 @@ +version: 0.0 +os: linux +files: + - source: / + destination: /home/ec2-user/laravel-portal +hooks: + BeforeInstall: + - location: scripts/before-install.sh + timeout: 3600 + runas: root + ApplicationStart: + - location: scripts/install.sh + timeout: 3600 + runas: root \ No newline at end of file diff --git a/scripts/before-install.sh b/scripts/before-install.sh new file mode 100644 index 0000000..8629390 --- /dev/null +++ b/scripts/before-install.sh @@ -0,0 +1,51 @@ +echo 'Update OS' +sudo yum -y update + +echo 'Check if PHP is installed' +php --version +if [ "$?" -ne 0 ]; then + sudo yum clean all + sudo yum -y update + sudo yum -y install epel-release + wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm + wget https://centos6.iuscommunity.org/ius-release.rpm + sudo rpm -Uvh ius-release*.rpm + sudo yum -y update + sudo yum -y install php56u php56u-opcache php56u-xml php56u-mcrypt php56u-gd php56u-devel php56u-mysql php56u-intl php56u-mbstring php56u-bcmath +fi + +echo 'Check if Laravel is installed' +cd /var/www/laravel-develop/ +if [ "$?" -ne 0 ]; then + curl -sS https://getcomposer.org/installer | php + sudo mv composer.phar /usr/local/bin/composer + chmod +x /usr/local/bin/composer + wget https://github.com/laravel/laravel/archive/develop.zip + unzip develop.zip + mv laravel-develop /var/www/ + sudo rm -rf develop.zip + cd /var/www/laravel-develop/ + composer install +fi + +echo 'Update Composer' +composer update + +echo 'Move back to ec2-user directory' +cd /home/ec2-user + +echo 'Check if Docker is installed' +docker -v +if [ "$?" -ne 0 ]; then + sudo yum install -y docker-io +fi + +echo 'Starting Docker services' +sudo service docker start + +echo 'Remove existing containers if any' +sudo docker ps -a | grep -w "laravel-container" | awk '{print $1}' | xargs --no-run-if-empty docker stop +sudo docker ps -a | grep -w "laravel-container" | awk '{print $1}' | xargs --no-run-if-empty docker rm + +echo 'Remove existing images if any' +sudo docker images | grep -w "laravel-image" | awk '{print $3}' | xargs --no-run-if-empty docker rmi -f \ No newline at end of file diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100644 index 0000000..26a7b04 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,5 @@ +echo 'Deploying Laravel Portal' +cd '/home/ec2-user/laravel-portal' + +echo 'Run Laravel' +php -S localhost:4000 \ No newline at end of file