This commit is contained in:
chabad360 2018-08-09 22:40:59 +00:00 committed by GitHub
commit 95e5ef5ed8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 242 additions and 103 deletions

View file

@ -1,21 +1,28 @@
sudo: required
language: python language: python
python: python:
- "2.7" - "2.7"
env: env:
- DOCKER_COMPOSE_VERSION: 1.8.0 - DOCKER_COMPOSE_VERSION: 1.8.0
services: services:
- docker - docker
before_install:
- 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
- chmod ugo+x ./dbench
- chmod ugo+x ./curl-travis
install: install:
- docker-compose build - ./dbench --setup -u
- docker-compose up -d - ./dbench --init
- docker exec -it -u root frappe bash -c "cd /home/frappe && chown -R frappe:frappe ./*" - ./dbench --start
- docker exec -i frappe bash -c "cd .. && bench init frappe-bench --skip-bench-mkdir --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'
- pip install --upgrade virtualenv - pip install --upgrade virtualenv
- virtualenv -p python3 testenv - virtualenv -p python3 testenv
- source testenv/bin/activate - source testenv/bin/activate
@ -29,3 +36,4 @@ script:
- docker-compose ps | grep -i mariadb - docker-compose ps | grep -i mariadb
- python test.py - python test.py
- docker-compose stop - docker-compose stop
- ./curl-travis

View file

@ -1,8 +1,8 @@

