refactor(frappe-docker): code cleanup and fixes (#63)

* testing replacement for dbench

* fixed perm issue and added docker control

* fixes and tests

fixed travis test, and perm issue

* auto add permissions

* bench setup anything-else should work now

* removed adding site names to host (its pointless)

* moved redis configuration folder into conf/

* added a docker down feature to dbench and changed some of the docs

* hopefully should fix the args issue

* Condensed Dockerfile

Updated to latest node, and uses python-pip, also condensed a lot the Dockerfile.

* Removed extra line

* Removed MAINTAINER in favor of LABEL

* all installs are in one apt command

* Switch bench to dbench, added -s feature of dbench to bench. updated
Docker file with sudo and vim, and setup travis to run with said changes

* dockerfile: clean up (#52)

* Condensed Dockerfile

Updated to latest node, and uses python-pip, also condensed a lot the Dockerfile.

* fixed travis, and cleaned up dbench a little

* Oops...

* oops, but only for travis, this runs fine

* Travis!

* added help to dbench, and updated readme

* changes some of the wording of the help message

* dbench: fix init issues (#55)

./dbench init would lead to 'missing argument: PATH' issue (#54), and could not find Procfile_docker and site-config.

Signed-off-by: Chinmay Pai <chinmaydpai@gmail.com>

* bench setup anything-else should work now

* Clean cache to get a smaller image (#57)

Please include this commit to decrease the size of the docker image, the "rm -rf /var/lib/apt/lists/*" it is not usefull if it is not used in the same stage of the apt-get install RUN, similar with pip cache.

References:
 - https://linux.die.net/man/8/apt-get
 - https://stackoverflow.com/questions/9510474/removing-pips-cache
 - https://semaphoreci.com/blog/2016/12/13/lightweight-docker-images-in-5-steps.html

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file;

(b) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.

Signed-off-by: William Moreno Reyes <williamjmorenor@gmail.com>

* removed adding site names to host (its pointless)

* moved redis configuration folder into conf/

* added a docker down feature to dbench and changed some of the docs

* Changed the readme significantly

 Please enter the commit message for your changes. Lines starting

* changed test.py to avoid naming errors

* moving some things around for less lines

* some more slight name changes

* added a .gitignore

* added the frappe folder again

* added a .dockerignore and fixed the dockerfile up a bit

* Updating travis' docker and compose

 This is the commit message #3:

* bringing chown in dbench back

* some refractoring

* implementing codacy sugestions

* moving some things around

* Updating dbench in some areas

* some random changes and fixes

* dockerfile refactoring

* Refractoring, reducing layers

* removing the py script that took too many lines to do one simple thing

* Fixed up the readme

* some refractoring

* moving to debian slim and refractoring

* adding some logging

* Updated travis to ubuntu xenial, should fix the curl issue

* manually building curl, cause we cant use  the latest version...

* maybe we dont need it

* changing the url to curl

* trying this instead

* lets just let it pollute the stream

* please pollute!
This commit is contained in:
chabad360
2019-04-05 15:50:30 -04:00
committed by Chinmay Pai
parent 687ef7cecc
commit 33ad0c4fe9
19 changed files with 173 additions and 213 deletions

10
.dockerignore Normal file
View File

@@ -0,0 +1,10 @@
# frappe_docker .dockerignore file
conf/*
.travis.yml
test.sh
README.md
LICENSE.md
.gitignore
dbench
docker-*.yml

1
.gitignore vendored Normal file
View File

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

View File

@@ -1,22 +1,29 @@
language: python dist: xenial
python:
- "2.7"
env: env:
- DOCKER_COMPOSE_VERSION: 1.22.0 - DOCKER_COMPOSE_VERSION: 1.23.1
services: services:
- docker - 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: install:
- chmod ugo+x ./dbench - chmod ugo+x ./dbench
- chmod ugo+x ./test.sh
- ./dbench setup docker - ./dbench setup docker
- ./dbench init frappe-bench - ./dbench init frappe-bench
- ./dbench new-site site1.local - ./dbench new-site site1.local
- sudo ./dbench setup hosts - ./dbench setup hosts
- pip install --upgrade virtualenv
- virtualenv -p python3 testenv
- source testenv/bin/activate
- pip install requests
script: script:
- docker-compose ps | grep -i frappe - docker-compose ps | grep -i frappe
@@ -24,5 +31,5 @@ script:
- docker-compose ps | grep -i redis-queue - docker-compose ps | grep -i redis-queue
- docker-compose ps | grep -i redis-socketio - docker-compose ps | grep -i redis-socketio
- docker-compose ps | grep -i mariadb - docker-compose ps | grep -i mariadb
- python test.py - ./test.sh
- docker-compose stop - ./dbench setup docker stop

View File

@@ -1,34 +1,36 @@
# Frappe Bench Dockerfile
#bench Dockerfile FROM debian:9.6-slim
LABEL author=frappé
FROM ubuntu:16.04 # Set locale C.UTF-8 for mariadb and general locale data
LABEL MAINTAINER frappé
USER root
# Generate locale C.UTF-8 for mariadb and general locale data
ENV LANG C.UTF-8 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 \ # Install all neccesary packages
redis-tools redis-server software-properties-common libxrender1 libxext6 xfonts-75dpi xfonts-base zlib1g-dev libfreetype6-dev \ RUN apt-get update && apt-get install -y --no-install-suggests --no-install-recommends build-essential cron curl git iputils-ping libffi-dev \
liblcms2-dev libwebp-dev python-tk apt-transport-https libsasl2-dev libldap2-dev libtiff5-dev tcl8.6-dev tk8.6-dev \ liblcms2-dev libldap2-dev libmariadbclient-dev libsasl2-dev libssl-dev libtiff5-dev libwebp-dev mariadb-client \
wget libmysqlclient-dev mariadb-client mariadb-common curl rlwrap redis-tools nano wkhtmltopdf python-pip vim sudo && apt-get clean \ python-dev python-pip python-setuptools python-tk redis-tools rlwrap software-properties-common sudo tk8.6-dev \
&& rm -rf /var/lib/apt/lists/* vim xfonts-75dpi xfonts-base wget wkhtmltopdf \
RUN pip install --upgrade setuptools pip && rm -rf ~/.cache/pip && apt-get clean && rm -rf /var/lib/apt/lists/* \
RUN useradd -ms /bin/bash -G sudo frappe && printf '# User rules for frappe\nfrappe ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/frappe && pip install --upgrade setuptools pip --no-cache \
&& curl https://deb.nodesource.com/node_10.x/pool/main/n/nodejs/nodejs_10.10.0-1nodesource1_amd64.deb > node.deb \
#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 \ && dpkg -i node.deb \
&& rm 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 WORKDIR /home/frappe
RUN git clone -b master https://github.com/frappe/bench.git bench-repo # Install bench
RUN pip install -e git+https://github.com/frappe/bench.git#egg=bench --no-cache
USER root
RUN pip install -e bench-repo && rm -rf ~/.cache/pip \
&& npm install -g yarn \
&& chown -R frappe:frappe /home/frappe/*
USER frappe USER frappe
# Add some bench files
COPY --chown=frappe:frappe ./frappe-bench /home/frappe/frappe-bench
WORKDIR /home/frappe/frappe-bench WORKDIR /home/frappe/frappe-bench
EXPOSE 8000 9000 6787
VOLUME [ "/home/frappe/frappe-bench" ]

142
README.md
View File

@@ -1,134 +1,72 @@
# 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. [![Build Status](https://travis-ci.org/frappe/frappe_docker.svg?branch=develop)](https://travis-ci.org/frappe/frappe_docker)
- Docker makes it much easier to deploy [frappe](https://github.com/frappe/frappe) on your servers. This is a repo designed to aide setting up frappe/ERPNext on docker.
- This container uses [bench](https://github.com/frappe/bench) to install frappe.
## Getting Started ## 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.
### Prerequisites Unfortunetly, this container is not curently suited for a production enviorment (but we're working towards that goal!).
[Docker](https://www.docker.com/) ### Build the container and initialize the bench
[Docker Compose](https://docs.docker.com/compose/overview/) **Note:** These instructions assume you have both [Docker](https://docs.docker.com/engine/installation) and [Docker Compose](https://docs.docker.com/compose/install/) installed on your system.
### Container Configuration 1. Clone this repo and change your working directory to it:
#### ports: ```bash
git clone https://github.com/frappe/frappe_docker.git
``` cd frappe_docker/
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. 2. Build and start the container, and initialize the bench:
#### 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
- 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
#### 2. Build the container and install bench
* 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
* 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.
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 setup docker
Note: Please do not remove the bench-repo directory the above commands will create
#### Basic Usage
##### Make sure your current directory is frappe_docker
1. First time setup
./dbench init ./dbench init
```
2. Command to be executed everytime after starting your containers **Note:** This will take a while, as docker will now build the container.
3. Add a new site and start Frappe:
```bash
./dbench new-site site1.local
./dbench setup hosts ./dbench setup hosts
./dbench start
```
3. Command to enter your container 4. Use Frappe:
Open your browser to `localhost:8000/login`. Then login using the username `Administrator` and the password `admin`.
./dbench ### Basic Usage of `./dbench`
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```. **IMPORTANT: 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) - `./dbench`: Launches you into an interactive shell in the container as the user `frappe`.
To login to Frappe / ERPNext, open your browser and go to `[your-external-ip]:8000`, probably `localhost:8000` - `./dbench setup docker [ stop | down ]`: Starts and builds the docker containers using `docker-compose up -d`.
- `stop`: Stops the containers with `docker-compose stop`.
- `down`: Deletes the containers and the coresponding volumes with `docker-compose down`.
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. - `./dbench setup hosts`: Adds all sites to the containers hosts file.
**Note:** Run this after you've added a new site to avoid errors.
## Built With - `./dbench -c frappe | root <command to run>`: Runs a command in the container, as the selected user.
* [Docker](https://www.docker.com/) - `./dbench -h`: Shows this help message.
- `./dbench <bench command>`: Runs a command in bench (i.e. Running `./dbench new-site site1.local`, will run `bench new-site site1.local` in the container).
## For More Info
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 ## Contributing
Feel free to contribute to this project and make the container better Feel free to contribute to this project and make it better.
## License ## License

View File

@@ -15,8 +15,8 @@
#collation-server = utf8_general_ci #collation-server = utf8_general_ci
#character_set_server = utf8 #character_set_server = utf8
#collation_server = utf8_general_ci #collation_server = utf8_general_ci
# Import all .cnf files from configuration directory
bind-address = 0.0.0.0 bind-address = 0.0.0.0
# Import all .cnf files from configuration directory
!includedir /etc/mysql/mariadb.conf.d/ !includedir /etc/mysql/mariadb.conf.d/
@@ -27,3 +27,12 @@ collation-server = utf8mb4_unicode_ci
[mysql] [mysql]
default-character-set = utf8mb4 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

48
dbench
View File

@@ -1,43 +1,51 @@
#!/bin/bash #!/bin/bash
function run () {
user=$1
shift
docker exec -itu "${user}" frappe bash -c "$@"
}
if [[ $# -eq 0 ]]; then if [[ $# -eq 0 ]]; then
docker exec -it frappe bash docker exec -it frappe bash
elif [ "$1" == 'init' ]; then elif [[ "$1" == 'init' ]]; then
docker exec -itu root frappe bash -c "cd /home/frappe && chown -R frappe:frappe ./*" run root "chown -R frappe:frappe /home/frappe"
docker exec -i frappe bash -c "cd .. && bench init frappe-bench --ignore-exist --skip-redis-config-generation && cd frappe-bench" run frappe "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" 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' ] && [ "$2" == 'docker' ]; then elif [[ "$1" == 'setup' ]]; then
if [ "$3" == '--swarm-mode' ]; then if [[ "$2" == 'docker' ]]; then
if [[ "$3" == '--swarm-mode' ]]; then
echo "Docker swarm mode is not currently supported" echo "Docker swarm mode is not currently supported"
elif [[ "$3" == 'down' ]]; then
docker-compose down
elif [[ "$3" == 'stop' ]]; then
docker-compose stop
else else
docker-compose up -d docker-compose up -d
fi fi
elif [ "$1" == 'setup' ] && [ "$2" == 'hosts' ]; then elif [[ "$2" == 'hosts' ]]; then
a=$(cd frappe-bench && ls sites/*/site_config.json | grep -o '/.\+/') a=$(run frappe "ls sites/*/site_config.json | grep -o '/.\+/'") \
a="${a//$'\n'/ }" a="${a//$'\n'/ }"
a=$(echo $a | tr -d / ) a=$(echo "$a" | tr -d / )
result="127.0.0.1 ${a}" result="127.0.0.1 ${a}"
echo $result | sudo tee -a /etc/hosts run root "echo ${result} | tee --append /etc/hosts"
docker exec -iu root frappe bash -c "echo ${result} | tee --append /etc/hosts" fi
docker exec -itu root frappe bash -c "printf '# User rules for frappe\nfrappe ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/frappe" elif [[ "$1" == '-c' ]]; then
elif [ "$1" == '-c' ]; then
shift shift
user=$1 user=$1
shift shift
docker exec -iu "$user" frappe bash -c "$@" run "$user" "$@"
elif [ "$1" == '-h' ]; then elif [[ "$1" == '-h' ]]; then
echo "$0 [-h] | [ -c frappe | root <command to run> ] [ <command to send to bench> ]" echo "$0 [-h] | [ -c frappe | root <command to run> ] [ <command to send to bench> ]"
echo "" echo ""
echo "$0 extends the Frappe Bench tool, and is used like it. However, it extends the tool in a few places." echo "$0 extends the Frappe Bench tool, and is used like it. However, it extends the tool in a few places."
echo "Usage:" echo "Usage:"
echo " $0" echo " $0"
echo " Launches you into an interactive shell in the container as user frappe" echo " Launches you into an interactive shell in the container as user frappe"
echo " $0 init bench-folder-name" echo " $0 setup docker [ stop | down ]"
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 " Starts and builds the docker containers using \"docker-compose up -d\""
echo " $0 setup hosts" echo " $0 setup hosts"
echo " Adds all sites to the hosts file, run with sudo" echo " Adds all sites to the containers hosts file"
echo " $0 -c frappe | root <command to run>" echo " $0 -c frappe | root <command to run>"
echo " Runs a command in the container, as the selected user" echo " Runs a command in the container, as the selected user"
echo " $0 -h" echo " $0 -h"
@@ -46,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" echo " Runs a command in bench, i.e. $0 new-site site1.local = bench new-site site1.local"
else else
IFS=" " IFS=" "
docker exec -it frappe bash -c "bench $*" run frappe "bench $*"
fi fi

View File

@@ -1,22 +1,26 @@
version: '2' version: '3.7'
services: services:
mariadb: mariadb:
image: mariadb image: mariadb
environment: environment:
- MYSQL_ROOT_PASSWORD=123 - MYSQL_ROOT_PASSWORD=123
- MYSQL_USER=root - MYSQL_USER=root
volumes: volumes:
- ./conf/mariadb-conf.d:/etc/mysql/conf.d - ./conf/mariadb-conf.d:/etc/mysql/conf.d
- /var/lib/mysql - /var/lib/mysql
ports: ports:
- "3307:3306" #mariadb-port - "3307:3306" # MariaDB Port
container_name: mariadb container_name: mariadb
redis-cache: redis-cache:
image: redis:alpine image: redis:alpine
volumes: volumes:
- ./redis-conf:/etc/conf.d - ./conf/redis-conf.d:/etc/conf.d
command: ["redis-server","/etc/conf.d/redis_cache.conf"] command: ["redis-server","/etc/conf.d/redis_cache.conf"]
@@ -25,8 +29,9 @@ services:
redis-queue: redis-queue:
image: redis:alpine image: redis:alpine
volumes: volumes:
- ./redis-conf:/etc/conf.d - ./conf/redis-conf.d:/etc/conf.d
command: ["redis-server","/etc/conf.d/redis_queue.conf"] command: ["redis-server","/etc/conf.d/redis_queue.conf"]
@@ -36,7 +41,7 @@ services:
image: redis:alpine image: redis:alpine
volumes: volumes:
- ./redis-conf:/etc/conf.d - ./conf/redis-conf.d:/etc/conf.d
command: ["redis-server","/etc/conf.d/redis_socketio.conf"] command: ["redis-server","/etc/conf.d/redis_socketio.conf"]
@@ -44,26 +49,32 @@ services:
frappe: frappe:
build: .
volumes: volumes:
- ./frappe-bench:/home/frappe/frappe-bench - ./frappe-bench:/home/frappe/frappe-bench
- ./redis-conf/redis_cache.conf:/home/frappe/frappe-bench/config/redis_cache.conf - ./conf/redis-conf.d/redis_cache.conf:/home/frappe/frappe-bench/config/redis_cache.conf
- ./redis-conf/redis_queue.conf:/home/frappe/frappe-bench/config/redis_queue.conf - ./conf/redis-conf.d/redis_queue.conf:/home/frappe/frappe-bench/config/redis_queue.conf
- ./redis-conf/redis_socketio.conf:/home/frappe/frappe-bench/config/redis_socketio.conf - ./conf/redis-conf.d/redis_socketio.conf:/home/frappe/frappe-bench/config/redis_socketio.conf
build: .
ports: ports:
- "8000:8000" #webserver_port - "8000:8000" # Webserver Port
- "9000:9000" #socketio_port - "9000:9000" # Socketio Port
- "6787:6787" #file_watcher_port - "6787:6787" # File Watcher Port
stdin_open: true stdin_open: true
tty: true tty: true
links: links:
- redis-cache - redis-cache
- redis-queue - redis-queue
- redis-socketio - redis-socketio
- mariadb - mariadb
depends_on: depends_on:
- mariadb - mariadb
- redis-cache - redis-cache
- redis-queue - redis-queue
- redis-socketio - redis-socketio
container_name: frappe container_name: frappe

View File

@@ -1 +0,0 @@
20

View File

@@ -1 +0,0 @@
24

View File

@@ -1 +0,0 @@
29

29
test.py
View File

@@ -1,29 +0,0 @@
import subprocess, requests, datetime, _thread, time, os, signal
start_time = datetime.datetime.now().time()
bench_start = 'docker exec -i frappe bash -c "bench start"'
process = subprocess.Popen(bench_start, stdout=subprocess.PIPE , shell=True)
def print_out(val,delay):
while 1:
time.sleep(delay)
if val == 1:
result,error = process.communicate()
print(result)
elif val == 2:
try:
global r
r = requests.get("http://site1.local:8000")
print(r)
except requests.exceptions.ConnectionError as e:
print(e)
_thread.start_new_thread(print_out, (1, 1))
#result, error = process.communicate()
_thread.start_new_thread(print_out, (2, 1))
time.sleep(30)
process.kill()
assert '<title> Login </title>' in str(r.content)

17
test.sh Normal file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
cat <(./dbench start) &
sleep 5
while ! [[ $i == 20 ]]
do
output=$( curl "http://localhost:8000" )
{ echo "Exit status of curl: $?"
} 1>&2
sleep 2
i=$((i + 1))
done
echo "${output}" | grep '<title> Login </title>' || exit 1