diff --git a/deploy/aws/base-install.sh b/deploy/aws/base-install.sh new file mode 100755 index 0000000000..b3560c9daa --- /dev/null +++ b/deploy/aws/base-install.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +set -o errexit + +if [[ $EUID > 0 ]]; then + echo "Please run with sudo." >&2 + exit 1 +fi + +install_package() { + sudo apt-get -y update --quiet + sudo apt-get install -y ntp bc python3-pip --quiet + pip3 install boto3 + sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common virtualenv python3-setuptools --quiet + + # Installing docker + sudo apt-get -y --quiet install gnupg-agent + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - + sudo add-apt-repository \ + "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ + $(lsb_release -cs) \ + stable" + + sudo apt-get -y update --quiet + sudo apt-get -y install docker-ce docker-ce-cli containerd.io --quiet + + # Installing docker compose + if [ ! -f /usr/bin/docker-compose ];then + echo "Installing docker-compose" + sudo curl -L "https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker-compose + sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose + fi + +} + +install_package + +#Download boot.sh and schedule at boot time. +app_path="/home/ubuntu/appsmith" +script_path="script" +boot_script_path=$app_path/$script_path +boot_file_name="boot.sh" +config_ssl_file_name="configure-ssl.sh" +mkdir -p $boot_script_path +sudo chown -R ubuntu:ubuntu $app_path +cd $boot_script_path + +sudo curl -O https://raw.githubusercontent.com/appsmithorg/appsmith/release/deploy/configure-ssl.sh +sudo chown ubuntu:ubuntu $boot_script_path/$config_ssl_file_name && sudo chmod +x $boot_script_path/$config_ssl_file_name + +sudo curl -O https://raw.githubusercontent.com/appsmithorg/appsmith/feature/deploy-script/deploy/aws/boot.sh +sudo chown ubuntu:ubuntu $boot_script_path/$boot_file_name && sudo chmod +x $boot_script_path/$boot_file_name + +USER="ubuntu" +CRON_FILE="/var/spool/cron/crontabs/$USER" +echo "@reboot /bin/bash $boot_script_path/$boot_file_name" >> $CRON_FILE +sudo chmod 0600 $CRON_FILE diff --git a/deploy/aws/boot.sh b/deploy/aws/boot.sh new file mode 100755 index 0000000000..651629d053 --- /dev/null +++ b/deploy/aws/boot.sh @@ -0,0 +1,96 @@ +#!/bin/bash + +set -o errexit +# Check if Lock File exists, if not create it and set trap on exit +if { set -C; 2>/dev/null >/home/ubuntu/.appsmith.lock; }; then + trap "rm -f /home/ubuntu/.appsmith.lock" EXIT +else + exit +fi + +start_docker() { + if [ `sudo systemctl is-active docker.service` == "inactive" ];then + echo "Starting docker" + sudo systemctl start docker.service + fi +} + +# generate random string +generate_random_string() { + value=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1` + echo $value +} + +start_docker + +install_dir="/home/ubuntu/appsmith" + +if [ ! -d $install_dir ];then + mkdir -p $install_dir +fi +chown -R ubuntu:ubuntu $install_dir + +mongo_host="mongo" +mongo_database="appsmith" +mongo_root_user=$( generate_random_string ) +mongo_root_password=$( generate_random_string ) +user_encryption_password=$( generate_random_string ) +user_encryption_salt=$( generate_random_string ) + +custom_domain="" +NGINX_SSL_CMNT="" +if [[ -z $custom_domain ]]; then + NGINX_SSL_CMNT="#" +fi + +script_dir="/script" +mkdir -p "$install_dir/$script_dir" +chown -R ubuntu:ubuntu "$install_dir/$script_dir" + +cd $install_dir/$script_dir +mkdir -p template +cd template +echo $PWD +curl -O https://raw.githubusercontent.com/appsmithorg/appsmith/release/deploy/template/docker-compose.yml.sh +curl -O https://raw.githubusercontent.com/appsmithorg/appsmith/release/deploy/template/init-letsencrypt.sh.sh +curl -O https://raw.githubusercontent.com/appsmithorg/appsmith/release/deploy/template/mongo-init.js.sh +curl -O https://raw.githubusercontent.com/appsmithorg/appsmith/release/deploy/template/docker.env.sh +curl -O https://raw.githubusercontent.com/appsmithorg/appsmith/release/deploy/template/nginx_app.conf.sh +curl -O https://raw.githubusercontent.com/appsmithorg/appsmith/release/deploy/template/encryption.env.sh +cd .. +echo $PWD + +# Role - Folder +for directory_name in nginx certbot mongo/db opa/config +do + if [[ ! -d "$install_dir/data/$directory_name" ]];then + mkdir -p "$install_dir/data/$directory_name" + fi +done + +echo "Generating the configuration files from the templates" +. ./template/nginx_app.conf.sh +. ./template/docker-compose.yml.sh +. ./template/mongo-init.js.sh +. ./template/docker.env.sh +. ./template/encryption.env.sh + +declare -A fileInfo + +fileInfo[/data/nginx/app.conf.template]="nginx_app.conf" +fileInfo[/docker-compose.yml]="docker-compose.yml" +fileInfo[/data/mongo/init.js]="mongo-init.js" +fileInfo[/docker.env]="docker.env" +fileInfo[/encryption.env]="encryption.env" + +for f in ${!fileInfo[@]} +do + mv -f ${fileInfo[$f]} $install_dir/$f +done + +cd $install_dir +echo "Pull Images: $PWD" +sudo docker-compose pull + +echo "docker compose $PWD" +sudo docker-compose -f docker-compose.yml up -d --remove-orphans diff --git a/deploy/aws/configure-ssl.sh b/deploy/aws/configure-ssl.sh new file mode 100755 index 0000000000..e643fbbbef --- /dev/null +++ b/deploy/aws/configure-ssl.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -o errexit + +read -p 'Enter your domain / subdomain name (example.com / app.example.com): ' custom_domain + +NGINX_SSL_CMNT="" +install_dir="/home/ubuntu/appsmith" +TEMPLATE_PATH="$install_dir/script/template" + +. $TEMPLATE_PATH/nginx_app.conf.sh +. $TEMPLATE_PATH/init-letsencrypt.sh.sh + +chmod 0755 init-letsencrypt.sh + +mv -f app.conf $install_dir/data/nginx/app.conf +mv -f init-letsencrypt.sh $install_dir/init-letsencrypt.sh + +cd $install_dir +sudo ./init-letsencrypt.sh diff --git a/deploy/template/docker-compose.yml.sh b/deploy/template/docker-compose.yml.sh index 9012839ad2..9f00c285d1 100644 --- a/deploy/template/docker-compose.yml.sh +++ b/deploy/template/docker-compose.yml.sh @@ -4,7 +4,7 @@ if [ ! -f docker-compose.yml ]; then touch docker-compose.yml fi -cat > docker-compose.yml << EOF +cat >| docker-compose.yml << EOF version: "3.7" services: diff --git a/deploy/template/docker.env.sh b/deploy/template/docker.env.sh index 748cf7c986..88f0ca3451 100644 --- a/deploy/template/docker.env.sh +++ b/deploy/template/docker.env.sh @@ -4,7 +4,7 @@ if [ ! -f docker-compose.yml ]; then touch docker-compose.yml fi -cat > docker.env << EOF +cat >| docker.env << EOF # Read our documentation on how to configure these features # https://docs.appsmith.com/v/v1.1/enabling-3p-services diff --git a/deploy/template/encryption.env.sh b/deploy/template/encryption.env.sh index 78b449578e..27c64b9237 100644 --- a/deploy/template/encryption.env.sh +++ b/deploy/template/encryption.env.sh @@ -4,8 +4,8 @@ if [ ! -f encryption.env ]; then touch encryption.env fi -cat > encryption.env << EOF +cat >| encryption.env << EOF APPSMITH_ENCRYPTION_PASSWORD=$user_encryption_password APPSMITH_ENCRYPTION_SALT=$user_encryption_salt -EOF \ No newline at end of file +EOF diff --git a/deploy/template/init-letsencrypt.sh.sh b/deploy/template/init-letsencrypt.sh.sh index a723c992f9..095e6a6280 100755 --- a/deploy/template/init-letsencrypt.sh.sh +++ b/deploy/template/init-letsencrypt.sh.sh @@ -6,7 +6,7 @@ fi -cat > init-letsencrypt.sh << EOF +cat >| init-letsencrypt.sh << EOF #!/bin/bash if ! [ -x "\$(command -v docker-compose)" ]; then diff --git a/deploy/template/mongo-init.js.sh b/deploy/template/mongo-init.js.sh index ae9ae395c9..b88b0bfef9 100644 --- a/deploy/template/mongo-init.js.sh +++ b/deploy/template/mongo-init.js.sh @@ -6,7 +6,7 @@ fi -cat > mongo-init.js << EOF +cat >| mongo-init.js << EOF let error = false print("**** Going to start Mongo seed ****") diff --git a/deploy/template/nginx_app.conf.sh b/deploy/template/nginx_app.conf.sh index e543ff9f66..51c4f81010 100644 --- a/deploy/template/nginx_app.conf.sh +++ b/deploy/template/nginx_app.conf.sh @@ -5,7 +5,7 @@ if [ ! -f nginx_app.conf ]; then fi # This template file is different from the others because of the sub_filter commands in the Nginx configuration -# Those variables are substituted inside the Docker container for appsmith-editor during bootup. +# Those variables are substituted inside the Docker container for appsmith-editor during bootup. # Hence we wish to prevent environment substitution here. # Relevant variables will be replaced at the end of this file via sed command @@ -26,7 +26,7 @@ $NGINX_SSL_CMNT server_name $custom_domain ; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $host; - + location / { try_files $uri /index.html =404; @@ -49,7 +49,7 @@ $NGINX_SSL_CMNT server_name $custom_domain ; location /f { proxy_pass https://cdn.optimizely.com/; } - + location /api { proxy_pass http://appsmith-internal-server:8080; } @@ -101,7 +101,7 @@ $NGINX_SSL_CMNT $NGINX_SSL_CMNT location /f { $NGINX_SSL_CMNT proxy_pass https://cdn.optimizely.com/; $NGINX_SSL_CMNT } -$NGINX_SSL_CMNT +$NGINX_SSL_CMNT $NGINX_SSL_CMNT location /api { $NGINX_SSL_CMNT proxy_pass http://appsmith-internal-server:8080; $NGINX_SSL_CMNT } @@ -115,7 +115,7 @@ $NGINX_SSL_CMNT proxy_pass http://appsmith-internal-server:8080; $NGINX_SSL_CMNT } $NGINX_SSL_CMNT $NGINX_SSL_CMNT } -' > nginx_app.conf +' >| nginx_app.conf if [[ "$OSTYPE" == "darwin"* ]]; then sed -i '' "s/\$NGINX_SSL_CMNT/$NGINX_SSL_CMNT/g" nginx_app.conf @@ -123,4 +123,4 @@ if [[ "$OSTYPE" == "darwin"* ]]; then else sed -i "s/\$NGINX_SSL_CMNT/$NGINX_SSL_CMNT/g" nginx_app.conf sed -i "s/\$custom_domain/$custom_domain/g" nginx_app.conf -fi \ No newline at end of file +fi