#bench Dockerfile #bench Dockerfile
FROM ubuntu:16.04 FROM ubuntu:16.04
MAINTAINER frappé LABEL Author frappé
USER root USER root
RUN apt-get update RUN apt-get update
@ -18,6 +18,7 @@ RUN apt-get install -y curl
RUN apt-get install -y rlwrap RUN apt-get install -y rlwrap
RUN apt-get install redis-tools RUN apt-get install redis-tools
RUN apt-get install -y nano RUN apt-get install -y nano
RUN apt-get install -y cron
# Generate locale C.UTF-8 for mariadb and general locale data # Generate locale C.UTF-8 for mariadb and general locale data
ENV LANG C.UTF-8 ENV LANG C.UTF-8
@ -37,7 +38,8 @@ USER root
RUN pip install -e bench-repo RUN pip install -e bench-repo
RUN apt-get install -y libmysqlclient-dev mariadb-client mariadb-common RUN apt-get install -y libmysqlclient-dev mariadb-client mariadb-common
RUN npm install -g yarn RUN npm install -g yarn
RUN chown -R frappe:frappe /home/frappe/* RUN chown -R frappe:frappe /home/frappe
ENV PATH /home/frappe/.local/bin:$PATH
USER frappe USER frappe
WORKDIR /home/frappe/frappe-bench WORKDIR /home/frappe/frappe-bench

View file

@ -1,5 +1,8 @@
# frappe_docker # frappe_docker
[![Build Status](https://travis-ci.org/frappe/frappe_docker.svg?branch=master)](https://travis-ci.org/frappe/frappe_docker)
| `latest` | `develop` | `arm` |
|:--------:|:---------:|:-----:|
| [![Build Status](https://travis-ci.org/chabad360/frappe_docker.svg?branch=master)](https://travis-ci.org/chabad360/frappe_docker) | [![Build Status](https://travis-ci.org/chabad360/frappe_docker.svg?branch=develop)](https://travis-ci.org/chabad360/frappe_docker) | [![Build Status](https://travis-ci.org/chabad360/frappe_docker.svg?branch=arm)](https://travis-ci.org/chabad360/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](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.
@ -19,9 +22,9 @@ These instructions will get you a copy of the project up and running on your loc
### Container Configuration ### Container Configuration
#### ports: #### Ports
``` ```bash
ports: ports:
- "3307:3307" mariadb-port - "3307:3307" mariadb-port
- "8000:8000" webserver-port - "8000:8000" webserver-port
@ -32,11 +35,11 @@ ports:
- "6787:6787" file-watcher-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. 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
``` ```bash
volumes: volumes:
- ./frappe-bench:/home/frappe/frappe-bench - ./frappe-bench:/home/frappe/frappe-bench
- ./conf/mariadb-conf.d:/etc/mysql/conf.d - ./conf/mariadb-conf.d:/etc/mysql/conf.d
@ -44,11 +47,12 @@ volumes:
- ./redis-conf/redis_queue.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 - ./redis-conf/redis_cache.conf:/etc/conf.d/redis.conf
``` ```
Exposes a directory inside the host to the container. Exposes a directory inside the host to the container.
#### links: #### Links
``` ```bash
links: links:
- redis-cache - redis-cache
- redis-queue - redis-queue
@ -58,20 +62,21 @@ links:
Links allow you to define extra aliases by which a service is reachable from another service. Links allow you to define extra aliases by which a service is reachable from another service.
#### depends_on: #### Depends_on
``` ```bash
depends_on: depends_on:
- mariadb - mariadb
- redis-cache - redis-cache
- redis-queue - redis-queue
- redis-socketio - redis-socketio
``` ```
Express dependency between services, which has two effects: 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. 1. `docker-compose up -d` 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. 2. `docker-compose up SERVICE` will automatically include `SERVICE`s dependencies. In the following example, `docker-compose up -d frappe` will also create and start MariaDB and Redis.
### Installation ### Installation
@ -81,54 +86,49 @@ Express dependency between services, which has two effects:
- 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 include Docker Compose
#### 2. Build the container and install bench #### 2. Build the container
* Clone this repo and change your working directory to frappe_docker - Clone this repo and change your working directory to frappe_docker
git clone --depth 1 https://github.com/frappe/frappe_docker.git git clone --depth 1 https://github.com/chabad360/frappe_docker.git
cd frappe_docker cd frappe_docker
* Build the container and install bench inside the container. - Build the container and install bench inside the container.
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. 1. Build and start the 5 linked containers frappe, mariadb, redis-cache, redis-queue and redis-socketio using this command.
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 -u
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)
Note: Please do not remove the bench-repo directory the above commands will create Note: Please do not remove the bench-repo directory the above commands will create
#### 3. Install and Start Bench
#### Basic Usage
##### Make sure your current directory is frappe_docker
1. First time setup 1. First time setup
./dbench init ./dbench --init
2. Command to start all the containers 2. Command to start all the containers
docker-compose start ./dbench --start
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 - 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 `./dbench -c`. For more information on `dbench` run the command `./dbench -h`.
docker exec -it frappe bash For more info on how to build this docker container refer to this [Wiki](https://github.com/chabad360/frappe_docker/wiki/First-Timers-Manual)
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```. To login to Frappe / ERPNext, open your browser and go to `[your-external-ip]:8000`, or `localhost:8000`
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) 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.
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 ## Built With
* [Docker](https://www.docker.com/) - [Docker](https://www.docker.com/)
## Contributing ## Contributing

View file

@ -21,9 +21,9 @@ bind-address = 0.0.0.0
[mysqld] [mysqld]
innodb-file-format=barracuda #innodb-file-format=barracuda
innodb-file-per-table=1 #innodb-file-per-table=1
innodb-large-prefix=1 #innodb-large-prefix=1
character-set-client-handshake = FALSE character-set-client-handshake = FALSE
character-set-server = utf8mb4 character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci collation-server = utf8mb4_unicode_ci

3
curl-travis Normal file
View file

@ -0,0 +1,3 @@
#!/bin/bash
curl -H "Content-Type: application/json" --data '{"docker_tag": "latest"}' -X POST https://registry.hub.docker.com/u/chabad360/frappe/trigger/$hubkey/

210
dbench Executable file → Normal file
View file

@ -1,57 +1,183 @@
#!/bin/bash #!/bin/bash
display_usage() { function usage {
echo "$(basename "$0") [-h] [-c \"<command to be executed inside container>\"]" echo "Usage: $(basename "$0") [ --setup [-u] | --init [-m -e -d] [sitename] | --start [-b] | -h (--help) | -d (--developer) [sitename] | -a (--add) | -c \"Command to be sent to Frappe Bench on Docker\""
echo '' echo ''
echo 'where:' echo 'where:'
echo ' -h show this help text' echo ' dbench loads up container'
echo ' -c execute a command inside docker using docker exec' echo ' -c "command" send a command to bench in the container'
echo ' -s adds site-names to /etc/hosts file in the container to facilitate multisite access' echo ' -h | --help show this help text'
echo ' init initializes frappe-bench adds a new-site bench-manager.local and installs the bench_manager app echo ' -d | --developer [sitename] enables developer mode for "sitename" (if not specified, it will default to site1.local)'
app onto it' echo ' -a | --add adds site-names to /etc/hosts file in the container to facilitate multisite access'
echo ' --setup [-u] builds docker containers, NOTE: assumes you have docker installed'
echo ' -u start up docker containers as well'
echo ' --init [-m -e -d] [sitename] initializes frappe-bench in docker and adds a site "sitename" (if not specified, it will default to site1.local)'
echo ' -e initializes frappe-bench and installs erpnext'
echo ' --start [-b] starts frappe docker'
echo ' -b starts bench as well'
} }
if [[ $# -eq 0 ]]; then function frappe_installer {
docker exec -it frappe bash echo "starting frappe_docker setup"
elif [ $1 == 'init' ]
then
docker exec -i -u root frappe bash -c "cd /home/frappe && chown -R frappe:frappe ./*" 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 -i 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 -i 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 vim && apt-get install sudo && usermod -aG sudo frappe && printf '# User rules for frappe\nfrappe ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/frappe" echo "frappe-bench folder setup"
docker exec -it frappe bash -c "bench set-mariadb-host mariadb" docker exec -i -u root frappe bash -c "apt-get install vim -y && apt-get install sudo -y && 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 new-site site1.local" echo "adding $1"
docker exec -it frappe bash -c "bench get-app erpnext" docker exec -i frappe bash -c "bench new-site $1"
docker exec -it frappe bash -c "bench --site site1.local install-app erpnext" docker exec -i -u root frappe bash -c "echo 127.0.0.1 $1 >> /etc/hosts"
sudo su -c 'echo 127.0.0.1 $1 >> /etc/hosts'
echo "$1 added"
}
else
while getopts ':hsc:' option; do add=0
case "$option" in setup=0
h) up=0
display_usage start=0
exit init=0
dev=0
erp=0
mgr=0
site=0
bench=0
cmd=0
positional=()
if [ $# == 0 ]; then
docker exec -it frappe bash
exit 0
fi
while [[ $# -gt 0 ]]; do
key="$1"
case "$key" in
-h | --help)
usage
exit 0
;; ;;
c) -a | --add)
docker exec -it frappe bash -c "bench $OPTARG" add=1
;; ;;
s) -d | --developer)
a=$(cd frappe-bench && ls sites/*/site_config.json | grep -o '/.\+/') dev=1
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"
;; ;;
\?) -c)
echo "Invalid option: -$OPTARG" >&2 cmd=1
exit 1
;; ;;
:) -e)
echo "Option -$OPTARG requires an argument." >&2 erp=1
exit 1 ;;
-u)
up=1
;;
-m)
mgr=1
;;
-b)
bench=1
;;
--setup)
setup=1
;;
--init)
init=1
;;
--start)
start=1
;;
*)
positional+=("$key")
;; ;;
esac esac
done shift
done
set -- "${positional[@]}"
site="$1"
if [ -z "$1" ]; then
site="site1.local"
fi fi
if [ $setup == 1 ]; then
docker-compose build
if [ $up == 1 ]; then
docker-compose up -d
else
docker-compose up
fi
exit 0
fi
if [ $init == 1 ]; then
frappe_installer "$site"
if [ $mgr == 1 ]; then
echo "installing bench manager"
docker exec -it frappe bash -c "bench setup manager"
fi
if [ $erp == 1 ]; then
echo "installing erpnext"
docker exec -i frappe bash -c "bench get-app erpnext"
docker exec -i frappe bash -c "bench --site $site install-app erpnext"
docker exec -i -u root frappe bash -c "bench --site $site set-config \"developer_mode\" 1 && bench clear-cache"
echo "finished"
fi
if [ $dev == 1 ]; then
docker exec -it -u root frappe bash -c "bench --site $site set-config \"developer_mode\" 1 && bench clear-cache"
fi
exit 0
fi
if [ $dev == 1 ]; then
if [ "$site" == 0 ]; then
site="site1.local"
fi
docker exec -it -u root frappe bash -c "bench --site $site set-config \"developer_mode\" 1 && bench clear-cache"
exit 0
fi
if [ $start == 1 ]; then
docker-compose start
./dbench -a
if [ $bench == 1 ]; then
docker exec -it frappe bash -c "bench start"
fi
exit 0
fi
if [ $dev == 1 ]; then
docker exec -it -u root frappe bash -c "bench --site $site set-config \"developer_mode\" 1 && bench clear-cache"
exit 0
fi
if [ $cmd == 1 ]; then
docker exec -it frappe bash -c "bench $*"
exit 0
fi
if [ $add == 1 ]; then
a=$(docker exec -i frappe bash -c "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"
exit 0
fi
if "$*"; then
echo "Incorrect option $*, please make sure you are entering the correct commands"
usage
exit 1
fi
exit 0

View file

@ -1,7 +1,7 @@
version: '2' version: '2'
services: services:
mariadb: mariadb:
image: "mariadb" image: "mariadb:latest"
environment: environment:
- MYSQL_ROOT_PASSWORD=123 - MYSQL_ROOT_PASSWORD=123
- MYSQL_USER=root - MYSQL_USER=root

View file

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