From 6f7a9b92ac382a7588f8e72beb94014e59967d62 Mon Sep 17 00:00:00 2001 From: Davide Bortolami Date: Tue, 3 Mar 2020 23:40:11 +0000 Subject: [PATCH 1/7] Refactor renaming erpnext-assets and frappe-assets to erpnext-nginx and frappe-nginx --- .travis.yml | 68 +++++++++---------- .../Dockerfile | 2 +- .../docker-entrypoint.sh | 0 .../v11.Dockerfile | 2 +- .../v12.Dockerfile | 2 +- .../Dockerfile | 2 +- .../docker-entrypoint.sh | 0 .../v11.Dockerfile | 2 +- .../v12.Dockerfile | 2 +- installation/docker-compose-erpnext.yml | 4 +- installation/docker-compose-frappe.yml | 4 +- 11 files changed, 44 insertions(+), 44 deletions(-) rename build/{erpnext-assets => erpnext-nginx}/Dockerfile (96%) rename build/{erpnext-assets => erpnext-nginx}/docker-entrypoint.sh (100%) rename build/{erpnext-assets => erpnext-nginx}/v11.Dockerfile (96%) rename build/{erpnext-assets => erpnext-nginx}/v12.Dockerfile (96%) rename build/{frappe-assets => frappe-nginx}/Dockerfile (96%) rename build/{frappe-assets => frappe-nginx}/docker-entrypoint.sh (100%) rename build/{frappe-assets => frappe-nginx}/v11.Dockerfile (96%) rename build/{frappe-assets => frappe-nginx}/v12.Dockerfile (96%) diff --git a/.travis.yml b/.travis.yml index 8158bb93..9aed1347 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,11 +30,11 @@ matrix: - name: "Build Frappe nginx + static assets (edge)" if: branch = develop AND type != pull_request script: - - docker build -t frappe-assets -f build/frappe-assets/Dockerfile . - - docker tag frappe-assets frappe/frappe-assets:edge - - docker tag frappe-assets frappe/frappe-assets:develop - - docker push frappe/frappe-assets:edge - - docker push frappe/frappe-assets:develop + - docker build -t frappe-nginx -f build/frappe-nginx/Dockerfile . + - docker tag frappe-nginx frappe/frappe-nginx:edge + - docker tag frappe-nginx frappe/frappe-nginx:develop + - docker push frappe/frappe-nginx:edge + - docker push frappe/frappe-nginx:develop - name: "Build ERPNext python environment (edge)" if: branch = develop AND type != pull_request script: @@ -46,11 +46,11 @@ matrix: - name: "Build ERPNext nginx + static assets (edge)" if: branch = develop AND type != pull_request script: - - docker build -t erpnext-assets -f build/erpnext-assets/Dockerfile . - - docker tag erpnext-assets frappe/erpnext-assets:edge - - docker tag erpnext-assets frappe/erpnext-assets:develop - - docker push frappe/erpnext-assets:edge - - docker push frappe/erpnext-assets:develop + - docker build -t erpnext-nginx -f build/erpnext-nginx/Dockerfile . + - docker tag erpnext-nginx frappe/erpnext-nginx:edge + - docker tag erpnext-nginx frappe/erpnext-nginx:develop + - docker push frappe/erpnext-nginx:edge + - docker push frappe/erpnext-nginx:develop - name: "Build Frappe socketio service (edge)" if: branch = develop AND type != pull_request script: @@ -81,12 +81,12 @@ matrix: - git fetch --tags - export VERSION=$(git tag --list --sort=-version:refname "v12*" | sed -n 1p | sed -e 's#.*@\(\)#\1#') - cd .. - - docker build -t frappe/frappe-assets:$VERSION -f build/frappe-assets/v12.Dockerfile . - - docker tag frappe/frappe-assets:$VERSION frappe/frappe-assets:version-12 - - docker tag frappe/frappe-assets:$VERSION frappe/frappe-assets:v12 - - docker push frappe/frappe-assets:$VERSION - - docker push frappe/frappe-assets:version-12 - - docker push frappe/frappe-assets:v12 + - docker build -t frappe/frappe-nginx:$VERSION -f build/frappe-nginx/v12.Dockerfile . + - docker tag frappe/frappe-nginx:$VERSION frappe/frappe-nginx:version-12 + - docker tag frappe/frappe-nginx:$VERSION frappe/frappe-nginx:v12 + - docker push frappe/frappe-nginx:$VERSION + - docker push frappe/frappe-nginx:version-12 + - docker push frappe/frappe-nginx:v12 - name: "Build ERPNext python environment (v12)" if: branch = master AND type != pull_request script: @@ -109,12 +109,12 @@ matrix: - git fetch --tags - export VERSION=$(git tag --list --sort=-version:refname "v12*" | sed -n 1p | sed -e 's#.*@\(\)#\1#') - cd .. - - docker build -t frappe/erpnext-assets:$VERSION -f build/erpnext-assets/v12.Dockerfile . - - docker tag frappe/erpnext-assets:$VERSION frappe/erpnext-assets:version-12 - - docker tag frappe/erpnext-assets:$VERSION frappe/erpnext-assets:v12 - - docker push frappe/erpnext-assets:$VERSION - - docker push frappe/erpnext-assets:version-12 - - docker push frappe/erpnext-assets:v12 + - docker build -t frappe/erpnext-nginx:$VERSION -f build/erpnext-nginx/v12.Dockerfile . + - docker tag frappe/erpnext-nginx:$VERSION frappe/erpnext-nginx:version-12 + - docker tag frappe/erpnext-nginx:$VERSION frappe/erpnext-nginx:v12 + - docker push frappe/erpnext-nginx:$VERSION + - docker push frappe/erpnext-nginx:version-12 + - docker push frappe/erpnext-nginx:v12 - name: "Build Frappe socketio service (v12)" if: branch = master AND type != pull_request script: @@ -151,12 +151,12 @@ matrix: - git fetch --tags - export VERSION=$(git tag --list --sort=-version:refname "v11*" | sed -n 1p | sed -e 's#.*@\(\)#\1#') - cd .. - - docker build -t frappe/frappe-assets:$VERSION -f build/frappe-assets/v11.Dockerfile . - - docker tag frappe/frappe-assets:$VERSION frappe/frappe-assets:version-11 - - docker tag frappe/frappe-assets:$VERSION frappe/frappe-assets:v11 - - docker push frappe/frappe-assets:$VERSION - - docker push frappe/frappe-assets:version-11 - - docker push frappe/frappe-assets:v11 + - docker build -t frappe/frappe-nginx:$VERSION -f build/frappe-nginx/v11.Dockerfile . + - docker tag frappe/frappe-nginx:$VERSION frappe/frappe-nginx:version-11 + - docker tag frappe/frappe-nginx:$VERSION frappe/frappe-nginx:v11 + - docker push frappe/frappe-nginx:$VERSION + - docker push frappe/frappe-nginx:version-11 + - docker push frappe/frappe-nginx:v11 - name: "Build ERPNext python environment (v11)" if: branch = master AND type != pull_request script: @@ -179,12 +179,12 @@ matrix: - git fetch --tags - export VERSION=$(git tag --list --sort=-version:refname "v11*" | sed -n 1p | sed -e 's#.*@\(\)#\1#') - cd .. - - docker build -t frappe/erpnext-assets:$VERSION -f build/erpnext-assets/v11.Dockerfile . - - docker tag frappe/erpnext-assets:$VERSION frappe/erpnext-assets:version-11 - - docker tag frappe/erpnext-assets:$VERSION frappe/erpnext-assets:v11 - - docker push frappe/erpnext-assets:$VERSION - - docker push frappe/erpnext-assets:version-11 - - docker push frappe/erpnext-assets:v11 + - docker build -t frappe/erpnext-nginx:$VERSION -f build/erpnext-nginx/v11.Dockerfile . + - docker tag frappe/erpnext-nginx:$VERSION frappe/erpnext-nginx:version-11 + - docker tag frappe/erpnext-nginx:$VERSION frappe/erpnext-nginx:v11 + - docker push frappe/erpnext-nginx:$VERSION + - docker push frappe/erpnext-nginx:version-11 + - docker push frappe/erpnext-nginx:v11 - name: "Build Frappe socketio service (v11)" if: branch = master AND type != pull_request script: diff --git a/build/erpnext-assets/Dockerfile b/build/erpnext-nginx/Dockerfile similarity index 96% rename from build/erpnext-assets/Dockerfile rename to build/erpnext-nginx/Dockerfile index 7fcb2b20..967a8c04 100644 --- a/build/erpnext-assets/Dockerfile +++ b/build/erpnext-nginx/Dockerfile @@ -30,7 +30,7 @@ FROM nginx:latest COPY --from=0 /home/frappe/frappe-bench/sites /var/www/html/ COPY --from=0 /var/www/error_pages /var/www/ COPY build/common/nginx-default.conf.template /etc/nginx/conf.d/default.conf.template -COPY build/erpnext-assets/docker-entrypoint.sh / +COPY build/erpnext-nginx/docker-entrypoint.sh / RUN apt-get update && apt-get install -y rsync && apt-get clean diff --git a/build/erpnext-assets/docker-entrypoint.sh b/build/erpnext-nginx/docker-entrypoint.sh similarity index 100% rename from build/erpnext-assets/docker-entrypoint.sh rename to build/erpnext-nginx/docker-entrypoint.sh diff --git a/build/erpnext-assets/v11.Dockerfile b/build/erpnext-nginx/v11.Dockerfile similarity index 96% rename from build/erpnext-assets/v11.Dockerfile rename to build/erpnext-nginx/v11.Dockerfile index 6db3b415..5d737448 100644 --- a/build/erpnext-assets/v11.Dockerfile +++ b/build/erpnext-nginx/v11.Dockerfile @@ -30,7 +30,7 @@ FROM nginx:latest COPY --from=0 /home/frappe/frappe-bench/sites /var/www/html/ COPY --from=0 /var/www/error_pages /var/www/ COPY build/common/nginx-default.conf.template /etc/nginx/conf.d/default.conf.template -COPY build/erpnext-assets/docker-entrypoint.sh / +COPY build/erpnext-nginx/docker-entrypoint.sh / RUN apt-get update && apt-get install -y rsync && apt-get clean diff --git a/build/erpnext-assets/v12.Dockerfile b/build/erpnext-nginx/v12.Dockerfile similarity index 96% rename from build/erpnext-assets/v12.Dockerfile rename to build/erpnext-nginx/v12.Dockerfile index 9b13bb13..16b2c1fe 100644 --- a/build/erpnext-assets/v12.Dockerfile +++ b/build/erpnext-nginx/v12.Dockerfile @@ -30,7 +30,7 @@ FROM nginx:latest COPY --from=0 /home/frappe/frappe-bench/sites /var/www/html/ COPY --from=0 /var/www/error_pages /var/www/ COPY build/common/nginx-default.conf.template /etc/nginx/conf.d/default.conf.template -COPY build/erpnext-assets/docker-entrypoint.sh / +COPY build/erpnext-nginx/docker-entrypoint.sh / RUN apt-get update && apt-get install -y rsync && apt-get clean diff --git a/build/frappe-assets/Dockerfile b/build/frappe-nginx/Dockerfile similarity index 96% rename from build/frappe-assets/Dockerfile rename to build/frappe-nginx/Dockerfile index 762e74d1..03b40883 100644 --- a/build/frappe-assets/Dockerfile +++ b/build/frappe-nginx/Dockerfile @@ -27,7 +27,7 @@ FROM nginx:latest COPY --from=0 /home/frappe/frappe-bench/sites /var/www/html/ COPY --from=0 /var/www/error_pages /var/www/ COPY build/common/nginx-default.conf.template /etc/nginx/conf.d/default.conf.template -COPY build/frappe-assets/docker-entrypoint.sh / +COPY build/frappe-nginx/docker-entrypoint.sh / RUN apt-get update && apt-get install -y rsync && apt-get clean diff --git a/build/frappe-assets/docker-entrypoint.sh b/build/frappe-nginx/docker-entrypoint.sh similarity index 100% rename from build/frappe-assets/docker-entrypoint.sh rename to build/frappe-nginx/docker-entrypoint.sh diff --git a/build/frappe-assets/v11.Dockerfile b/build/frappe-nginx/v11.Dockerfile similarity index 96% rename from build/frappe-assets/v11.Dockerfile rename to build/frappe-nginx/v11.Dockerfile index 225243d2..cfeb2c3d 100644 --- a/build/frappe-assets/v11.Dockerfile +++ b/build/frappe-nginx/v11.Dockerfile @@ -27,7 +27,7 @@ FROM nginx:latest COPY --from=0 /home/frappe/frappe-bench/sites /var/www/html/ COPY --from=0 /var/www/error_pages /var/www/ COPY build/common/nginx-default.conf.template /etc/nginx/conf.d/default.conf.template -COPY build/frappe-assets/docker-entrypoint.sh / +COPY build/frappe-nginx/docker-entrypoint.sh / RUN apt-get update && apt-get install -y rsync && apt-get clean diff --git a/build/frappe-assets/v12.Dockerfile b/build/frappe-nginx/v12.Dockerfile similarity index 96% rename from build/frappe-assets/v12.Dockerfile rename to build/frappe-nginx/v12.Dockerfile index cbbac49b..4994ad28 100644 --- a/build/frappe-assets/v12.Dockerfile +++ b/build/frappe-nginx/v12.Dockerfile @@ -27,7 +27,7 @@ FROM nginx:latest COPY --from=0 /home/frappe/frappe-bench/sites /var/www/html/ COPY --from=0 /var/www/error_pages /var/www/ COPY build/common/nginx-default.conf.template /etc/nginx/conf.d/default.conf.template -COPY build/frappe-assets/docker-entrypoint.sh / +COPY build/frappe-nginx/docker-entrypoint.sh / RUN apt-get update && apt-get install -y rsync && apt-get clean diff --git a/installation/docker-compose-erpnext.yml b/installation/docker-compose-erpnext.yml index 93b7c6a1..f932a512 100644 --- a/installation/docker-compose-erpnext.yml +++ b/installation/docker-compose-erpnext.yml @@ -1,8 +1,8 @@ version: '3' services: - erpnext-assets: - image: frappe/erpnext-assets:${VERSION} + erpnext-nginx: + image: frappe/erpnext-nginx:${VERSION} restart: on-failure environment: - FRAPPE_PY=erpnext-python diff --git a/installation/docker-compose-frappe.yml b/installation/docker-compose-frappe.yml index 869fb73c..df1e7c43 100644 --- a/installation/docker-compose-frappe.yml +++ b/installation/docker-compose-frappe.yml @@ -1,8 +1,8 @@ version: '3' services: - frappe-assets: - image: frappe/frappe-assets:${VERSION} + frappe-nginx: + image: frappe/frappe-nginx:${VERSION} restart: on-failure environment: - FRAPPE_PY=frappe-python From d071bf232db3b4b2a1756944e7253587f4861986 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Thu, 5 Mar 2020 21:39:03 +0530 Subject: [PATCH 2/7] feat: development docker --- .devcontainer/devcontainer.json | 12 +++ .devcontainer/docker-compose.yml | 30 ++++++++ .gitignore | 2 + .travis.yml | 13 +++- build/bench/Dockerfile | 58 +++++++++++++++ development/.vscode/launch.json | 22 ++++++ development/.vscode/settings.json | 4 + development/README.md | 118 ++++++++++++++++++++++++++++++ 8 files changed, 255 insertions(+), 4 deletions(-) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml create mode 100644 build/bench/Dockerfile create mode 100644 development/.vscode/launch.json create mode 100644 development/.vscode/settings.json create mode 100644 development/README.md diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..4bab99fc --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,12 @@ +{ + "name": "Frappe Bench", + "appPort": [8000, 9000, 6787], + "remoteUser": "frappe", + "settings": { + "terminal.integrated.shell.linux": "/bin/bash" + }, + "dockerComposeFile": "./docker-compose.yml", + "service": "frappe", + "workspaceFolder": "/workspace/development", + "shutdownAction": "stopCompose" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 00000000..2d43b0c6 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,30 @@ +version: "3.7" +services: + mariadb: + image: mariadb:10.3 + environment: + - MYSQL_ROOT_PASSWORD=123 + - MYSQL_USER=root + volumes: + - ../installation/frappe-mariadb.cnf:/etc/mysql/conf.d/frappe.cnf + - mariadb-vol:/var/lib/mysql + + redis-cache: + image: redis:alpine + + redis-queue: + image: redis:alpine + + redis-socketio: + image: redis:alpine + + frappe: + image: frappe/bench:latest + command: sleep infinity + volumes: + - ..:/workspace:cached + ports: + - "8000:8000" + +volumes: + mariadb-vol: diff --git a/.gitignore b/.gitignore index 502c3673..cb373cae 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ # mounted volume sites + +development diff --git a/.travis.yml b/.travis.yml index 7042d7b0..d8d22dff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,12 +20,17 @@ after_success: matrix: include: - - name: "Build Frappe python environment (edge)" + - name: "Build Frappe bench development environment(latest)" if: branch = develop AND type != pull_request script: - - ./travis.py frappe --worker --tag edge - - ./travis.py frappe --worker --tag develop --tag-only - - name: "Build Frappe nginx + static assets (edge)" + - docker build -t frappe/bench:latest -f build/bench/Dockerfile . + - docker push frappe/bench:latest + - name: "Build Frappe python environment (edge)" + if: branch = develop AND type != pull_request + script: + - ./travis.py frappe --nginx --tag edge + - ./travis.py frappe --nginx --tag develop--tag-only + - name: "Build Frappe nginx + static assets (edge)" if: branch = develop AND type != pull_request script: - ./travis.py frappe --nginx --tag edge diff --git a/build/bench/Dockerfile b/build/bench/Dockerfile new file mode 100644 index 00000000..3f153bc7 --- /dev/null +++ b/build/bench/Dockerfile @@ -0,0 +1,58 @@ +# Frappe Bench Dockerfile + +FROM debian:9.6-slim +LABEL author=frappé + +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends locales \ + && sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \ + && dpkg-reconfigure --frontend=noninteractive locales \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +# Set locale en_us.UTF-8 for mariadb and general locale data +ENV PYTHONIOENCODING=utf-8 +ENV LANGUAGE=en_US.UTF-8 +ENV LANG=en_US.UTF-8 +ENV LC_ALL=en_US.UTF-8 + +# Install all neccesary packages +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-suggests --no-install-recommends \ + build-essential cron curl git libffi-dev liblcms2-dev libldap2-dev libmariadbclient-dev libsasl2-dev libssl1.0-dev libtiff5-dev \ + libwebp-dev mariadb-client iputils-ping python3-dev python3-pip python3-setuptools python3-tk redis-tools rlwrap \ + software-properties-common sudo tk8.6-dev vim xfonts-75dpi xfonts-base wget wkhtmltopdf fonts-cantarell \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +# Install nvm with node +ENV NVM_DIR /usr/local/nvm +ENV NODE_VERSION 12.16.1 +RUN mkdir /usr/local/nvm \ + && wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.35.2/install.sh | bash \ + && . $NVM_DIR/nvm.sh \ + && nvm install $NODE_VERSION \ + && nvm install 10.19.0 \ + && nvm alias default $NODE_VERSION \ + && nvm use default \ + && npm install yarn -g +ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules +ENV PATH $NVM_DIR/v$NODE_VERSION/bin:$PATH + +# Install wkhtmltox correctly +RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.stretch_amd64.deb +RUN dpkg -i wkhtmltox_0.12.5-1.stretch_amd64.deb && rm wkhtmltox_0.12.5-1.stretch_amd64.deb + + +# Add frappe user and setup sudo +RUN groupadd -g 1000 frappe \ + && useradd -ms /bin/bash -u 1000 -g 1000 -G sudo frappe \ + && chown -R 1000:1000 /home/frappe \ + && echo '. "$NVM_DIR/nvm.sh"' >> /home/frappe/.bashrc + +# Install bench +RUN pip3 install -e git+https://github.com/frappe/bench.git#egg=bench --no-cache + +USER frappe + +WORKDIR /home/frappe/frappe-bench + +EXPOSE 8000 9000 6787 + +VOLUME [ "/home/frappe/frappe-bench" ] diff --git a/development/.vscode/launch.json b/development/.vscode/launch.json new file mode 100644 index 00000000..21867b35 --- /dev/null +++ b/development/.vscode/launch.json @@ -0,0 +1,22 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Bench", + "type": "python", + "request": "launch", + "program": "${workspaceFolder}/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", + "args": [ + "frappe", "serve", "--port", "8000", "--noreload", "--nothreading" + ], + "pythonPath": "${workspaceFolder}/frappe-bench/env/bin/python", + "cwd": "${workspaceFolder}/frappe-bench/sites", + "env": { + "DEV_SERVER": "1" + } + } + ] +} \ No newline at end of file diff --git a/development/.vscode/settings.json b/development/.vscode/settings.json new file mode 100644 index 00000000..17a5d56d --- /dev/null +++ b/development/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "python.pythonPath": "frappe-bench/env/bin/python", + "debug.node.autoAttach": "on" +} \ No newline at end of file diff --git a/development/README.md b/development/README.md new file mode 100644 index 00000000..ba2aa311 --- /dev/null +++ b/development/README.md @@ -0,0 +1,118 @@ +# Getting Started + +## Prerequisites + +- Docker +- docker-compose +- user added to docker group + +### Bootstrap Containers for development + +Clone and change working directory to frappe_docker directory + +```shell +git clone https://github.com/frappe/frappe_docker.git +cd frappe_docker +``` + +#### Manually start containers + +```shell +docker-compose -f .devcontainer/docker-compose.yml up -d +``` + +Enter the bench container + +```shell +docker exec -e "TERM=xterm-256color" -w /workspace/development -it frappe bash +``` + +#### Use VSCode Remote Containers extension + +- Install Remote Development Pack / Remote Containers extension +- Install VSCode Python extension +- Open frappe_docker in VSCode +- From Command Palette (Ctrl + Shift + P) Execute Remote Containers : Reopen in Container + +### Setup Docker specific bench environment + +Notes: + +- `development` directory is ignored by it. It is mounted and available in container. Create all your benches inside this directory +- Execute these commands from container +- nvm with node v12 and v10 is installed. Check with `nvm ls`. Node v12 is default + +#### Setup first bench + +```shell +bench init --skip-redis-config-generation --frappe-branch version-12 frappe-bench +cd frappe-bench +``` + +#### Set hosts + +```shell +bench set-mariadb-host mariadb +bench set-redis-cache-host redis-cache:6379 +bench set-redis-queue-host redis-queue:6379 +bench set-redis-socketio-host redis-socketio:6379 +``` + +#### Changes related to bench start / honcho / Procfile + +- honcho/Procfile starts processes required for development. +- By default Procfile has 3 redis processes that it starts. Comment (`#`) or remove these lines and then run `bench start`. +- Another option is to run following command + +```shell +honcho start \ + web \ + socketio \ + watch \ + schedule \ + worker_short \ + worker_long \ + worker_default +``` + +#### Changes related to MariaDB + +Notes: + +- `bench new-site` command creates a user in mariadb with container IP as host +- After rebuilding container there is a chance that new bench container will not be able to access mariadb +- `'db_name'@'%'` needs to be set in mariadb and permission to the site database be given to the user +- Replace `db_name` and `db_password` from site's `site_config.json` +- MariaDB root password is 123 + +Enter mariadb shell + +```shell +mysql -uroot -p123 -hmariadb +``` + +Execute following queries + +```sql +UPDATE mysql.user SET Host = '%' where User = 'db_name'; FLUSH PRIVILEGES; +SET PASSWORD FOR 'db_name'@'%' = PASSWORD('db_password'); FLUSH PRIVILEGES; +GRANT ALL PRIVILEGES ON `db_name`.* TO 'db_name'@'%'; FLUSH PRIVILEGES; +``` + +### Visual Studio Code Python Debugging + +- Install VSCode Python Extension once in remote container +- Reload VSCode +- Do not start `web` process with honcho + +```shell +honcho start \ + socketio \ + watch \ + schedule \ + worker_short \ + worker_long \ + worker_default +``` + +- On debugger tab, Connect debugger. This will start the web process with debugger connected From 4771feee06ea5c9e89471e0e67ea5b262ac790d2 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Thu, 5 Mar 2020 22:04:43 +0530 Subject: [PATCH 3/7] fix: travis yml formatting --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d8d22dff..60881c42 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ after_success: matrix: include: - - name: "Build Frappe bench development environment(latest)" + - name: "Build Frappe bench development environment (latest)" if: branch = develop AND type != pull_request script: - docker build -t frappe/bench:latest -f build/bench/Dockerfile . @@ -30,7 +30,7 @@ matrix: script: - ./travis.py frappe --nginx --tag edge - ./travis.py frappe --nginx --tag develop--tag-only - - name: "Build Frappe nginx + static assets (edge)" + - name: "Build Frappe nginx + static assets (edge)" if: branch = develop AND type != pull_request script: - ./travis.py frappe --nginx --tag edge From 71763673b8f687416364381a76ebe6e6517e9c72 Mon Sep 17 00:00:00 2001 From: Davide Bortolami Date: Thu, 5 Mar 2020 16:39:32 +0000 Subject: [PATCH 4/7] merged documentation changes --- README.md | 136 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 105 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 611cde45..778f3680 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -### Getting Started +## Getting Started The templates in this repository will help deploy Frappe/ERPNext docker in a production environment. @@ -8,31 +8,13 @@ This docker installation takes care of the following: * Setting up all the system requirements: eg. MariaDB, Node, Redis. * [OPTIONAL] Configuring networking for remote access and setting up LetsEncrypt -### Installation Process +## Deployment -#### Setting up Pre-requisites +### Setting up Pre-requisites This repository requires Docker and Git to be setup on the instance to be used. -#### Setup Letsencrypt Nginx Proxy Companion - -This is an optional first step. This step is only required if you want to have SSL setup on your docker instance. - -This step also assumes that the DNS is preconfigured since it automatically handles setup and renewal of SSL certificates. - -For more details, see: https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion - -To setup the proxy companion, run the following steps: - -```sh -cd $HOME -git clone https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion.git -cd docker-compose-letsencrypt-nginx-proxy-companion -cp .env.sample .env -./start.sh -``` - -#### Setting up Frappe/ERPNext Docker +### Cloning the repository and preliminary steps Clone this repository somewhere in your system: @@ -43,7 +25,7 @@ cd frappe_docker Copy the example docker environment file to `.env`: -``` +```sh cp installation/env-example installation/.env ``` @@ -53,9 +35,7 @@ Make a directory for sites: mkdir installation/sites ``` -#### Setup Environment Variables - -Docker allows passing an environment file to aide in setting up containers, which is used by this repository to pass secret and variable data. +### Setup Environment Variables To get started, copy the existing `env-example` file to `.env` inside the `installation` directory. By default, the file will contain the following variables: @@ -68,13 +48,70 @@ To get started, copy the existing `env-example` file to `.env` inside the `insta - In case of a separately managed database setup, set the value to the database's hostname/IP/domain. - `SITES=site1.domain.com,site2.domain.com` - List of sites that are part of the deployment "bench". Each site is separated by a comma(,). - - If LetsEncrypt is being setup, make sure that the DNS for all the site domains are pointing to the current instance. + - If LetsEncrypt is being setup, make sure that the DNS for all the site's domains are pointing to the current instance. - `LETSENCRYPT_EMAIL=your.email@your.domain.com` - - Email for LetsEncrypt expiry notification. This is only required if you are setting up the nginx proxy companion. + - Email for LetsEncrypt expiry notification. This is only required if you are setting up LetsEncrypt. + + +### Deployment for local development + +To start the Frappe/ERPNext services for production, run the following command: + +For Erpnext: + + +```sh +docker-compose \ + --project-name \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-erpnext.yml \ + -f installation/docker-compose-networks.yml \ + --project-directory installation run --publish 80:80 erpnext-nginx +``` + +For Frappe: +```sh +docker-compose \ + --project-name \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-frappe.yml \ + -f installation/docker-compose-networks.yml \ + --project-directory installation run --publish 80:80 frappe-nginx +``` + +Make sure to replace `` with any desired name you wish to set for the project. + +Note: this command does not run docker-compose in daemon mode. You will need to keep the terminal window open. +Note: the local deployment is for testing only. The site names are limited to patterns matching \*.localhost. + + +### Deployment for production + +#### Setup Letsencrypt Nginx Proxy Companion + + + +Letsencrypt Nginx Proxy Companion can optionally be setup to provide SSL. This is recommended for istances accessed over the internet. + +Your DNS will need to be configured correctly in order for Letsencrypt to verify your domain. + +To setup the proxy companion, run the following commands: + +```sh +cd $HOME +git clone https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion.git +cd docker-compose-letsencrypt-nginx-proxy-companion +cp .env.sample .env +./start.sh +``` + +For more details, see: https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion +Letsencrypt Nginx Proxy Companion works by automatically proxing to containers with the `VIRTUAL_HOST` environmental variable. + #### Start Frappe/ERPNext Services -To start the Frappe/ERPNext services, run the following command: +To start the Frappe/ERPNext services for production, run the following command: ```sh docker-compose \ @@ -86,8 +123,45 @@ docker-compose \ ``` Make sure to replace `` with any desired name you wish to set for the project. +Note: use `docker-compose-frappe.yml` in case you need only Frappe without ERPNext. -Note: use `docker-compose-frappe.yml` in case you need bench with just frappe installed. + +### Docker containers + +This repository contains the following docker-compose files each one containing the described images: +* docker-compose-common.yml + * redis-cache + * volume: redis-cache-vol + * redis-queue + * volume: redis-queue-vol + * redis-socketio + * volume: redis-socketio-vol + * mariadb: main database + * volume: mariadb-vol +* docker-compose-erpnext.yml + * erpnext-nginx: serves static assets and proxies web request to the appropriate container, allowing to offer all services on the same port. + * volume: assets + * erpnext-python: main application code + * frappe-socketio: enables realtime comunication to the user interface through websockets + * frappe-worker-default: background runner + * frappe-worker-short: background runner for short-running jobs + * frappe-worker-long: background runner for long-running jobs + * frappe-schedule + +* docker-compose-frappe.yml + * frappe-nginx: serves static assets and proxies web request to the appropriate container, allowing to offer all services on the same port. + * volume: assets + * erpnext-python: main application code + * frappe-socketio: enables realtime comunication to the user interface through websockets + * frappe-worker-default: background runner + * frappe-worker-short: background runner for short-running jobs + * frappe-worker-long: background runner for long-running jobs + * frappe-schedule + +* docker-compose-networks.yml: this yml define the network to comunicate with *Letsencrypt Nginx Proxy Companion*. + + +### Site operations #### Setup New Sites @@ -161,7 +235,7 @@ docker exec -it \ _erpnext-python_1 docker-entrypoint.sh migrate ``` -### Troubleshoot +## Troubleshoot 1. Remove containers and volumes, and clear redis cache: From 7477e53428fc8e2389254de8680fbd2aa72271a0 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Thu, 5 Mar 2020 22:25:11 +0530 Subject: [PATCH 5/7] fix: travis yml indent error --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 60881c42..f6fda31b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,10 +26,10 @@ matrix: - docker build -t frappe/bench:latest -f build/bench/Dockerfile . - docker push frappe/bench:latest - name: "Build Frappe python environment (edge)" - if: branch = develop AND type != pull_request - script: - - ./travis.py frappe --nginx --tag edge - - ./travis.py frappe --nginx --tag develop--tag-only + if: branch = develop AND type != pull_request + script: + - ./travis.py frappe --nginx --tag edge + - ./travis.py frappe --nginx --tag develop--tag-only - name: "Build Frappe nginx + static assets (edge)" if: branch = develop AND type != pull_request script: From be3d90dd03d35948ad7da27fed7ac0a631476c31 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Thu, 5 Mar 2020 23:49:48 +0530 Subject: [PATCH 6/7] fix: bench image install nvm in user home allows npm install -g install yarn in v10 --- build/bench/Dockerfile | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/build/bench/Dockerfile b/build/bench/Dockerfile index 3f153bc7..a0f599ee 100644 --- a/build/bench/Dockerfile +++ b/build/bench/Dockerfile @@ -21,17 +21,25 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-ins software-properties-common sudo tk8.6-dev vim xfonts-75dpi xfonts-base wget wkhtmltopdf fonts-cantarell \ && apt-get clean && rm -rf /var/lib/apt/lists/* +# Add frappe user and setup sudo +RUN groupadd -g 1000 frappe \ + && useradd -ms /bin/bash -u 1000 -g 1000 -G sudo frappe \ + && chown -R 1000:1000 /home/frappe \ + && echo '. "$NVM_DIR/nvm.sh"' >> /home/frappe/.bashrc + # Install nvm with node -ENV NVM_DIR /usr/local/nvm +ENV NVM_DIR /home/frappe/.nvm ENV NODE_VERSION 12.16.1 -RUN mkdir /usr/local/nvm \ +RUN mkdir /home/frappe/.nvm \ && wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.35.2/install.sh | bash \ && . $NVM_DIR/nvm.sh \ && nvm install $NODE_VERSION \ && nvm install 10.19.0 \ + && npm install yarn -g \ && nvm alias default $NODE_VERSION \ && nvm use default \ - && npm install yarn -g + && npm install yarn -g \ + && chown -R frappe:frappe /home/frappe ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules ENV PATH $NVM_DIR/v$NODE_VERSION/bin:$PATH @@ -39,13 +47,6 @@ ENV PATH $NVM_DIR/v$NODE_VERSION/bin:$PATH RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.stretch_amd64.deb RUN dpkg -i wkhtmltox_0.12.5-1.stretch_amd64.deb && rm wkhtmltox_0.12.5-1.stretch_amd64.deb - -# Add frappe user and setup sudo -RUN groupadd -g 1000 frappe \ - && useradd -ms /bin/bash -u 1000 -g 1000 -G sudo frappe \ - && chown -R 1000:1000 /home/frappe \ - && echo '. "$NVM_DIR/nvm.sh"' >> /home/frappe/.bashrc - # Install bench RUN pip3 install -e git+https://github.com/frappe/bench.git#egg=bench --no-cache From 2f085ea2349ca20985524508cdcf2546cb0e221d Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Fri, 6 Mar 2020 06:45:54 +0530 Subject: [PATCH 7/7] fix: Improve README(s) --- README.md | 63 +++++++++++++++++++++++++++---------------- development/README.md | 39 +++++++++++++++------------ 2 files changed, 62 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 778f3680..9aadc8ef 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ This docker installation takes care of the following: * Setting up all the system requirements: eg. MariaDB, Node, Redis. * [OPTIONAL] Configuring networking for remote access and setting up LetsEncrypt +For docker based development refer this [README](development/README.md) + ## Deployment ### Setting up Pre-requisites @@ -53,45 +55,62 @@ To get started, copy the existing `env-example` file to `.env` inside the `insta - Email for LetsEncrypt expiry notification. This is only required if you are setting up LetsEncrypt. -### Deployment for local development +### Local deployment -To start the Frappe/ERPNext services for production, run the following command: +For trying out locally or to develop apps using ERPNext ReST API port 80 must be published. +First start the containers and then run an additional command to publish port of *-nginx container. + +To start and publish Frappe/ERPNext services as local api, run the following commands: For Erpnext: - ```sh -docker-compose \ +# Start services +docker-compose \ --project-name \ -f installation/docker-compose-common.yml \ -f installation/docker-compose-erpnext.yml \ - -f installation/docker-compose-networks.yml \ - --project-directory installation run --publish 80:80 erpnext-nginx + --project-directory installation up -d + +# Publish port +docker-compose \ + --project-name \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-erpnext.yml \ + --project-directory installation run --publish 80:80 -d erpnext-nginx ``` For Frappe: + ```sh -docker-compose \ +# Start services +docker-compose \ --project-name \ -f installation/docker-compose-common.yml \ -f installation/docker-compose-frappe.yml \ - -f installation/docker-compose-networks.yml \ - --project-directory installation run --publish 80:80 frappe-nginx + --project-directory installation up -d + +# Publish port +docker-compose \ + --project-name \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-frappe.yml \ + --project-directory installation run --publish 80:80 -d frappe-nginx ``` Make sure to replace `` with any desired name you wish to set for the project. -Note: this command does not run docker-compose in daemon mode. You will need to keep the terminal window open. -Note: the local deployment is for testing only. The site names are limited to patterns matching \*.localhost. - +Note: + - This command adds an additional container for frappe-nginx with published ports. + - The local deployment is for testing and REST API development purpose only. + - The site names are limited to patterns matching \*.localhost by default + - Additional site name patterns can be added to /etc/hosts of desired container or host ### Deployment for production #### Setup Letsencrypt Nginx Proxy Companion - - -Letsencrypt Nginx Proxy Companion can optionally be setup to provide SSL. This is recommended for istances accessed over the internet. +Letsencrypt Nginx Proxy Companion can optionally be setup to provide SSL. This is recommended for instances accessed over the internet. Your DNS will need to be configured correctly in order for Letsencrypt to verify your domain. @@ -106,8 +125,7 @@ cp .env.sample .env ``` For more details, see: https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion -Letsencrypt Nginx Proxy Companion works by automatically proxing to containers with the `VIRTUAL_HOST` environmental variable. - +Letsencrypt Nginx Proxy Companion works by automatically proxying to containers with the `VIRTUAL_HOST` environmental variable. #### Start Frappe/ERPNext Services @@ -125,7 +143,6 @@ docker-compose \ Make sure to replace `` with any desired name you wish to set for the project. Note: use `docker-compose-frappe.yml` in case you need only Frappe without ERPNext. - ### Docker containers This repository contains the following docker-compose files each one containing the described images: @@ -139,26 +156,26 @@ This repository contains the following docker-compose files each one containing * mariadb: main database * volume: mariadb-vol * docker-compose-erpnext.yml - * erpnext-nginx: serves static assets and proxies web request to the appropriate container, allowing to offer all services on the same port. + * erpnext-nginx: serves static assets and proxies web request to the appropriate container, allowing to offer all services on the same port. * volume: assets * erpnext-python: main application code - * frappe-socketio: enables realtime comunication to the user interface through websockets + * frappe-socketio: enables realtime communication to the user interface through websockets * frappe-worker-default: background runner * frappe-worker-short: background runner for short-running jobs * frappe-worker-long: background runner for long-running jobs * frappe-schedule * docker-compose-frappe.yml - * frappe-nginx: serves static assets and proxies web request to the appropriate container, allowing to offer all services on the same port. + * frappe-nginx: serves static assets and proxies web request to the appropriate container, allowing to offer all services on the same port. * volume: assets * erpnext-python: main application code - * frappe-socketio: enables realtime comunication to the user interface through websockets + * frappe-socketio: enables realtime communication to the user interface through websockets * frappe-worker-default: background runner * frappe-worker-short: background runner for short-running jobs * frappe-worker-long: background runner for long-running jobs * frappe-schedule -* docker-compose-networks.yml: this yml define the network to comunicate with *Letsencrypt Nginx Proxy Companion*. +* docker-compose-networks.yml: this yml define the network to communicate with *Letsencrypt Nginx Proxy Companion*. ### Site operations diff --git a/development/README.md b/development/README.md index ba2aa311..c7d78071 100644 --- a/development/README.md +++ b/development/README.md @@ -8,7 +8,7 @@ ### Bootstrap Containers for development -Clone and change working directory to frappe_docker directory +Clone and change to frappe_docker directory ```shell git clone https://github.com/frappe/frappe_docker.git @@ -17,30 +17,34 @@ cd frappe_docker #### Manually start containers +In case VS Code is not used follow these steps. + ```shell docker-compose -f .devcontainer/docker-compose.yml up -d ``` -Enter the bench container +Enter the bench container at location `/workspace/development` ```shell -docker exec -e "TERM=xterm-256color" -w /workspace/development -it frappe bash +docker exec -e "TERM=xterm-256color" -w /workspace/development -it devcontainer_frappe_1 bash ``` -#### Use VSCode Remote Containers extension +#### Use VS Code Remote Containers extension -- Install Remote Development Pack / Remote Containers extension -- Install VSCode Python extension -- Open frappe_docker in VSCode -- From Command Palette (Ctrl + Shift + P) Execute Remote Containers : Reopen in Container +Follow these in case VS Code is used. Do not start containers manually. + +- Install Remote Development Pack / Remote Containers extension. +- Install VS Code Python extension. +- Open frappe_docker in VS Code. +- From Command Palette (Ctrl + Shift + P) Execute Remote Containers : Reopen in Container. ### Setup Docker specific bench environment Notes: -- `development` directory is ignored by it. It is mounted and available in container. Create all your benches inside this directory -- Execute these commands from container -- nvm with node v12 and v10 is installed. Check with `nvm ls`. Node v12 is default +- `development` directory is ignored by git. It is mounted and available in container. Create all your benches inside this directory. +- Execute these commands from container. +- nvm with node v12 and v10 is installed. Check with `nvm ls`. Node v12 is default. #### Setup first bench @@ -62,7 +66,7 @@ bench set-redis-socketio-host redis-socketio:6379 - honcho/Procfile starts processes required for development. - By default Procfile has 3 redis processes that it starts. Comment (`#`) or remove these lines and then run `bench start`. -- Another option is to run following command +- Another option is to run following command : ```shell honcho start \ @@ -94,15 +98,16 @@ mysql -uroot -p123 -hmariadb Execute following queries ```sql -UPDATE mysql.user SET Host = '%' where User = 'db_name'; FLUSH PRIVILEGES; -SET PASSWORD FOR 'db_name'@'%' = PASSWORD('db_password'); FLUSH PRIVILEGES; -GRANT ALL PRIVILEGES ON `db_name`.* TO 'db_name'@'%'; FLUSH PRIVILEGES; +UPDATE mysql.user SET Host = '%' where User = 'db_name'; +SET PASSWORD FOR 'db_name'@'%' = PASSWORD('db_password'); +GRANT ALL PRIVILEGES ON `db_name`.* TO 'db_name'@'%'; +FLUSH PRIVILEGES; ``` ### Visual Studio Code Python Debugging -- Install VSCode Python Extension once in remote container -- Reload VSCode +- Install VS Code Python Extension once in remote container +- Reload VS Code - Do not start `web` process with honcho ```shell