2
0
mirror of https://github.com/frappe/frappe_docker.git synced 2024-12-23 18:48:58 +00:00

improvements to travis and dbench (#53)

This PR adds the `bench` script, which aims for near parity with frappe bench, it makes setting up far easier, because instead of running `./dbench -c "new-site site1.local"` you only white what you would if bench was installed on the local system (i.e. `./bench new-site site1.local`), it also adds other features as well.
This commit is contained in:
chabad360 2018-10-12 20:05:29 -07:00 committed by Chinmay Pai
parent e079c479f5
commit 2b1334d5a5
4 changed files with 74 additions and 86 deletions

View File

@ -2,20 +2,17 @@ language: python
python:
- "2.7"
env:
- DOCKER_COMPOSE_VERSION: 1.8.0
- DOCKER_COMPOSE_VERSION: 1.22.0
services:
- docker
install:
- docker-compose build
- docker-compose up -d
- docker exec -it -u 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"
- 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'
- chmod ugo+x ./dbench
- ./dbench setup docker
- ./dbench init frappe-bench
- ./dbench new-site site1.local
- sudo ./dbench setup hosts
- pip install --upgrade virtualenv
- virtualenv -p python3 testenv
- source testenv/bin/activate

View File

@ -5,17 +5,16 @@ FROM ubuntu:16.04
LABEL MAINTAINER frappé
USER root
RUN useradd -ms /bin/bash frappe
RUN apt-get update
RUN apt-get install -y iputils-ping git build-essential python-setuptools python-dev libffi-dev libssl-dev \
redis-tools redis-server software-properties-common libxrender1 libxext6 xfonts-75dpi xfonts-base \
libjpeg8-dev 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
RUN pip install --upgrade setuptools pip
# Generate 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
RUN pip install --upgrade setuptools pip
RUN useradd -ms /bin/bash -G sudo frappe && printf '# User rules for frappe\nfrappe ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/frappe
#nodejs
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 \
@ -28,7 +27,8 @@ RUN git clone -b master https://github.com/frappe/bench.git bench-repo
USER root
RUN pip install -e bench-repo \
&& npm install -g yarn \
&& chown -R frappe:frappe /home/frappe/*
&& chown -R frappe:frappe /home/frappe/* \
&& rm -rf /var/lib/apt/lists/*
USER frappe
WORKDIR /home/frappe/frappe-bench

View File

@ -94,7 +94,7 @@ Express dependency between services, which has two effects:
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 docker
Note: Please do not remove the bench-repo directory the above commands will create
@ -106,19 +106,15 @@ Express dependency between services, which has two effects:
./dbench init
2. Command to start all the containers
2. Command to be executed everytime after starting your containers
docker-compose start
./dbench setup hosts
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
docker exec -it frappe bash
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```.
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```.
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)

89
dbench
View File

@ -1,57 +1,52 @@
#!/bin/bash
display_usage() {
echo "$(basename "$0") [-h] [-c \"<command to be executed inside container>\"]"
echo ''
echo 'where:'
echo ' -h show this help text'
echo ' -c execute a command inside docker using docker exec'
echo ' -s adds site-names to /etc/hosts file in the container to facilitate multisite access'
echo ' init initializes frappe-bench adds a new-site bench-manager.local and installs the bench_manager app
app onto it'
}
if [[ $# -eq 0 ]]; then
docker exec -it frappe bash
elif [ $1 == 'init' ]
then
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 -it 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 -y vim sudo && 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 set-mariadb-host mariadb"
docker exec -it frappe bash -c "bench new-site site1.local"
docker exec -it frappe bash -c "bench get-app erpnext"
docker exec -it frappe bash -c "bench --site site1.local install-app erpnext"
else
while getopts ':hsc:' option; do
case "$option" in
h)
display_usage
exit
;;
c)
docker exec -it frappe bash -c "bench $OPTARG"
;;
s)
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 $2 --ignore-exist --skip-redis-config-generation"
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' ]; then
if [ "$2" == 'docker' ]; then
if [ "$3" == '--swarm-mode' ]; then
echo "Docker swarm mode is not currently supported"
else
docker-compose up -d
fi
elif [ "$2" == 'hosts' ]; then
a=$(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"
echo $result | sudo tee -a /etc/hosts
docker exec -iu root 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"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
fi
elif [ "$1" == '-c' ]; then
shift
user=$1
shift
docker exec -iu "$user" frappe bash -c "$@"
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"
echo " Starts and builds the docker containers using \"docker-compose up -d\""
echo " $0 setup hosts"
echo " Adds all sites to the hosts file, run with sudo"
echo " $0 -c frappe | root <command to run>"
echo " Runs a command in the container, as the selected user"
echo " $0 -h"
echo " Shows this help message"
echo " $0 <command to send to bench>"
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 $*"
fi