Merge pull request #5 from chabad360/develop

Adds random fixes and improvements from Develop
This commit is contained in:
chabad360 2019-02-26 00:34:01 -05:00 committed by GitHub
commit 6609a8f200
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 125 additions and 160 deletions

7
.dockerignore Normal file
View file

@ -0,0 +1,7 @@
# frappe_docker .dockerignore file
conf/*
.travis.yml
test.py
dbench
docker-*.yml

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.code-workspace

View file

@ -2,11 +2,21 @@ language: python
python:
- "2.7"
env:
- DOCKER_COMPOSE_VERSION: 1.22.0
- DOCKER_COMPOSE_VERSION: 1.23.1
services:
- docker
before_install:
- 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
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
- sudo rm /usr/local/bin/docker-compose
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
install:
- chmod ugo+x ./dbench
- ./dbench setup docker

View file

@ -1,34 +1,44 @@
#bench Dockerfile
# Frappe Bench Dockerfile
FROM ubuntu:16.04
LABEL MAINTAINER frappé
LABEL author=frappé
USER root
# Generate locale C.UTF-8 for mariadb and general locale data
# Set 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 && apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# 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 \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
RUN pip install --upgrade setuptools pip && rm -rf ~/.cache/pip
RUN useradd -ms /bin/bash -G sudo frappe && printf '# User rules for frappe\nfrappe ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/frappe
#nodejs
# 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 \
&& dpkg -i node.deb \
&& rm node.deb
&& dpkg -i node.deb \
&& rm node.deb \
&& npm install -g yarn
# Add frappe user and setup sudo
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
RUN git clone -b master https://github.com/frappe/bench.git bench-repo
# Add some bench files
COPY --chown=frappe:frappe ./frappe-bench /home/frappe/frappe-bench
USER root
RUN pip install -e bench-repo && rm -rf ~/.cache/pip \
&& npm install -g yarn \
&& chown -R frappe:frappe /home/frappe/*
# 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
VOLUME [ "/home/frappe/frappe-bench" ]

137
README.md
View file

@ -1,130 +1,65 @@
# frappe_docker
# Frappe on Docker
[![Build Status](https://travis-ci.org/frappe/frappe_docker.svg?branch=master)](https://travis-ci.org/frappe/frappe_docker)
- [Docker](https://docker.com/) is an open source project to pack, ship and run any Linux application in a lighter weight, faster container than a traditional virtual machine.
- Docker makes it much easier to deploy [frappe](https://github.com/frappe/frappe) on your servers.
- This container uses [bench](https://github.com/frappe/bench) to install frappe.
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. See deployment for notes on how to deploy the project on a live system.
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.
### Prerequisites
[Docker](https://www.docker.com/)
[Docker Compose](https://docs.docker.com/compose/overview/)
### Container Configuration
#### ports:
```
ports:
- "3307:3307" mariadb-port
- "8000:8000" webserver-port
- "11000:11000" redis-cache
- "12000:12000" redis-queue
- "13000:13000" redis-socketio
- "9000:9000" socketio-port
- "6787:6787" file-watcher-port
```
Expose port 3307 inside the container on port 3307 on ALL local host interfaces. In order to bind to only one interface, you may specify the host's IP address as `([<host_interface>:[host_port]])|(<host_port>):<container_port>[/udp]` as defined in the [docker port binding documentation](http://docs.docker.com/userguide/dockerlinks/). The port 3307 of the mariadb container and port 8000 of the frappe container is exposed to the host machine and other containers.
#### volumes:
```
volumes:
- ./frappe-bench:/home/frappe/frappe-bench
- ./conf/mariadb-conf.d:/etc/mysql/conf.d
- ./redis-conf/redis_socketio.conf:/etc/conf.d/redis.conf
- ./redis-conf/redis_queue.conf:/etc/conf.d/redis.conf
- ./redis-conf/redis_cache.conf:/etc/conf.d/redis.conf
```
Exposes a directory inside the host to the container.
#### links:
```
links:
- redis-cache
- redis-queue
- redis-socketio
- mariadb
```
Links allow you to define extra aliases by which a service is reachable from another service.
#### depends_on:
```
depends_on:
- mariadb
- redis-cache
- redis-queue
- redis-socketio
```
Express dependency between services, which has two effects:
1. docker-compose up will start services in dependency order. In the following example, mariadb and redis will be started before frappe.
2. docker-compose up SERVICE will automatically include SERVICEs dependencies. In the following example, docker-compose up docker_frappe will also create and start mariadb and redis.
### Installation
#### 1. Installation Pre-requisites
### 1. Installation Pre-requisites
- Install [Docker](https://docs.docker.com/engine/installation) Community Edition
- Install [Docker Compose](https://docs.docker.com/compose/install/) (only for Linux users). Docker for Mac, Docker for Windows, and Docker Toolbox include Docker Compose
- 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).
#### 2. Build the container and install bench
### 2. Build the container and initialize the bench
* Clone this repo and change your working directory to frappe_docker
1. 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
```bash
git clone https://github.com/frappe/frappe_docker.git
cd frappe_docker
```
* Build the container and install bench inside the container.
2. Build and start the container, and initialize the bench
1.Build the 5 linked containers frappe, mariadb, redis-cache, redis-queue and redis-socketio using this command. Make sure your current working directory is frappe_docker which contains the docker-compose.yml and Dockerfile.
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)
```bash
./dbench setup docker
./dbench init
```
./dbench setup docker
Note: This will take a while, as docker will now build the container.
Note: Please do not remove the bench-repo directory the above commands will create
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*
#### Basic Usage
##### Make sure your current directory is frappe_docker
1. First time setup
- `./dbench`: Launches you into an interactive shell in the container as user frappe
./dbench init
- `./dbench setup docker [ stop | down ]`: Starts and builds the docker containers using `docker-compose up -d`
2. Command to be executed everytime after starting your containers
- `./dbench setup hosts`: Adds all sites to the containers hosts file.
Do this after you've added a new site to avoid errors.
./dbench setup hosts
- `./dbench -c frappe | root <command to run>`: Runs a command in the container, as the selected user
3. Command to enter your container
- `./dbench -h`: Shows this help message
./dbench
- `./dbench <bench command>`: Runs a command in bench, (Running `./dbench new-site site1.local` will run in the conatiner as `bench new-site site1.local`)
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```.
*Always make sure that your current directory is the root directory of the repo (i.e. `frappe_docker/`)
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.
## Built With
* [Docker](https://www.docker.com/)
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

View file

@ -27,3 +27,12 @@ collation-server = utf8mb4_unicode_ci
[mysql]
default-character-set = utf8mb4
[mysqld_safe]
skip_log_error
syslog
[mysqldump]
quick
quote-names
max_allowed_packet = 16M

View file

@ -1,2 +0,0 @@
[mysql]

View file

@ -1,4 +0,0 @@
[mysqld_safe]
skip_log_error
syslog

View file

@ -1,5 +0,0 @@
[mysqldump]
quick
quote-names
max_allowed_packet = 16M

View file

@ -1 +0,0 @@
20

View file

@ -1 +0,0 @@
24

View file

@ -1 +0,0 @@
29

42
dbench
View file

@ -1,41 +1,47 @@
#!/bin/bash
function run () {
user=$1
shift
docker exec -itu "${user}" frappe bash -c "$@"
}
if [[ $# -eq 0 ]]; then
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 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 && bench set-mariadb-host mariadb"
elif [ "$1" == 'setup' ] && [ "$2" == 'docker' ]; then
if [ "$3" == '--swarm-mode' ]; then
elif [[ "$1" == 'init' ]]; then
run root "chown -R frappe:frappe /home/frappe"
run frappe "cd .. && bench init frappe-bench --ignore-exist --skip-redis-config-generation && cd frappe-bench"
run frappe "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"
elif [ "$3" == 'down' ]; then
elif [[ "$3" == 'down' ]]; then
docker-compose down
elif [ "$3" == 'stop' ]; then
elif [[ "$3" == 'stop' ]]; then
docker-compose stop
else
docker-compose up -d
fi
elif [ "$1" == 'setup' ] && [ "$2" == 'hosts' ]; then
a=$(cd frappe-bench && ls sites/*/site_config.json | grep -o '/.\+/')
elif [[ "$2" == 'hosts' ]]; then
a=$(run frappe "ls sites/*/site_config.json | grep -o '/.\+/'") \
a="${a//$'\n'/ }"
a=$(echo $a | tr -d / )
a=$(echo "$a" | tr -d / )
result="127.0.0.1 ${a}"
docker exec -iu root frappe bash -c "echo ${result} | tee --append /etc/hosts"
elif [ "$1" == '-c' ]; then
run root "echo ${result} | tee --append /etc/hosts"
fi
elif [[ "$1" == '-c' ]]; then
shift
user=$1
shift
docker exec -iu $user frappe bash -c "$@"
elif [ "$1" == '-h' ]; then
run "$user" "$@"
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 [ stop | down ]"
echo " Starts and builds the docker containers using \"docker-compose up -d\""
echo " $0 setup hosts"
@ -48,5 +54,5 @@ elif [ "$1" == '-h' ]; then
echo " Runs a command in bench, i.e. $0 new-site site1.local = bench new-site site1.local"
else
IFS=" "
docker exec -it frappe bash -c "bench $*"
run frappe "bench $*"
fi

