From c21d26fa36b2dffc14f1c045c004c1bf25eb068f Mon Sep 17 00:00:00 2001 From: "Chinmay D. Pai" Date: Mon, 2 Mar 2020 23:47:13 +0530 Subject: [PATCH 1/5] chore: remove redundant docker-compose Signed-off-by: Chinmay D. Pai --- docker-compose.yml | 80 --------------- frappe-installer | 250 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 250 insertions(+), 80 deletions(-) delete mode 100644 docker-compose.yml create mode 100755 frappe-installer diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index a24d2283..00000000 --- a/docker-compose.yml +++ /dev/null @@ -1,80 +0,0 @@ -version: '3.7' -services: - mariadb: - image: mariadb - - environment: - - MYSQL_ROOT_PASSWORD=123 - - MYSQL_USER=root - - volumes: - - ./conf/mariadb-conf.d:/etc/mysql/conf.d - - /var/lib/mysql - - ports: - - "3307:3306" # MariaDB Port - - container_name: mariadb - - redis-cache: - image: redis:alpine - - volumes: - - ./conf/redis-conf.d:/etc/conf.d - - command: ["redis-server","/etc/conf.d/redis_cache.conf"] - - container_name: redis-cache - - redis-queue: - image: redis:alpine - - - volumes: - - ./conf/redis-conf.d:/etc/conf.d - - command: ["redis-server","/etc/conf.d/redis_queue.conf"] - - container_name: redis-queue - - redis-socketio: - image: redis:alpine - - volumes: - - ./conf/redis-conf.d:/etc/conf.d - - command: ["redis-server","/etc/conf.d/redis_socketio.conf"] - - container_name: redis-socketio - - - frappe: - build: . - - volumes: - - ./frappe-bench:/home/frappe/frappe-bench - - ./conf/redis-conf.d/redis_cache.conf:/home/frappe/frappe-bench/config/redis_cache.conf - - ./conf/redis-conf.d/redis_queue.conf:/home/frappe/frappe-bench/config/redis_queue.conf - - ./conf/redis-conf.d/redis_socketio.conf:/home/frappe/frappe-bench/config/redis_socketio.conf - - ports: - - "8000:8000" # Webserver Port - - "9000:9000" # Socketio Port - - "6787:6787" # File Watcher Port - - stdin_open: true - tty: true - - links: - - redis-cache - - redis-queue - - redis-socketio - - mariadb - - depends_on: - - mariadb - - redis-cache - - redis-queue - - redis-socketio - - container_name: frappe diff --git a/frappe-installer b/frappe-installer new file mode 100755 index 00000000..13436afd --- /dev/null +++ b/frappe-installer @@ -0,0 +1,250 @@ +#!/usr/bin/env bash + +set -euo pipefail +IFS=$'\n\t' + +[ -z "$DEBUG" ] & [ "${DEBUG}" == 1 ] && set -o xtrace + + +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$__dir" + +env_url="https://raw.githubusercontent.com/frappe/frappe_docker/master/installation/env-example" +docker_nginx_url="https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion" +frappe_docker_url="https://github.com/frappe/frappe_docker" +env_file="$__dir/.env" + + +check_root() { + if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root. Login as root or use sudo." 1>&2 + exit 1 + fi +} + +check_git() { + if [ ! -x "$(command -v git)" ]; then + echo "Git is not installed. Please install git before continuing." + exit 1 + fi +} + +check_docker() { + if [ ! -x "$(command -v docker)" ]; then + read -rp "No docker installation found. Press Enter to install docker or ctrl+c to exit." + curl -fsSL https://get.docker.com | sh + fi + if [ ! -x "$(command -v docker)" ]; then + echo "Docker installation failed. Exiting." + exit 1 + fi +} + +check_env() { + if [ ! -f "$env_file" ]; then + echo "No environment file found. This file is required for setting up Frappe/ERPNext Docker." + echo "Would you like to fetch the default environment file?" + echo "(NOTE: You will be prompted to set it up later)" + read -rp "Press Enter to fetch the configuration file, or create a .env file and re-run the script." + curl -fsSL "$env_url" -o "$env_file" + fi +} + +clone_repository() { + echo "Cloning Repository: $1" + git clone "$2" +} + +get_config() { + if [ -n "$2" ]; then + config_file="$2" + else + config_file="$env_file" + fi + line=$(grep -E "^$=" "$config_file") + line_result=$(echo "$line" | awk -F"=" '{print $2}') +} + +get_install_version() { + echo "Choose a version you would like to setup [current: $1]:" + echo "1. develop (edge)" + echo "2. version-12" + echo "3. version-11" + echo "Please enter your choice [1-3]: " + select choice in "1" "2" "3"; do + case $choice in + 1 ) version="edge" ;; + 2 ) version="version-12" ;; + 3 ) version="version-11" ;; + esac + done +} + +prompt_config() { + # inspired by discourse_docker + get_config "VERSION" + local install_version=$line_result + get_config "MYSQL_ROOT_PASSWORD" + local mysql_password=$line_result + get_config "SITES" + local sites=$line_result + get_config "LETSENCRYPT_EMAIL" + local letsencrypt_email=$line_result + + echo "Would you like to setup networking for docker? [y/n]" + echo "This is required if you wish to access the instance from other machines." + select choice in "y" "n"; do + case $choice in + y ) setup_networking=1 ;; + n ) setup_networking=0 + setup_letsencrypt=0 ;; + esac + done + if [ -n "$letsencrypt_email" ] & [ "$setup_networking" -ne "0" ]; then + echo "Would you like to setup LetsEncrypt? [y/n]" + select choice in "y" "n"; do + case $choice in + y ) setup_letsencrypt=1 + echo "Please ensure that all the required domains point to this IP address." + read -rp "Enter an Email Address to setup LetsEncrypt with: " letsencrypt_email ;; + n ) setup_letsencrypt=0 + echo "Skipping LetsEncrypt Setup." ;; + esac + done + fi + + local new_value="" + local config_state="n" + + echo + + get_install_version "$install_version" + install_version="$version" + + while [ "$config_state" = "n" ]; do + if [ -n "$mysql_password" ]; then + read -srp "Enter MySQL Password [$mysql_password]: " new_value + if [ -n "$new_value" ]; then + mysql_password="$new_value" + fi + fi + + if [ -n "$sites" ]; then + read -rp "Enter sitename to setup [$sites]: " new_value + if [ -n "$new_value" ]; then + sites="$new_value" + fi + fi + + if [ "$setup_letsencrypt" -ne "0" ]; then + read -rp "Enter email address for LetsEncrypt [$letsencrypt_email]: " new_value + if [ -n "$new_value" ]; then + letsencrypt_email=$new_value + fi + fi + + echo "Current Configuration:" + echo "Version: $([ "$install_version" = "edge" ] && echo "develop" || echo "$install_version")" + echo "MySQL Root Password: $mysql_password" + echo "Sites: $sites" + + if [ "$setup_letsencrypt" -ne "0" ]; then + echo "LetsEncrypt Email Address: $letsencrypt_email" + fi + + echo + echo "Does this configuration look okay?" + read -rp "Press Enter to continue, 'n' to try again, or ctrl+c to exit: " config_state + done + + echo "Saving the current configuration file to $env_file" + + cat << EOF > "$env_file" +VERSION=$install_version +MYSQL_ROOT_PASSWORD=$mysql_password +SITES=$sites +$([ "$setup_letsencrypt" -ne "0" ] && echo "LETSENCRYPT_EMAIL=$letsencrypt_email") +EOF + setup_configuration=$(<"$env_file") +} + +setup_user() { + echo "The rest of the setup requires a user account." + echo "You may use an existing account, or set up a new one right away." + read -rp "Enter username: " username + if grep -E "^$username" /etc/passwd > /dev/null; then + echo "User $username already exists." + else + read -rsp "Enter password: " password + password="$(perl -e 'print crypt($ARGV[0], "password")' "$password")" + if useradd -m -p "$password" "$username" -s "$(command -v bash)"; then + echo "User $username has been added to the system." + else + echo "Failed to add user to the system." + echo "Please add a user manually and re-run the script." + exit 1 + fi + fi + + if ! getent group docker > /dev/null 2>&1 ; then + echo "Creating group: docker" + groupadd docker + fi + echo "Adding user $username to group: docker" + usermod -aG docker "$username" + newgrp docker +} + +install() { + if [ "$setup_letsencrypt" -ne "0" ] & [ "$setup_networking" -ne "0" ]; then + echo "Setting up NGINX Proxy for LetsEncrypt" + clone_repository "Docker Compose LetsEncrypt NGINX Proxy Companion" "$docker_nginx_url" + cd "$(basename "$docker_nginx_url")" + if [ -f .env.sample ]; then + cp .env.sample env + fi + ./start.sh > /dev/null 2>&1 + cd "$(eval echo ~"$username")" + fi + + echo "Setting up Frappe/ERPNext" + clone_repository "Frappe/ERPNext Docker" "$frappe_docker_url" + cd "$(basename "$frappe_docker_url")" + echo "$setup_configuration" > .env + echo "Enter a name for the project." + read -rp "This project name will be used to setup the docker instance: [erpnext_docker]" project_name + if [ -z "$project_name" ]; then + echo "Setting the project name to erpnext_docker" + project_name="erpnext_docker" + fi + + docker-compose \ + --project-name "$project_name" \ + --project-directory . up -d \ + -f installation/docker-compose-frappe.yml \ + -f installation/docker-compose-erpnext.yml \ + -f installation/docker-compose-common.yml \ + "$( (( setup_networking == 1 )) && printf %s '-f installation/docker-compose-networks.yml' )" + + get_config "SITES" "$(pwd)/.env" + local sites=$line_result + + docker exec \ + -e "SITE_NAME=$sites" \ + -e "INSTALL_ERPNEXT=1" \ + -it "$project_name"_erpnext-python_1 docker-entrypoint.sh new + + echo "Installation Complete!" +} + +check_root +check_git +check_docker +check_env + +prompt_config +setup_user + +su - "$username" << EOF +install +EOF From 501d14472896c5e0658ab66e1807cf1cec127a3b Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Wed, 4 Mar 2020 14:36:13 +0530 Subject: [PATCH 2/5] fix: worker images new site command install apps is a list not boolean --- build/common/commands/new.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/common/commands/new.py b/build/common/commands/new.py index b87641db..973a6245 100644 --- a/build/common/commands/new.py +++ b/build/common/commands/new.py @@ -6,7 +6,7 @@ site_name = os.environ.get("SITE_NAME", 'site1.localhost') mariadb_root_username = os.environ.get("DB_ROOT_USER", 'root') mariadb_root_password = os.environ.get("MYSQL_ROOT_PASSWORD", 'admin') force = True if os.environ.get("FORCE", None) else False -install_apps = ['erpnext'] if os.environ.get("INSTALL_ERPNEXT", None) else False +install_apps = ['erpnext'] if os.environ.get("INSTALL_ERPNEXT", None) else [] frappe.init(site_name, new_site=True) _new_site( From 922877bf9269f6cfcf36b7fee7ade55df15306d5 Mon Sep 17 00:00:00 2001 From: Davide Bortolami Date: Wed, 4 Mar 2020 14:15:25 +0000 Subject: [PATCH 3/5] Fixes #101 Nginx will now wait up to 10 seconds for frappe-python and frappe-socketio to be available --- build/erpnext-assets/docker-entrypoint.sh | 7 +++++++ build/frappe-assets/docker-entrypoint.sh | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/build/erpnext-assets/docker-entrypoint.sh b/build/erpnext-assets/docker-entrypoint.sh index 4919fb34..2774a9f4 100755 --- a/build/erpnext-assets/docker-entrypoint.sh +++ b/build/erpnext-assets/docker-entrypoint.sh @@ -37,4 +37,11 @@ envsubst '${API_HOST} ${SOCKETIO_PORT}' \ < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf +echo "Waiting for frappe-python to be available on $FRAPPE_PY port $FRAPPE_PY_PORT" +timeout 10 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/$0/$1; do sleep 1; done' $FRAPPE_PY $FRAPPE_PY_PORT +echo "Frappe-python available on $FRAPPE_PY port $FRAPPE_PY_PORT" +echo "Waiting for frappe-socketio to be available on $FRAPPE_PY port $FRAPPE_PY_PORT" +timeout 10 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/$0/$1; do sleep 1; done' $FRAPPE_SOCKETIO $SOCKETIO_PORT +echo "Frappe-socketio available on $FRAPPE_PY port $FRAPPE_PY_PORT" + exec "$@" diff --git a/build/frappe-assets/docker-entrypoint.sh b/build/frappe-assets/docker-entrypoint.sh index f68e7fd3..6603aad9 100755 --- a/build/frappe-assets/docker-entrypoint.sh +++ b/build/frappe-assets/docker-entrypoint.sh @@ -36,4 +36,11 @@ envsubst '${API_HOST} ${SOCKETIO_PORT}' \ < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf +echo "Waiting for frappe-python to be available on $FRAPPE_PY port $FRAPPE_PY_PORT" +timeout 10 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/$0/$1; do sleep 1; done' $FRAPPE_PY $FRAPPE_PY_PORT +echo "Frappe-python available on $FRAPPE_PY port $FRAPPE_PY_PORT" +echo "Waiting for frappe-socketio to be available on $FRAPPE_PY port $FRAPPE_PY_PORT" +timeout 10 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/$0/$1; do sleep 1; done' $FRAPPE_SOCKETIO $SOCKETIO_PORT +echo "Frappe-socketio available on $FRAPPE_PY port $FRAPPE_PY_PORT" + exec "$@" From aa3f5f32b247088fc4d30f3c3453ec124d8d9453 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Thu, 5 Mar 2020 06:17:55 +0530 Subject: [PATCH 4/5] fix: travis py script --- travis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis.py b/travis.py index 06ed6c17..02101369 100755 --- a/travis.py +++ b/travis.py @@ -1,4 +1,4 @@ -#!/bin/env python3 +#!/usr/bin/env python3 import argparse import subprocess From 70021c7e50f34e76946201f665cc6476a3ee42c6 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Thu, 5 Mar 2020 06:34:26 +0530 Subject: [PATCH 5/5] fix: travis yml use to bionic --- .travis.yml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index a01d8898..7042d7b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ sudo: required -dist: xenial +dist: bionic services: - docker @@ -23,7 +23,7 @@ matrix: - name: "Build Frappe python environment (edge)" if: branch = develop AND type != pull_request script: - - ./travis.py frappe --worker --tag edge + - ./travis.py frappe --worker --tag edge - ./travis.py frappe --worker --tag develop --tag-only - name: "Build Frappe nginx + static assets (edge)" if: branch = develop AND type != pull_request @@ -38,7 +38,7 @@ matrix: - name: "Build ERPNext nginx + static assets (edge)" if: branch = develop AND type != pull_request script: - - ./travis.py erpnext --nginx --tag edge + - ./travis.py erpnext --nginx --tag edge - ./travis.py erpnext --nginx --tag develop --tag-only - name: "Build Frappe socketio service (edge)" if: branch = develop AND type != pull_request @@ -48,13 +48,13 @@ matrix: - name: "Build Frappe python environment (v12)" if: branch = master AND type != pull_request script: - - ./travis.py frappe --worker --git-branch 12 + - ./travis.py frappe --worker --git-branch 12 - ./travis.py frappe --worker --tag v12 --tag-only - ./travis.py frappe --worker --tag version-12 --tag-only - name: "Build Frappe nginx + static assets (v12)" if: branch = master AND type != pull_request script: - - ./travis.py frappe --nginx --git-branch 12 + - ./travis.py frappe --nginx --git-branch 12 - ./travis.py frappe --nginx --tag v12 --tag-only - ./travis.py frappe --nginx --tag version-12 --tag-only - name: "Build ERPNext python environment (v12)" @@ -78,13 +78,13 @@ matrix: - name: "Build Frappe python environment (v11)" if: branch = master AND type != pull_request script: - - ./travis.py frappe --worker --git-branch 11 + - ./travis.py frappe --worker --git-branch 11 - ./travis.py frappe --worker --tag v11 --tag-only - ./travis.py frappe --worker --tag version-11 --tag-only - name: "Build Frappe nginx + static assets (v11)" if: branch = master AND type != pull_request script: - - ./travis.py erpnext frappe --nginx --git-branch 11 + - ./travis.py erpnext frappe --nginx --git-branch 11 - ./travis.py erpnext frappe --nginx --tag v11 --tag-only - ./travis.py erpnext frappe --nginx --tag version-11 --tag-only - name: "Build ERPNext python environment (v11)" @@ -105,5 +105,3 @@ matrix: - ./travis.py frappe --socketio --git-branch 11 - ./travis.py frappe --socketio --tag v11 --tag-only - ./travis.py frappe --socketio --tag version-11 --tag-only - - \ No newline at end of file