From 0361b281f98cadbb18e1d41fe293393cca2233ef Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Mon, 27 Apr 2020 13:36:33 +0530 Subject: [PATCH] fix: README single command to deploy locally env file placed where docker-compose will be executed --- README.md | 133 ++++++------------------ installation/env-example => env-example | 0 installation/erpnext-publish.yml | 6 ++ installation/frappe-publish.yml | 6 ++ 4 files changed, 44 insertions(+), 101 deletions(-) rename installation/env-example => env-example (100%) create mode 100644 installation/erpnext-publish.yml create mode 100644 installation/frappe-publish.yml diff --git a/README.md b/README.md index 9b87e994..5e24bf91 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ For docker based development refer to this [README](development/README.md) ### Setting up Pre-requisites -This repository requires Docker and Git to be setup on the instance to be used. +This repository requires Docker, docker-compose and Git to be setup on the instance to be used. ### Cloning the repository and preliminary steps @@ -33,7 +33,7 @@ cd frappe_docker Copy the example docker environment file to `.env`: ```sh -cp installation/env-example installation/.env +cp env-example .env ``` ### Setup Environment Variables @@ -63,37 +63,23 @@ The first command will start the containers; the second command will publish the For Erpnext: ```sh -# Start services docker-compose \ --project-name \ -f installation/docker-compose-common.yml \ -f installation/docker-compose-erpnext.yml \ - --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 + -f installation/erpnext-publish.yml \ + up -d ``` For Frappe: ```sh -# Start services docker-compose \ --project-name \ -f installation/docker-compose-common.yml \ -f installation/docker-compose-frappe.yml \ - --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 + -f installation/frappe-publish.yml \ + up -d ``` Make sure to replace `` with the desired name you wish to set for the project. @@ -124,8 +110,16 @@ cp .env.sample .env ./start.sh ``` +It will create the required network and configure containers for Letencrypt ACME. + For more details, see the [Letsencrypt Nginx Proxy Companion github repo](https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion). Letsencrypt Nginx Proxy Companion github repo works by automatically proxying to containers with the `VIRTUAL_HOST` environmental variable. +Notes: + +- `SITES` variables from `env-example` is set as `VIRTUAL_HOST` +- `LETSENCRYPT_EMAIL` variables from `env-example` is used as it is. +- This is simple nginx + letsencrypt solution. Any other solution can be setup. Above two variables can be re-used or removed in case any other reverse-proxy is used. + #### Start Frappe/ERPNext Services To start the Frappe/ERPNext services for production, run the following command: @@ -136,7 +130,7 @@ docker-compose \ -f installation/docker-compose-common.yml \ -f installation/docker-compose-erpnext.yml \ -f installation/docker-compose-networks.yml \ - --project-directory installation up -d + up -d ``` Make sure to replace `` with any desired name you wish to set for the project. @@ -159,7 +153,7 @@ docker run \ Instead of `alpine` you can use any image you like. -For full instructions, refer to the [wiki](https://github.com/frappe/frappe/wiki/Using-Frappe-with-Amazon-RDS-(or-any-other-DBaaS). Common question can be found in Issues and on forum. +For full instructions, refer to the [wiki](https://github.com/frappe/frappe/wiki/Using-Frappe-with-Amazon-RDS-(or-any-other-DBaaS)). Common question can be found in Issues and on forum. ### Docker containers @@ -201,6 +195,9 @@ This repository contains the following docker-compose files, each one containing * docker-compose-networks.yml: this yaml define the network to communicate with *Letsencrypt Nginx Proxy Companion*. +* erpnext-publish.yml: this yml extends erpnext-nginx service to publish port 80, can only be used with docker-compose-erpnext.yml + +* frappe-publish.yml: this yml extends frappe-nginx service to publish port 80, can only be used with docker-compose-frappe.yml ### Site operations @@ -215,13 +212,15 @@ Note: ```sh # Create ERPNext site -docker exec -it \ +docker run \ -e "SITE_NAME=$SITE_NAME" \ -e "DB_ROOT_USER=$DB_ROOT_USER" \ -e "MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD" \ -e "ADMIN_PASSWORD=$ADMIN_PASSWORD" \ -e "INSTALL_APPS=erpnext" \ - _erpnext-python_1 docker-entrypoint.sh new + -v _sites-vol:/home/frappe/frappe-bench/sites \ + --network _default \ + frappe/erpnext-worker:edge new ``` Environment Variables needed: @@ -246,10 +245,12 @@ Environment Variables - All the files generated by backup are placed at volume location `sites-vol:/{site-name}/private/backups/*` ```sh -docker exec -it \ +docker run \ -e "SITES=site1.domain.com:site2.domain.com" \ -e "WITH_FILES=1" \ - _erpnext-python_1 docker-entrypoint.sh backup + -v _sites-vol:/home/frappe/frappe-bench/sites \ + --network _default \ + frappe/erpnext-worker:edge backup ``` The backup will be available in the `sites-vol` volume. @@ -306,11 +307,13 @@ docker-compose \ -f installation/docker-compose-common.yml \ -f installation/docker-compose-erpnext.yml \ -f installation/docker-compose-networks.yml \ - --project-directory installation up -d + up -d -docker exec -it \ +docker run \ -e "MAINTENANCE_MODE=1" \ - _erpnext-python_1 docker-entrypoint.sh migrate + -v _sites-vol:/home/frappe/frappe-bench/sites \ + --network _default \ + frappe/erpnext-worker:edge migrate ``` #### Restore backups @@ -410,78 +413,6 @@ sed -i "s#\[app\]#[custom]#" ./installation/docker-compose-custom.yml Install like usual, except that when you set the `INSTALL_APPS` variable to `erpnext,[custom]`. -## Troubleshoot - -### Failed migration after image upgrade - -Issue: After upgrade of the containers, the automatic migration fails. -Solution: Remove containers and volumes, and clear redis cache: - -```shell -# change to repo root -cd $HOME/frappe_docker - -# Stop all bench containers -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 stop - -# Remove redis containers -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 rm redis-cache redis-queue redis-socketio - -# Clean redis volumes -docker volume rm \ - _redis-cache-vol \ - _redis-queue-vol \ - _redis-socketio-vol - -# Restart project -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 up -d -``` - -### ValueError: There exists an active worker named XXX already - -Issue: You have the following error during container restart - - -``` -frappe-worker-short_1 | Traceback (most recent call last): -frappe-worker-short_1 | File "/home/frappe/frappe-bench/commands/worker.py", line 5, in -frappe-worker-short_1 | start_worker(queue, False) -frappe-worker-short_1 | File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/background_jobs.py", line 147, in start_worker -frappe-worker-short_1 | Worker(queues, name=get_worker_name(queue)).work(logging_level = logging_level) -frappe-worker-short_1 | File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/rq/worker.py", line 474, in work -frappe-worker-short_1 | self.register_birth() -frappe-worker-short_1 | File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/rq/worker.py", line 261, in register_birth -frappe-worker-short_1 | raise ValueError(msg.format(self.name)) -frappe-worker-short_1 | ValueError: There exists an active worker named '8dfe5c234085.10.short' already -``` - -Solution: Clear redis cache using `docker exec` command (take care of replacing `` accordingly): - -```sh -# Clear the cache which is causing problem. - -docker exec -it _redis-cache_1 redis-cli FLUSHALL -docker exec -it _redis-queue_1 redis-cli FLUSHALL -docker exec -it _redis-socketio_1 redis-cli FLUSHALL -``` - -Note: Environment variables from `.env` file located at the current working directory will be used. - ## Development This repository includes a complete setup to develop with Frappe/ERPNext and Bench, Including the following features: diff --git a/installation/env-example b/env-example similarity index 100% rename from installation/env-example rename to env-example diff --git a/installation/erpnext-publish.yml b/installation/erpnext-publish.yml new file mode 100644 index 00000000..6975442a --- /dev/null +++ b/installation/erpnext-publish.yml @@ -0,0 +1,6 @@ +version: "3" + +services: + erpnext-nginx: + ports: + - "80:80" diff --git a/installation/frappe-publish.yml b/installation/frappe-publish.yml new file mode 100644 index 00000000..a3f4caa9 --- /dev/null +++ b/installation/frappe-publish.yml @@ -0,0 +1,6 @@ +version: "3" + +services: + frappe-nginx: + ports: + - "80:80"