View file

@ -1,4 +1,4 @@
version: '3.3'
version: '3.7'
services:
mariadb:
image: mariadb
@ -20,7 +20,7 @@ services:
image: redis:alpine
volumes:
- ./conf/redis-conf:/etc/conf.d
- ./conf/redis-conf.d:/etc/conf.d
command: ["redis-server","/etc/conf.d/redis_cache.conf"]
@ -29,8 +29,9 @@ services:
redis-queue:
image: redis:alpine
volumes:
- ./conf/redis-conf:/etc/conf.d
- ./conf/redis-conf.d:/etc/conf.d
command: ["redis-server","/etc/conf.d/redis_queue.conf"]
@ -40,7 +41,7 @@ services:
image: redis:alpine
volumes:
- ./conf/redis-conf:/etc/conf.d
- ./conf/redis-conf.d:/etc/conf.d
command: ["redis-server","/etc/conf.d/redis_socketio.conf"]
@ -50,9 +51,9 @@ services:
frappe:
volumes:
- ./frappe-bench:/home/frappe/frappe-bench
- ./conf/redis-conf/redis_cache.conf:/home/frappe/frappe-bench/config/redis_cache.conf
- ./conf/redis-conf/redis_queue.conf:/home/frappe/frappe-bench/config/redis_queue.conf
- ./conf/redis-conf/redis_socketio.conf:/home/frappe/frappe-bench/config/redis_socketio.conf
- ./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

View file

@ -13,7 +13,7 @@ def print_out(val,delay):
elif val == 2:
try:
global r
r = requests.get("http://site1.local:8000")
r = requests.get("http://localhost:8000")
print(r)
except requests.exceptions.ConnectionError as e:
print(e)