Last active
March 9, 2020 00:20
-
-
Save djravine/adb8821a49621fb6c8306c4882767018 to your computer and use it in GitHub Desktop.
Provision script to setup laravel on Ubuntu with mock members.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -xuo pipefail | |
# GIST: https://gist.github.com/djravine/adb8821a49621fb6c8306c4882767018 | |
# USAGE: ssh -i ~/.ssh/${KEYNAME} -t -p 22 ubuntu@${EC2_IP} 'curl -sL https://gist.githubusercontent.com/djravine/adb8821a49621fb6c8306c4882767018/raw | sudo bash -s -- ${GIT_REPO_URL}' | |
# LARAVEL BOOTSTRAP | |
laravel_bootstrap () { | |
# INSTALL MYSQL-SERVER | |
sudo apt-get install -y mysql-server | |
# SETUP MYSQL | |
sudo mysql << END | |
CREATE DATABASE IF NOT EXISTS laravel; | |
CREATE USER IF NOT EXISTS 'laravel'@'%' IDENTIFIED BY 'laravel'; | |
GRANT ALL PRIVILEGES ON laravel.* TO 'laravel'@'%'; | |
FLUSH PRIVILEGES; | |
END | |
# IMPORT MOCK MEMBER DATA | |
curl -sL https://intellipharm-techchallenge.s3-ap-southeast-2.amazonaws.com/members.sql > /development/members.sql | |
sudo mysql laravel < /development/members.sql | |
# UPDATE .env | |
cat << 'EOF' >> .env | |
APP_NAME=Laravel | |
APP_ENV=local | |
APP_KEY= | |
APP_DEBUG=true | |
APP_URL=http://localhost | |
LOG_CHANNEL=stack | |
DB_CONNECTION=mysql | |
DB_HOST=127.0.0.1 | |
DB_PORT=3306 | |
DB_DATABASE=laravel | |
DB_USERNAME=laravel | |
DB_PASSWORD=laravel | |
BROADCAST_DRIVER=log | |
CACHE_DRIVER=file | |
QUEUE_CONNECTION=sync | |
SESSION_DRIVER=file | |
SESSION_LIFETIME=120 | |
REDIS_HOST=127.0.0.1 | |
REDIS_PASSWORD=null | |
REDIS_PORT=6379 | |
MAIL_DRIVER=smtp | |
MAIL_HOST=smtp.mailtrap.io | |
MAIL_PORT=2525 | |
MAIL_USERNAME=null | |
MAIL_PASSWORD=null | |
MAIL_ENCRYPTION=null | |
MAIL_FROM_ADDRESS=null | |
MAIL_FROM_NAME="${APP_NAME}" | |
AWS_ACCESS_KEY_ID= | |
AWS_SECRET_ACCESS_KEY= | |
AWS_DEFAULT_REGION=us-east-1 | |
AWS_BUCKET= | |
PUSHER_APP_ID= | |
PUSHER_APP_KEY= | |
PUSHER_APP_SECRET= | |
PUSHER_APP_CLUSTER=mt1 | |
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" | |
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" | |
EOF | |
# LARAVEL APP SETUP | |
composer install | |
php artisan key:generate | |
php artisan migrate --force | |
# LARAVEL KILL EXISTING | |
kill $(ps aux | grep '[p]hp' | awk '{print $2}') | |
# LARAVEL SERVE | |
sudo nohup php artisan serve --host=0.0.0.0 --port=80 & | |
ps aux | grep php | |
# TO VIEW | |
ps aux | grep '[p]hp' | |
# TO KILL | |
# sudo kill $(ps aux | grep '[p]hp' | awk '{print $2}') | |
} | |
# LARAVEL DOCKER BOOTSTRAP | |
laravel_docker_bootstrap () { | |
# DOCKER SETUP | |
sudo apt-get install -y docker.io | |
sudo usermod -aG docker $USER | |
# DOCKER-COMPOSE SETUP | |
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | |
sudo chmod +x /usr/local/bin/docker-compose | |
# DOCKER START | |
newgrp docker << END | |
docker-compose up -d | |
END | |
# TO VIEW | |
docker ps | |
# TO KILL | |
# docker stop | |
} | |
# ARGUMENTS | |
GIT_REPO=${1} | |
GIT_BASE=$(basename $GIT_REPO) | |
GIT_FOLDER=${GIT_BASE%.*} | |
# INSTALL | |
sudo apt-get update | |
sudo apt-get install -y curl unzip wget zip php7.2-cli php7.2-common php7.2-curl php7.2-mbstring php7.2-zip php7.2-xml php7.2-mysql | |
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer | |
sudo chmod +x /usr/local/bin/composer | |
sudo chown -R $USER:$USER ~/.composer | |
composer global require hirak/prestissimo | |
composer global require laravel/installer | |
# SETUP FOLDERS | |
sudo mkdir -p /development | |
sudo chown $USER:$USER /development | |
cd /development | |
# GIT CLONE | |
if [ ! -d "$GIT_FOLDER" ]; then | |
git clone $GIT_REPO | |
cd $GIT_FOLDER | |
else | |
cd $GIT_FOLDER | |
git pull | |
fi | |
ls -al | |
# CHECK FOR 'app' FOLDER | |
if [ -d "app" ]; then | |
if [ ! -f "docker-compose.yml" ]; then | |
laravel_bootstrap | |
else | |
laravel_docker_bootstrap | |
fi | |
else | |
# CHECK SUB-FOLDERS FOR 'app' | |
for dir in *; do | |
if [ -d $dir ]; then | |
if [ -d $dir/app ]; then | |
cd $dir | |
if [ ! -f "docker-compose.yml" ]; then | |
laravel_bootstrap | |
else | |
laravel_docker_bootstrap | |
fi | |
break | |
fi | |
fi | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment