diff --git a/app/client/Dockerfile b/app/client/Dockerfile index d758b762ce..d273e15762 100644 --- a/app/client/Dockerfile +++ b/app/client/Dockerfile @@ -3,6 +3,8 @@ FROM nginx:1.17.9-alpine COPY ./build /var/www/appsmith EXPOSE 80 +# This is the default nginx template file inside the container. +# This is replaced by the install.sh script during a deployment COPY ./docker/templates/nginx-linux.conf.template /nginx.conf.template COPY ./docker/start-nginx.sh /start-nginx.sh CMD ["/start-nginx.sh"] diff --git a/app/client/docker/start-nginx.sh b/app/client/docker/start-nginx.sh index e4b1192492..b11c25ef5d 100755 --- a/app/client/docker/start-nginx.sh +++ b/app/client/docker/start-nginx.sh @@ -1,4 +1,4 @@ #!/bin/sh set -ue -cat /nginx.conf.template | envsubst "$(printf '$%s,' $(env | grep -Eo '^APPSMITH_[A-Z0-9_]+'))" | sed -e 's|\${\(APPSMITH_[A-Z0-9_]*\)}||g' | tee /etc/nginx/conf.d/app.conf +cat /nginx.conf.template | envsubst "$(printf '$%s,' $(env | grep -Eo '^APPSMITH_[A-Z0-9_]+'))" | sed -e 's|\${\(APPSMITH_[A-Z0-9_]*\)}||g' > /etc/nginx/conf.d/default.conf exec nginx -g 'daemon off;' diff --git a/deploy/install.sh b/deploy/install.sh index 1f54fc07bd..4e302d07b7 100755 --- a/deploy/install.sh +++ b/deploy/install.sh @@ -44,30 +44,70 @@ start_docker() { fi } +check_os() { + if [[ "$OSTYPE" == "darwin"* ]]; then + package_manager="brew" + desired_os=1 + return + fi + + os_name=`cat /etc/*-release | egrep "^NAME="` + os_name="${os_name#*=}" + echo $os_name + case "${os_name}" in + \"Ubuntu*\") + echo "In here" + desired_os=1 + package_manager="apt-get" + ;; + \"Red\ Hat*\") + desired_os=1 + package_manager="yum" + ;; + \"CentOS*\") + desired_os=1 + package_manager="yum" + ;; + *) desired_os=0 + esac +} + +overwrite_file() { + file_location=$1 + template_file=$2 + + if [ -f $install_dir/$file_location ] + then + read -p "File $file_location already exists. Would you like to replace it? [Y]: " value + value=${value:-Y} + + if [ $value == "Y" -o $value == "y" -o $value == "yes" -o $value == "Yes" ] + then + mv -f $template_file $install_dir/$file_location + echo "File $install_dir/$file_location replaced successfuly!" + else + echo "You chose not to replace existing file: $install_dir/$file_location" + rm -rf $template_file + echo "File $template_file removed from source directory." + echo "" + fi + else + mv -f $template_file $install_dir/$file_location + fi +} + echo -e "\U1F44B Thank you for trying out Appsmith! " echo "" -declare -A osInfo; - -osInfo[/etc/debian_version]="apt-get" -osInfo[/etc/centos-release]="yum" -osInfo[/etc/redhat-release]="yum" -osInfo[/System/Library/CoreServices/SystemVersion.plist]="brew" # Checking OS and assiging package manager desired_os=0 echo -e "\U1F575 Detecting your OS" +check_os echo "" -for f in ${!osInfo[@]} -do - if [[ -f $f ]];then - package_manager=${osInfo[$f]} - desired_os=1 - fi -done if [[ $desired_os -eq 0 ]];then - echo "This script is currently meant to install Appsmith on Ubuntu | RHEL | CentOS machines." + echo "This script is currently meant to install Appsmith on Mac OS X | Ubuntu | RHEL | CentOS machines." echo "Please contact hello@appsmith.com with your OS details if you wish to extend this support" echo -e "Exiting for now. Bye! \U1F44B" exit @@ -82,6 +122,7 @@ echo "1) Automatically setup mongo db on this instance (recommended)" echo "2) Connect to an external mongo db" read -p 'Enter option number [1]: ' mongo_option mongo_option=${mongo_option:-1} +echo "" if [[ $mongo_option -eq 2 ]];then read -p 'Enter your mongo db host: ' mongo_host @@ -95,7 +136,7 @@ elif [[ $mongo_option -eq 1 ]];then read -sp 'Set the mongo password: ' mongo_root_password fi echo "" - +echo "" echo "Appsmith needs password and salt to encrypt sensitive information" encryptionEnv=./template/encryption.env if test -f "$encryptionEnv"; then @@ -104,6 +145,7 @@ if test -f "$encryptionEnv"; then echo "2) Yes. Overwrite the existing encryption (NOT SUGGESTED)" read -p 'Enter option number [1]: ' overwrite_encryption overwrite_encryption=${overwrite_encryption:-1} + echo "" if [[ $overwrite_encryption -eq 1 ]];then setup_encryption="false" @@ -119,8 +161,8 @@ if [[ "$setup_encryption" = "true" ]];then echo "2) Set up your own salt and password" read -p 'Enter option number [1]: ' encryption_option encryption_option=${encryption_option:-1} - if [[ $encryption_option -eq 2 ]];then + echo "" read -p 'Enter your encryption password: ' user_encryption_password read -p 'Enter your encryption salt: ' user_encryption_salt elif [[ $encryption_option -eq 1 ]];then @@ -155,14 +197,14 @@ if [[ -z $custom_domain ]]; then fi mkdir -p template -cd template +( cd template 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 .. +) # Role - Docker if ! is_command_present docker ;then @@ -180,7 +222,7 @@ if [ $package_manager == "yum" -o $package_manager == "apt-get" ];then fi # Role - Folder -for directory_name in nginx certbot mongo/db opa/config appsmith-server/config +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" @@ -195,45 +237,18 @@ echo "Generating the configuration files from the templates" . ./template/docker.env.sh if [[ "$setup_encryption" = "true" ]];then . ./template/encryption.env.sh -fi +fi chmod 0755 init-letsencrypt.sh -declare -A fileInfo - -fileInfo[/data/nginx/app.conf]="nginx_app.conf" -fileInfo[/docker-compose.yml]="docker-compose.yml" -fileInfo[/data/mongo/init.js]="mongo-init.js" -fileInfo[/init-letsencrypt.sh]="init-letsencrypt.sh" -fileInfo[/docker.env]="docker.env" -fileInfo[/encryption.env]="encryption.env" - -for f in ${!fileInfo[@]} -do - - if [ -f $install_dir/$f ] - then - read -p "File $f already exist. Would you like to replace it? [Y]: " value - - if [ $value == "Y" -o $value == "y" -o $value == "yes" -o $value == "Yes" ] - then - mv -f ${fileInfo[$f]} $install_dir$f - echo "File $install_dir$f replaced succeffuly!" - else - echo "You choose not to replae existing file: $install_dir$f" - rm -rf ${fileInfo[$f]} - echo "File ${fileInfo[$f]} removed from source directory." - echo "" - fi - else - mv -f ${fileInfo[$f]} $install_dir$f - fi - -done - +overwrite_file "/data/nginx/app.conf.template" "nginx_app.conf" +overwrite_file "/docker-compose.yml" "docker-compose.yml" +overwrite_file "/data/mongo/init.js" "mongo-init.js" +overwrite_file "/init-letsencrypt.sh" "init-letsencrypt.sh" +overwrite_file "/docker.env" "docker.env" +overwrite_file "/encryption.env" "encryption.env" echo "" -#echo "Running init-letsencrypt.sh...." cd $install_dir if [[ ! -z $custom_domain ]]; then echo "Running init-letsencrypt.sh...." diff --git a/deploy/template/docker-compose.yml.sh b/deploy/template/docker-compose.yml.sh index 5d041463b8..9012839ad2 100644 --- a/deploy/template/docker-compose.yml.sh +++ b/deploy/template/docker-compose.yml.sh @@ -1,14 +1,9 @@ #!/bin/sh -if [ -f docker-compose.yml ] - then - echo "file docker-compose.yml already exists" - else +if [ ! -f docker-compose.yml ]; then touch docker-compose.yml fi - - cat > docker-compose.yml << EOF version: "3.7" @@ -20,10 +15,10 @@ services: - "80:80" - "443:443" volumes: - - ./data/nginx:/etc/nginx/conf.d + - ./data/nginx/app.conf.template:/nginx.conf.template - ./data/certbot/conf:/etc/letsencrypt - ./data/certbot/www:/var/www/certbot - command: "/bin/sh -c 'while :; do sleep 6h & wait \$\${!}; nginx -s reload; done & nginx -g \"daemon off;\"'" + command: "/bin/sh -c 'while :; do sleep 6h & wait \$\${!}; nginx -s reload; done & /start-nginx.sh'" depends_on: - appsmith-internal-server networks: diff --git a/deploy/template/docker.env.sh b/deploy/template/docker.env.sh index bd88fefb2e..7847c5ee01 100644 --- a/deploy/template/docker.env.sh +++ b/deploy/template/docker.env.sh @@ -1,9 +1,6 @@ #!/bin/sh -if [ -f docker-compose.yml ] - then - echo "file docker-compose.yml already exists" - else +if [ ! -f docker-compose.yml ]; then touch docker-compose.yml fi diff --git a/deploy/template/encryption.env.sh b/deploy/template/encryption.env.sh index 8050492b26..78b449578e 100644 --- a/deploy/template/encryption.env.sh +++ b/deploy/template/encryption.env.sh @@ -1,9 +1,6 @@ #!/bin/sh -if [ -f encryption.env ] - then - echo "file encryption.env already exists" - else +if [ ! -f encryption.env ]; then touch encryption.env fi diff --git a/deploy/template/init-letsencrypt.sh.sh b/deploy/template/init-letsencrypt.sh.sh index 3f41c3ad5d..a723c992f9 100755 --- a/deploy/template/init-letsencrypt.sh.sh +++ b/deploy/template/init-letsencrypt.sh.sh @@ -1,9 +1,6 @@ #!/bin/sh -if [ -f init-letsencrypt.sh ] - then - echo "file init-letsencrypt.sh already exists" - else +if [ ! -f init-letsencrypt.sh ]; then touch init-letsencrypt.sh fi diff --git a/deploy/template/mongo-init.js.sh b/deploy/template/mongo-init.js.sh index f765e9db19..ae9ae395c9 100644 --- a/deploy/template/mongo-init.js.sh +++ b/deploy/template/mongo-init.js.sh @@ -1,9 +1,6 @@ #!/bin/sh -if [ -f mongo-init.js ] - then - echo "file docker-compose.yml already exists" - else +if [ ! -f mongo-init.js ]; then touch mongo-init.js fi diff --git a/deploy/template/nginx_app.conf.sh b/deploy/template/nginx_app.conf.sh index f71af0f66e..0c8ed7fb96 100644 --- a/deploy/template/nginx_app.conf.sh +++ b/deploy/template/nginx_app.conf.sh @@ -1,15 +1,15 @@ #!/bin/sh -if [ -f nginx_app.conf ] - then - echo "file nginx_app.conf already exists" - else +if [ ! -f nginx_app.conf ]; then touch nginx_app.conf 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. +# Hence we wish to prevent environment substitution here. +# Relevant variables will be replaced at the end of this file via sed command - -cat > nginx_app.conf << EOF +echo ' server { listen 80; $NGINX_SSL_CMNT server_name $custom_domain ; @@ -20,10 +20,6 @@ $NGINX_SSL_CMNT server_name $custom_domain ; root /var/www/appsmith; index index.html index.htm; - #location / { - # return 301 https://\$host\$request_uri; - #} - location /.well-known/acme-challenge/ { root /var/www/certbot; } @@ -33,6 +29,21 @@ $NGINX_SSL_CMNT server_name $custom_domain ; location / { try_files \$uri /index.html =404; + + sub_filter __APPSMITH_SENTRY_DSN__ '\''${APPSMITH_SENTRY_DSN}'\''; + sub_filter __APPSMITH_APPSMITH_HOTJAR_HJID__ '\''${APPSMITH_HOTJAR_HJID}'\''; + sub_filter __APPSMITH_HOTJAR_HJSV__ '\''${APPSMITH_HOTJAR_HJSV}'\''; + sub_filter __APPSMITH_OAUTH2_GOOGLE_CLIENT_ID__ '\''${APPSMITH_OAUTH2_GOOGLE_CLIENT_ID}'\''; + sub_filter __APPSMITH_OAUTH2_GITHUB_CLIENT_ID__ '\''${APPSMITH_OAUTH2_GITHUB_CLIENT_ID}'\''; + sub_filter __APPSMITH_MARKETPLACE_URL__ '\''${APPSMITH_MARKETPLACE_URL}'\''; + sub_filter __APPSMITH_SEGMENT_KEY__ '\''${APPSMITH_SEGMENT_KEY}'\''; + sub_filter __APPSMITH_OPTIMIZELY_KEY__ '\''${APPSMITH_OPTIMIZELY_KEY}'\''; + sub_filter __APPSMITH_ALGOLIA_API_ID__ '\''${APPSMITH_ALGOLIA_API_ID}'\''; + sub_filter __APPSMITH_ALGOLIA_SEARCH_INDEX_NAME__ '\''${APPSMITH_ALGOLIA_SEARCH_INDEX_NAME}'\''; + sub_filter __APPSMITH_ALGOLIA_API_KEY__ '\''${APPSMITH_ALGOLIA_API_KEY}'\''; + sub_filter __APPSMITH_CLIENT_LOG_LEVEL__ '\''${APPSMITH_CLIENT_LOG_LEVEL}'\''; + sub_filter __APPSMITH_GOOGLE_MAPS_API_KEY__ '\''${APPSMITH_GOOGLE_MAPS_API_KEY}'\''; + sub_filter __APPSMITH_TNC_PP__ '\''${APPSMITH_TNC_PP}'\''; } location /f { @@ -66,6 +77,21 @@ $NGINX_SSL_CMNT index index.html index.htm; $NGINX_SSL_CMNT $NGINX_SSL_CMNT location / { $NGINX_SSL_CMNT try_files \$uri /index.html =404; +$NGINX_SSL_CMNT +$NGINX_SSL_CMNT sub_filter __APPSMITH_SENTRY_DSN__ '\''${APPSMITH_SENTRY_DSN}'\''; +$NGINX_SSL_CMNT sub_filter __APPSMITH_APPSMITH_HOTJAR_HJID__ '\''${APPSMITH_HOTJAR_HJID}'\''; +$NGINX_SSL_CMNT sub_filter __APPSMITH_HOTJAR_HJSV__ '\''${APPSMITH_HOTJAR_HJSV}'\''; +$NGINX_SSL_CMNT sub_filter __APPSMITH_OAUTH2_GOOGLE_CLIENT_ID__ '\''${APPSMITH_OAUTH2_GOOGLE_CLIENT_ID}'\''; +$NGINX_SSL_CMNT sub_filter __APPSMITH_OAUTH2_GITHUB_CLIENT_ID__ '\''${APPSMITH_OAUTH2_GITHUB_CLIENT_ID}'\''; +$NGINX_SSL_CMNT sub_filter __APPSMITH_MARKETPLACE_URL__ '\''${APPSMITH_MARKETPLACE_URL}'\''; +$NGINX_SSL_CMNT sub_filter __APPSMITH_SEGMENT_KEY__ '\''${APPSMITH_SEGMENT_KEY}'\''; +$NGINX_SSL_CMNT sub_filter __APPSMITH_OPTIMIZELY_KEY__ '\''${APPSMITH_OPTIMIZELY_KEY}'\''; +$NGINX_SSL_CMNT sub_filter __APPSMITH_ALGOLIA_API_ID__ '\''${APPSMITH_ALGOLIA_API_ID}'\''; +$NGINX_SSL_CMNT sub_filter __APPSMITH_ALGOLIA_SEARCH_INDEX_NAME__ '\''${APPSMITH_ALGOLIA_SEARCH_INDEX_NAME}'\''; +$NGINX_SSL_CMNT sub_filter __APPSMITH_ALGOLIA_API_KEY__ '\''${APPSMITH_ALGOLIA_API_KEY}'\''; +$NGINX_SSL_CMNT sub_filter __APPSMITH_CLIENT_LOG_LEVEL__ '\''${APPSMITH_CLIENT_LOG_LEVEL}'\''; +$NGINX_SSL_CMNT sub_filter __APPSMITH_GOOGLE_MAPS_API_KEY__ '\''${APPSMITH_GOOGLE_MAPS_API_KEY}'\''; +$NGINX_SSL_CMNT sub_filter __APPSMITH_TNC_PP__ '\''${APPSMITH_TNC_PP}'\''; $NGINX_SSL_CMNT } $NGINX_SSL_CMNT $NGINX_SSL_CMNT location /f { @@ -81,4 +107,7 @@ $NGINX_SSL_CMNT proxy_pass http://appsmith-internal-server:8080; $NGINX_SSL_CMNT } $NGINX_SSL_CMNT $NGINX_SSL_CMNT } -EOF +' > nginx_app.conf + +sed -in "s/\$NGINX_SSL_CMNT/$NGINX_SSL_CMNT/g" nginx_app.conf +sed -in "s/\$custom_domain/$custom_domain/g" nginx_app.conf \ No newline at end of file