From 1be128b1f793411a27e172e356158db07be3fef1 Mon Sep 17 00:00:00 2001 From: Mendel Greenberg Date: Fri, 1 Mar 2019 16:42:26 -0500 Subject: [PATCH 01/13] Refractoring, reducing layers --- Dockerfile | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index e5fc5dee..b219e444 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,11 +11,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends iputils-ping gi libffi-dev libssl-dev libjpeg8-dev redis-tools software-properties-common libxext6 xfonts-75dpi xfonts-base \ python-dev libfreetype6-dev liblcms2-dev libwebp-dev python-tk libsasl2-dev libldap2-dev libtiff5-dev \ python-setuptools tk8.6-dev wget libmysqlclient-dev mariadb-client curl rlwrap wkhtmltopdf python-pip sudo \ - && apt-get clean && rm -rf /var/lib/apt/lists/* -RUN pip install --upgrade setuptools pip && rm -rf ~/.cache/pip - -# Install Node.js and yarn -RUN curl https://deb.nodesource.com/node_10.x/pool/main/n/nodejs/nodejs_10.10.0-1nodesource1_amd64.deb > node.deb \ + && apt-get clean && rm -rf /var/lib/apt/lists/* \ + && pip install --upgrade setuptools pip --no-cache \ + && 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 \ && rm node.deb \ && npm install -g yarn @@ -24,21 +22,15 @@ RUN curl https://deb.nodesource.com/node_10.x/pool/main/n/nodejs/nodejs_10.10.0- RUN useradd -ms /bin/bash -G sudo frappe \ && printf '# Sudo rules for frappe\nfrappe ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/frappe -USER frappe WORKDIR /home/frappe +# Install bench +RUN pip install -e git+https://github.com/frappe/bench.git#egg=bench --no-cache + +USER frappe # Add some bench files COPY --chown=frappe:frappe ./frappe-bench /home/frappe/frappe-bench - -USER root -# Install bench -RUN pip install -e git+https://github.com/frappe/bench.git#egg=bench \ - && rm -rf ~/.cache/pip - -USER frappe WORKDIR /home/frappe/frappe-bench -EXPOSE 8000 -EXPOSE 9000 -EXPOSE 6787 +EXPOSE 8000 9000 6787 VOLUME [ "/home/frappe/frappe-bench" ] \ No newline at end of file From 16e766fedd20499c569e8d086fa5eb0614de602a Mon Sep 17 00:00:00 2001 From: Mendel Greenberg Date: Sat, 2 Mar 2019 22:01:00 -0500 Subject: [PATCH 02/13] removing the py script that took too many lines to do one simple thing --- .travis.yml | 12 +++--------- test.py | 29 ----------------------------- test.sh | 5 +++++ 3 files changed, 8 insertions(+), 38 deletions(-) delete mode 100644 test.py create mode 100644 test.sh diff --git a/.travis.yml b/.travis.yml index 18e18efb..032db3bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,3 @@ -language: python -python: - - "2.7" env: - DOCKER_COMPOSE_VERSION: 1.23.1 @@ -19,14 +16,11 @@ before_install: install: - chmod ugo+x ./dbench + - chmod ugo+x ./test.sh - ./dbench setup docker - ./dbench init frappe-bench - ./dbench new-site site1.local - ./dbench setup hosts - - pip install --upgrade virtualenv - - virtualenv -p python3 testenv - - source testenv/bin/activate - - pip install requests script: - docker-compose ps | grep -i frappe @@ -34,5 +28,5 @@ script: - docker-compose ps | grep -i redis-queue - docker-compose ps | grep -i redis-socketio - docker-compose ps | grep -i mariadb - - python test.py - - docker-compose stop + - ./test.sh + - ./dbench setup docker stop diff --git a/test.py b/test.py deleted file mode 100644 index c127ad74..00000000 --- a/test.py +++ /dev/null @@ -1,29 +0,0 @@ -import subprocess, requests, datetime, _thread, time, os, signal -start_time = datetime.datetime.now().time() -bench_start = 'docker exec -i frappe bash -c "bench start"' -process = subprocess.Popen(bench_start, stdout=subprocess.PIPE , shell=True) - - -def print_out(val,delay): - while 1: - time.sleep(delay) - if val == 1: - result,error = process.communicate() - print(result) - elif val == 2: - try: - global r - r = requests.get("http://localhost:8000") - print(r) - except requests.exceptions.ConnectionError as e: - print(e) - -_thread.start_new_thread(print_out, (1, 1)) -#result, error = process.communicate() -_thread.start_new_thread(print_out, (2, 1)) - -time.sleep(30) - -process.kill() - -assert ' Login ' in str(r.content) diff --git a/test.sh b/test.sh new file mode 100644 index 00000000..19e7bef9 --- /dev/null +++ b/test.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +./dbench start > /tmp/bench.log & + +curl --retry 20 --retry-delay 1 --retry-connrefused "http://localhost:8000/login" | grep ' Login ' || exit 1 \ No newline at end of file From 7271a5db3c94b798cdee454746b55f5c4a97e57b Mon Sep 17 00:00:00 2001 From: Mendel Greenberg Date: Sat, 2 Mar 2019 22:15:58 -0500 Subject: [PATCH 03/13] Fixed up the readme --- README.md | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 74653801..352706b5 100644 --- a/README.md +++ b/README.md @@ -1,69 +1,72 @@ # Frappe on Docker -[![Build Status](https://travis-ci.org/frappe/frappe_docker.svg?branch=master)](https://travis-ci.org/frappe/frappe_docker) +[![Build Status](https://travis-ci.org/frappe/frappe_docker.svg?branch=develop)](https://travis-ci.org/frappe/frappe_docker) This is a repo designed to aide setting up frappe/ERPNext on docker. ## Getting Started -These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. Unfortunetly, this container is not curently suited for a production enviorment. +These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. -### 1. Installation Pre-requisites +Unfortunetly, this container is not curently suited for a production enviorment (but we're working towards that goal!). -- Install [Docker](https://docs.docker.com/engine/installation) Community Edition +### Build the container and initialize the bench -- Install [Docker Compose](https://docs.docker.com/compose/install/) (only for Linux users. Docker for Mac, Docker for Windows, and Docker Toolbox already include Docker Compose). +**Note:** These instructions assume you have both [Docker](https://docs.docker.com/engine/installation) and [Docker Compose](https://docs.docker.com/compose/install/) installed on your system. -### 2. Build the container and initialize the bench - -1. Clone this repo and change your working directory to frappe_docker +1. Clone this repo and change your working directory to it: ```bash git clone https://github.com/frappe/frappe_docker.git - cd frappe_docker + cd frappe_docker/ ``` -2. Build and start the container, and initialize the bench +2. Build and start the container, and initialize the bench: ```bash ./dbench setup docker ./dbench init ``` - Note: This will take a while, as docker will now build the container. + **Note:** This will take a while, as docker will now build the container. -3. Add a new site and start frappe +3. Add a new site and start Frappe: ```bash ./dbench new-site site1.local ./dbench setup hosts ./dbench start ``` -4. To use frappe: Open your browser to `localhost:8000`. - Username: `Administrator` Password: `admin` -### Basic Usage* +4. Use Frappe: + Open your browser to `localhost:8000/login`. Then login using the username `Administrator` and the password `admin`. -- `./dbench`: Launches you into an interactive shell in the container as user frappe +### Basic Usage of `./dbench` -- `./dbench setup docker [ stop | down ]`: Starts and builds the docker containers using `docker-compose up -d` +**IMPORTANT: Always make sure that your current directory is the root directory of the repo (i.e. `frappe_docker/`)** + +- `./dbench`: Launches you into an interactive shell in the container as the user `frappe`. + +- `./dbench setup docker [ stop | down ]`: Starts and builds the docker containers using `docker-compose up -d`. + - `stop`: Stops the containers with `docker-compose stop`. + - `down`: Deletes the containers and the coresponding volumes with `docker-compose down`. - `./dbench setup hosts`: Adds all sites to the containers hosts file. - Do this after you've added a new site to avoid errors. + **Note:** Run this after you've added a new site to avoid errors. -- `./dbench -c frappe | root `: Runs a command in the container, as the selected user +- `./dbench -c frappe | root `: Runs a command in the container, as the selected user. -- `./dbench -h`: Shows this help message +- `./dbench -h`: Shows this help message. -- `./dbench `: Runs a command in bench, (Running `./dbench new-site site1.local` will run in the conatiner as `bench new-site site1.local`) +- `./dbench `: Runs a command in bench (i.e. Running `./dbench new-site site1.local`, will run `bench new-site site1.local` in the container). -*Always make sure that your current directory is the root directory of the repo (i.e. `frappe_docker/`) +## For More Info For more info on building this docker container refer to this [Wiki](https://github.com/frappe/frappe_docker/wiki/Hitchhiker's-guide-to-building-this-frappe_docker-image) ## Contributing -Feel free to contribute to this project and make the container better +Feel free to contribute to this project and make it better. ## License From 9b09b5a532bf2064e555e83deed535ed8d399d76 Mon Sep 17 00:00:00 2001 From: Mendel Greenberg Date: Sat, 2 Mar 2019 22:38:35 -0500 Subject: [PATCH 04/13] some refractoring --- .dockerignore | 5 ++++- conf/mariadb-conf.d/my.cnf | 2 +- docker-compose.yml | 16 +++++++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.dockerignore b/.dockerignore index 37f67d5a..455769b0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,6 +2,9 @@ conf/* .travis.yml -test.py +test.sh +README.md +LICENSE.md +.gitignore dbench docker-*.yml \ No newline at end of file diff --git a/conf/mariadb-conf.d/my.cnf b/conf/mariadb-conf.d/my.cnf index 5b99beba..67decf83 100644 --- a/conf/mariadb-conf.d/my.cnf +++ b/conf/mariadb-conf.d/my.cnf @@ -15,8 +15,8 @@ #collation-server = utf8_general_ci #character_set_server = utf8 #collation_server = utf8_general_ci -# Import all .cnf files from configuration directory bind-address = 0.0.0.0 +# Import all .cnf files from configuration directory !includedir /etc/mysql/mariadb.conf.d/ diff --git a/docker-compose.yml b/docker-compose.yml index 0b8362d5..a24d2283 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,7 +12,7 @@ services: - /var/lib/mysql ports: - - "3307:3306" #mariadb-port + - "3307:3306" # MariaDB Port container_name: mariadb @@ -49,26 +49,32 @@ services: 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 - build: . + ports: - - "8000:8000" #webserver_port - - "9000:9000" #socketio_port - - "6787:6787" #file_watcher_port + - "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 From 05ebf9a3a480b3a448d8f15ba1b9802b3a978bda Mon Sep 17 00:00:00 2001 From: Mendel Greenberg Date: Sat, 2 Mar 2019 22:38:50 -0500 Subject: [PATCH 05/13] moving to debian slim and refractoring --- Dockerfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index b219e444..aba98540 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,16 @@ # Frappe Bench Dockerfile -FROM ubuntu:16.04 +FROM debian:9.6-slim LABEL author=frappé # Set locale C.UTF-8 for mariadb and general locale data ENV LANG C.UTF-8 # Install all neccesary packages -RUN apt-get update && apt-get install -y --no-install-recommends iputils-ping git build-essential \ - libffi-dev libssl-dev libjpeg8-dev redis-tools software-properties-common libxext6 xfonts-75dpi xfonts-base \ - python-dev libfreetype6-dev liblcms2-dev libwebp-dev python-tk libsasl2-dev libldap2-dev libtiff5-dev \ - python-setuptools tk8.6-dev wget libmysqlclient-dev mariadb-client curl rlwrap wkhtmltopdf python-pip sudo \ +RUN apt-get update && apt-get install -y --no-install-recommends build-essential cron curl git iputils-ping libffi-dev \ + liblcms2-dev libldap2-dev libmariadbclient-dev libsasl2-dev libssl-dev libtiff5-dev libwebp-dev mariadb-client \ + python-dev python-pip python-setuptools python-tk redis-tools rlwrap software-properties-common sudo tk8.6-dev \ + vim xfonts-75dpi xfonts-base wget wkhtmltopdf \ && apt-get clean && rm -rf /var/lib/apt/lists/* \ && pip install --upgrade setuptools pip --no-cache \ && curl https://deb.nodesource.com/node_10.x/pool/main/n/nodejs/nodejs_10.10.0-1nodesource1_amd64.deb > node.deb \ From a5712263bd0a3ed2feb5b78a7192d39eabac6007 Mon Sep 17 00:00:00 2001 From: Mendel Greenberg Date: Sun, 3 Mar 2019 21:15:41 -0500 Subject: [PATCH 06/13] adding some logging --- test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/test.sh b/test.sh index 19e7bef9..7f021109 100644 --- a/test.sh +++ b/test.sh @@ -2,4 +2,5 @@ ./dbench start > /tmp/bench.log & +curl --version curl --retry 20 --retry-delay 1 --retry-connrefused "http://localhost:8000/login" | grep ' Login ' || exit 1 \ No newline at end of file From 252f191fb363295826cfba04a9df5fa6d446bf0b Mon Sep 17 00:00:00 2001 From: Mendel Greenberg Date: Sun, 3 Mar 2019 21:45:11 -0500 Subject: [PATCH 07/13] Updated travis to ubuntu xenial, should fix the curl issue --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index 032db3bc..5f9c573c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,10 @@ +dist: xenial + +addons: + apt: + packages: + - curl + env: - DOCKER_COMPOSE_VERSION: 1.23.1 From 0e7a5992eab01e967f35322a3505e8f182587642 Mon Sep 17 00:00:00 2001 From: Mendel Greenberg Date: Sun, 3 Mar 2019 22:41:23 -0500 Subject: [PATCH 08/13] manually building curl, cause we cant use the latest version... --- .travis.yml | 17 +++++++++++++---- Dockerfile | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5f9c573c..bf99d8b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,26 @@ dist: xenial +env: + - DOCKER_COMPOSE_VERSION: 1.23.1 + addons: apt: packages: - - curl - -env: - - DOCKER_COMPOSE_VERSION: 1.23.1 + - build-essential + - nghttp2 + - libnghttp2-dev + - libssl-dev services: - docker before_install: + - wget https://curl.haxx.se/download/curl-7.63.0.tar.gz && tar xzf curl-7.63.0.tar.gz + - cd curl-7.63.0 + - sudo apt-get -y remove curl + - ./configure --with-nghttp2 --with-ssl + - make && sudo make install + - sudo ldconfig && cd .. - 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 update diff --git a/Dockerfile b/Dockerfile index aba98540..4a8191d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ LABEL author=frappé ENV LANG C.UTF-8 # Install all neccesary packages -RUN apt-get update && apt-get install -y --no-install-recommends build-essential cron curl git iputils-ping libffi-dev \ +RUN apt-get update && apt-get install -y --no-install-suggests --no-install-recommends build-essential cron curl git iputils-ping libffi-dev \ liblcms2-dev libldap2-dev libmariadbclient-dev libsasl2-dev libssl-dev libtiff5-dev libwebp-dev mariadb-client \ python-dev python-pip python-setuptools python-tk redis-tools rlwrap software-properties-common sudo tk8.6-dev \ vim xfonts-75dpi xfonts-base wget wkhtmltopdf \ From c18efdcb6ced39e4dc185458d8d4e428589d5f2b Mon Sep 17 00:00:00 2001 From: Mendel Greenberg Date: Sun, 3 Mar 2019 23:27:16 -0500 Subject: [PATCH 09/13] maybe we dont need it --- .travis.yml | 13 ------------- test.sh | 12 ++++++++++-- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index bf99d8b0..058bfdfb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,24 +3,11 @@ dist: xenial env: - DOCKER_COMPOSE_VERSION: 1.23.1 -addons: - apt: - packages: - - build-essential - - nghttp2 - - libnghttp2-dev - - libssl-dev services: - docker before_install: - - wget https://curl.haxx.se/download/curl-7.63.0.tar.gz && tar xzf curl-7.63.0.tar.gz - - cd curl-7.63.0 - - sudo apt-get -y remove curl - - ./configure --with-nghttp2 --with-ssl - - make && sudo make install - - sudo ldconfig && cd .. - 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 update diff --git a/test.sh b/test.sh index 7f021109..c0f5e673 100644 --- a/test.sh +++ b/test.sh @@ -2,5 +2,13 @@ ./dbench start > /tmp/bench.log & -curl --version -curl --retry 20 --retry-delay 1 --retry-connrefused "http://localhost:8000/login" | grep ' Login ' || exit 1 \ No newline at end of file +output=$( + while ! curl "http://localhost:8000/login" + do + { echo "Exit status of curl: $?" + } 1>&2 + sleep 1 + done +) + +echo "${output}" | grep ' Login ' || exit 1 \ No newline at end of file From aa0b93dda9e14402d3db07f2ff377bad8ecbdf0f Mon Sep 17 00:00:00 2001 From: Mendel Greenberg Date: Sun, 3 Mar 2019 23:42:45 -0500 Subject: [PATCH 10/13] changing the url to curl --- test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.sh b/test.sh index c0f5e673..31fcbeb0 100644 --- a/test.sh +++ b/test.sh @@ -3,7 +3,7 @@ ./dbench start > /tmp/bench.log & output=$( - while ! curl "http://localhost:8000/login" + while ! curl "http://localhost:8000" do { echo "Exit status of curl: $?" } 1>&2 From 58824ca35875e7f7c3acc92b696ec7011df88d6e Mon Sep 17 00:00:00 2001 From: Mendel Greenberg Date: Mon, 4 Mar 2019 00:03:18 -0500 Subject: [PATCH 11/13] trying this instead --- test.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/test.sh b/test.sh index 31fcbeb0..4bba3cda 100644 --- a/test.sh +++ b/test.sh @@ -2,13 +2,14 @@ ./dbench start > /tmp/bench.log & -output=$( - while ! curl "http://localhost:8000" - do - { echo "Exit status of curl: $?" - } 1>&2 - sleep 1 - done -) +while ! [[ $i == 20 ]] +do + output=$( curl "http://localhost:8000" ) + { echo "Exit status of curl: $?" + } 1>&2 + sleep 2 + i=$((i + 1)) +done + echo "${output}" | grep ' Login ' || exit 1 \ No newline at end of file From b26da28087c231e22a1ebfc485f71aef2b6fbde4 Mon Sep 17 00:00:00 2001 From: Mendel Greenberg Date: Mon, 4 Mar 2019 00:22:51 -0500 Subject: [PATCH 12/13] lets just let it pollute the stream --- test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.sh b/test.sh index 4bba3cda..cde3830d 100644 --- a/test.sh +++ b/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -./dbench start > /tmp/bench.log & +./dbench start & while ! [[ $i == 20 ]] do From a36de81e4b4c43e01c5f85159a4fe2cbe30d4c22 Mon Sep 17 00:00:00 2001 From: Mendel Greenberg Date: Mon, 4 Mar 2019 00:33:27 -0500 Subject: [PATCH 13/13] please pollute! --- test.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test.sh b/test.sh index cde3830d..0896e498 100644 --- a/test.sh +++ b/test.sh @@ -1,6 +1,8 @@ #!/bin/bash -./dbench start & +cat <(./dbench start) & + +sleep 5 while ! [[ $i == 20 ]] do