diff --git a/.travis.yml b/.travis.yml index bf15e5f7..cda2ba5d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,20 +2,17 @@ language: python python: - "2.7" env: - - DOCKER_COMPOSE_VERSION: 1.8.0 + - DOCKER_COMPOSE_VERSION: 1.22.0 services: - docker install: - - docker-compose build - - docker-compose up -d - - docker exec -it -u root frappe bash -c "cd /home/frappe && chown -R frappe:frappe ./*" - - docker exec -i frappe bash -c "cd .. && bench init frappe-bench --ignore-exist --skip-redis-config-generation && cd frappe-bench" - - docker exec -i frappe bash -c "mv Procfile_docker Procfile && mv sites/common_site_config_docker.json sites/common_site_config.json" - - docker exec -i frappe bash -c "bench new-site site1.local" - - docker exec -i -u root frappe bash -c "echo 127.0.0.1 site1.local >> /etc/hosts" - - sudo su -c 'echo 127.0.0.1 site1.local >> /etc/hosts' + - chmod ugo+x ./dbench + - ./dbench setup docker + - ./dbench init frappe-bench + - ./dbench new-site site1.local + - sudo ./dbench setup hosts - pip install --upgrade virtualenv - virtualenv -p python3 testenv - source testenv/bin/activate diff --git a/Dockerfile b/Dockerfile index eaf29640..d653bc99 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,17 +5,16 @@ FROM ubuntu:16.04 LABEL MAINTAINER frappé USER root -RUN useradd -ms /bin/bash frappe -RUN apt-get update -RUN apt-get install -y iputils-ping git build-essential python-setuptools python-dev libffi-dev libssl-dev \ - redis-tools redis-server software-properties-common libxrender1 libxext6 xfonts-75dpi xfonts-base \ - libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev python-tk apt-transport-https libsasl2-dev libldap2-dev libtiff5-dev \ - tcl8.6-dev tk8.6-dev wget libmysqlclient-dev mariadb-client mariadb-common curl rlwrap redis-tools nano wkhtmltopdf python-pip -RUN pip install --upgrade setuptools pip - # Generate locale C.UTF-8 for mariadb and general locale data ENV LANG C.UTF-8 +RUN apt-get update && apt-get install -y iputils-ping git build-essential python-setuptools python-dev libffi-dev libssl-dev libjpeg8-dev \ + redis-tools redis-server software-properties-common libxrender1 libxext6 xfonts-75dpi xfonts-base zlib1g-dev libfreetype6-dev \ + liblcms2-dev libwebp-dev python-tk apt-transport-https libsasl2-dev libldap2-dev libtiff5-dev tcl8.6-dev tk8.6-dev \ + wget libmysqlclient-dev mariadb-client mariadb-common curl rlwrap redis-tools nano wkhtmltopdf python-pip vim sudo +RUN pip install --upgrade setuptools pip +RUN useradd -ms /bin/bash -G sudo frappe && printf '# User rules for frappe\nfrappe ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/frappe + #nodejs RUN curl https://deb.nodesource.com/node_10.x/pool/main/n/nodejs/nodejs_10.10.0-1nodesource1_amd64.deb > node.deb \ && dpkg -i node.deb \ @@ -28,7 +27,8 @@ RUN git clone -b master https://github.com/frappe/bench.git bench-repo USER root RUN pip install -e bench-repo \ && npm install -g yarn \ - && chown -R frappe:frappe /home/frappe/* - + && chown -R frappe:frappe /home/frappe/* \ + && rm -rf /var/lib/apt/lists/* + USER frappe WORKDIR /home/frappe/frappe-bench diff --git a/README.md b/README.md index 6308622c..a3d01a7e 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ Express dependency between services, which has two effects: #### 2. Build the container and install bench * Clone this repo and change your working directory to frappe_docker - + git clone --depth 1 https://github.com/frappe/frappe_docker.git cd frappe_docker @@ -94,7 +94,7 @@ Express dependency between services, which has two effects: It creates a user, frappe inside the frappe container, whose working directory is /home/frappe. It also clones the bench-repo from [here](https://github.com/frappe/bench) - docker-compose up -d + ./dbench setup docker Note: Please do not remove the bench-repo directory the above commands will create @@ -102,29 +102,25 @@ Express dependency between services, which has two effects: #### Basic Usage ##### Make sure your current directory is frappe_docker -1. First time setup - +1. First time setup + ./dbench init -2. Command to start all the containers +2. Command to be executed everytime after starting your containers - docker-compose start + ./dbench setup hosts -3. Command to be executed everytime after starting your containers +3. Command to enter your container - ./dbench -s + ./dbench -4. Command to enter your container - - docker exec -it frappe bash - -5. All bench commands can also be directly run from the host machine by using dbench. For instance ```bench start``` can be executed by running ```./dbench -c start```. Just preface the option with <b>./dbench -c</b>. For more information on dbench run the command ```./dbench -h```. +4. All bench commands can also be directly run from the host machine by using dbench. For instance ```bench start``` can be executed by running ```./dbench start```. Just preface the option with **`./dbench`**. For more information on dbench run the command ```./dbench -h```. For more info on how to build this docker container refer to this [Wiki](https://github.com/frappe/frappe_docker/wiki/Hitchhiker's-guide-to-building-this-frappe_docker-image) To login to Frappe / ERPNext, open your browser and go to `[your-external-ip]:8000`, probably `localhost:8000` -The default username is "Administrator" and password is what you set when you created the new site. The default admin password is set in common_site_config.json, and is set to 'admin' in this docker image. +The default username is "Administrator" and password is what you set when you created the new site. The default admin password is set in common_site_config.json, and is set to 'admin' in this docker image. ## Built With diff --git a/dbench b/dbench index fe835bf5..76da4e19 100755 --- a/dbench +++ b/dbench @@ -1,57 +1,52 @@ #!/bin/bash -display_usage() { - echo "$(basename "$0") [-h] [-c \"<command to be executed inside container>\"]" - echo '' - echo 'where:' - echo ' -h show this help text' - echo ' -c execute a command inside docker using docker exec' - echo ' -s adds site-names to /etc/hosts file in the container to facilitate multisite access' - echo ' init initializes frappe-bench adds a new-site bench-manager.local and installs the bench_manager app - app onto it' -} - if [[ $# -eq 0 ]]; then - docker exec -it frappe bash - -elif [ $1 == 'init' ] -then - docker exec -i -u root frappe bash -c "cd /home/frappe && chown -R frappe:frappe ./*" - docker exec -it frappe bash -c "cd .. && bench init frappe-bench --ignore-exist --skip-redis-config-generation && cd frappe-bench" - docker exec -it frappe bash -c "mv Procfile_docker Procfile && mv sites/common_site_config_docker.json sites/common_site_config.json" - docker exec -it -u root frappe bash -c "apt-get install -y vim sudo && usermod -aG sudo frappe && printf '# User rules for frappe\nfrappe ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/frappe" - docker exec -it frappe bash -c "bench set-mariadb-host mariadb" - docker exec -it frappe bash -c "bench new-site site1.local" - docker exec -it frappe bash -c "bench get-app erpnext" - docker exec -it frappe bash -c "bench --site site1.local install-app erpnext" - + docker exec -it frappe bash +elif [ "$1" == 'init' ]; then + docker exec -itu root frappe bash -c "cd /home/frappe && chown -R frappe:frappe ./*" + docker exec -i frappe bash -c "cd .. && bench init $2 --ignore-exist --skip-redis-config-generation" + docker exec -i frappe bash -c "mv Procfile_docker Procfile && mv sites/common_site_config_docker.json sites/common_site_config.json && bench set-mariadb-host mariadb" +elif [ "$1" == 'setup' ]; then + if [ "$2" == 'docker' ]; then + if [ "$3" == '--swarm-mode' ]; then + echo "Docker swarm mode is not currently supported" + else + docker-compose up -d + fi + elif [ "$2" == 'hosts' ]; then + a=$(cd frappe-bench && ls sites/*/site_config.json | grep -o '/.\+/') + a="${a//$'\n'/ }" + a=$(echo $a | tr -d / ) + result="127.0.0.1 ${a}" + echo $result | sudo tee -a /etc/hosts + docker exec -iu root frappe bash -c "echo ${result} | tee --append /etc/hosts" + docker exec -itu root frappe bash -c "printf '# User rules for frappe\nfrappe ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/frappe" + fi +elif [ "$1" == '-c' ]; then + shift + user=$1 + shift + docker exec -iu "$user" frappe bash -c "$@" +elif [ "$1" == '-h' ]; then + echo "$0 [-h] | [ -c frappe | root <command to run> ] [ <command to send to bench> ]" + echo "" + echo "$0 extends the Frappe Bench tool, and is used like it. However, it extends the tool in a few places." + echo "Usage:" + echo " $0" + echo " Launches you into an interactive shell in the container as user frappe" + echo " $0 init bench-folder-name" + echo " Runs \"bench init\" along with some other commands" + echo " $0 setup docker" + echo " Starts and builds the docker containers using \"docker-compose up -d\"" + echo " $0 setup hosts" + echo " Adds all sites to the hosts file, run with sudo" + echo " $0 -c frappe | root <command to run>" + echo " Runs a command in the container, as the selected user" + echo " $0 -h" + echo " Shows this help message" + echo " $0 <command to send to bench>" + echo " Runs a command in bench, i.e. $0 new-site site1.local = bench new-site site1.local" else - while getopts ':hsc:' option; do - case "$option" in - h) - display_usage - exit - ;; - c) - docker exec -it frappe bash -c "bench $OPTARG" - ;; - s) - a=$(cd frappe-bench && ls sites/*/site_config.json | grep -o '/.\+/') - a="${a//$'\n'/ }" - a=$(echo $a | tr -d / ) - result="127.0.0.1 ${a}" - echo $result - docker exec -u root -i frappe bash -c "echo ${result} | tee --append /etc/hosts" - docker exec -itu root frappe bash -c "printf '# User rules for frappe\nfrappe ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/frappe" - ;; - \?) - echo "Invalid option: -$OPTARG" >&2 - exit 1 - ;; - :) - echo "Option -$OPTARG requires an argument." >&2 - exit 1 - ;; - esac - done -fi + IFS=" " + docker exec -it frappe bash -c "bench $*" +fi \ No newline at end of file