Skip to content

Instantly share code, notes, and snippets.

@oktavianto
Last active September 27, 2019 14:08
Show Gist options
  • Save oktavianto/2db0a83c593f7454613b764e4cf81e0b to your computer and use it in GitHub Desktop.
Save oktavianto/2db0a83c593f7454613b764e4cf81e0b to your computer and use it in GitHub Desktop.
#!/bin/bash
cat << "EOF";
_ .-. _ .-.
:_; : : :_;.' `.
.-. .--. ,-.,-.: `-. .-.`. .'
: :' .; :: ,. :' .; :: : : :
:_;`.__.':_;:_;`.__.':_; :_;
Project Deploy Automation System
# Created by: Excel Dwi Oktavianto
# Github: https://github.com/oktavianto
# 27/09/2019
EOF
if ! [ $(id -u) = 0 ]; then
echo "\e[31m[-] Harus dijalankan menggunakan root. (atau pakai sudo)\e[0m"
exit 1
fi
read -p 'Project name: ' projectname
read -p 'Repository url: ' repourl
echo
echo "[+] Installing Docker compose.."
if ! [ -x "$(command -v docker-compose)" ]; then
sudo curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
echo "\e[32m[+] docker-compose berhasil di install.\e[0m"
else
echo "\e[32m[+] docker-compose sudah terinstall.\e[0m"
fi
echo
echo "[+] Clone Project.."
git clone $repourl $projectname
REPOFOLDER=$projectname
if [ -d "$REPOFOLDER" ]; then
cd $projectname
echo "\e[32m[+] $REPOFOLDER berhasil di clone!\e[0m"
else
cd $projectname
fi
echo
echo "[+] Configurating .env"
ENVFILE=.env.example
if [ -f "$ENVFILE" ]; then
echo
echo Setting up .env file
cp .env.example .env
echo "\e[32m[+] .env selesai!\e[0m"
else
echo "\e[31m[-] $FILE Tidak ditemukan!\e[0m"
exit 1
fi
# echo
# echo "[+] Running composser"
# docker run --rm -v $(pwd):/app composer install
# sudo chown -R $USER:$USER ~/$projectname
# echo "\e[32m[+] Composer selesai.\e[0m"
echo
echo "[+] Creating docker-compose.yml"
curl https://gist.githubusercontent.com/oktavianto/15e674b2c3a5a70482cda5fa40f41358/raw/1e99c254d2cae9e1534b997f97b917fc505b692c/docker-compose.yml -o docker-compose.yml
echo "\e[32m[+] docker-compose.yml selesai!\e[0m"
echo
echo "[+] Creating Dockerfile"
curl https://gist.githubusercontent.com/oktavianto/44f70c9b7fbf4edbf139fb319aeb762e/raw/015e4937673d6bd6cf16ca9c049152d3f04d3eb3/Dockerfile -o Dockerfile
echo "\e[32m[+] Dockerfile selesai!\e[0m"
echo
echo "[+] Creating php configuration"
echo "Example: 10M / 20M / 40"M
read -p 'upload_max_filesize= ' maxupload
read -p 'post_max_size= ' maxpost
sudo mkdir php
cat > php/local.ini << ENDOFFILE
upload_max_filesize=$maxupload
post_max_size=$maxpost
ENDOFFILE
echo "\e[32m[+] php configuration selesai!\e[0m"
echo
echo "[+] Configurating SSL (Lets encrypt)"
docker run --rm -it -v "/root/letsencrypt/log:/var/log/letsencrypt" -v "/var/www/html/$projectname:/var/www/" -v "/etc/letsencrypt:/etc/letsencrypt" -v "/root/letsencrypt/lib:/var/lib/letsencrypt" lojzik/letsencrypt certonly --webroot --webroot-path /var/www --email [email protected] -d $servername
echo "\e[32m[+] SSL Selesai!\e[0m"
echo
echo "[+] Configurating nginx"
sudo mkdir -p nginx/conf.d
read -p 'server_name (example: ionbit.id TANPA WWW) :' servername
read -p 'pakai www? www.$servername (Y/n)' pakaiwww
if [ "$pakaiwww" != "${pakaiwww#[Yy]}" ] ;then
cat > nginx/conf.d/app.conf << ENDOFFILE
server {
listen [::]:443 ssl;
listen 443 ssl;
server_name $servername www.$servername;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/$projectname/public;
ssl_certificate /etc/letsencrypt/live/$servername/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$servername/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
proxy_pass http://localhost:3000/;
}
}
ENDOFFILE
else
cat > nginx/conf.d/app.conf << ENDOFFILE
server {
listen [::]:443 ssl;
listen 443 ssl;
server_name $servername;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/$projectname/public;
ssl_certificate /etc/letsencrypt/live/$servername/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$servername/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
proxy_pass http://localhost:3000/;
}
}
ENDOFFILE
fi
echo "\e[32m[+] configurating nginx selesai!\e[0m"
echo
echo "[+] Running up docker-compose"
docker-compose up -d
echo "\e[32m[+] Running up selesai!\e[0m"
echo
echo "[+] Creating SSL Auto Renew"
if [ "$pakaiwww" != "${pakaiwww#[Yy]}" ] ;then
docker run -d
-e 'DOMAINS=$servername www.$servername'
-e [email protected]
-e NGINX_CONTAINER=nginx
-e SERVER_CONTAINER=nginx
-e CERTS_PATH=/etc/nginx/certs
-e WEBROOT_PATH=/var/www/$projectname
-e CHECK_FREQ=7
-v /var/run/docker.sock:/var/run/docker.sock
-v /etc/letsencrypt:/etc/letsencrypt
-v /var/lib/letsencrypt:/var/lib/letsencrypt
-v /tmp/letsencrypt:/var/www/$projectname
-v /etc/nginx/certs:/etc/nginx/certs
gordonchan/auto-letsencrypt
else
docker run -d
-e 'DOMAINS=$servername' \
-e [email protected] \
-e NGINX_CONTAINER=nginx \
-e SERVER_CONTAINER=nginx \
-e CERTS_PATH=/etc/nginx/certs \
-e WEBROOT_PATH=/var/www/$projectname \
-e CHECK_FREQ=7 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /etc/letsencrypt:/etc/letsencrypt \
-v /var/lib/letsencrypt:/var/lib/letsencrypt \
-v /tmp/letsencrypt:/var/www/$projectname \
-v /etc/nginx/certs:/etc/nginx/certs \
gordonchan/auto-letsencrypt
fi
echo "\e[32m[+] Auto Renew SSL Selesai!\e[0m"
echo
echo "[+] Running up laravel artisan"
docker-compose exec $projectname-app php artisan key:generate
docker-compose exec $projectname-app php artisan config:cache
docker-compose exec $projectname-app composer update
echo "\e[32m[+] running laravel artisan selesai!\e[0m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment