created a template python project with docker-compose integration tests

This commit is contained in:
B.J. Dweck 2021-01-25 11:33:36 +02:00
parent b08a2eacda
commit 32799b65d5
7 changed files with 68 additions and 0 deletions

12
Dockerfile Normal file
View File

@ -0,0 +1,12 @@
FROM python:2.7
WORKDIR /app
ADD requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt
ADD app.py /app/app.py
EXPOSE 80
CMD ["python", "app.py"]

9
Dockerfile.test Normal file
View File

@ -0,0 +1,9 @@
FROM ubuntu:trusty
RUN apt-get update && apt-get install -yq curl && apt-get clean
WORKDIR /app
ADD test.sh /app/test.sh
CMD ["bash", "test.sh"]

16
app.py Normal file
View File

@ -0,0 +1,16 @@
from flask import Flask
from redis import Redis
app = Flask(__name__)
redis = Redis(host="redis")
@app.route("/")
def hello():
visits = redis.incr('counter')
html = "<h3>Hello World!</h3>" \
"<b>Visits:</b> {visits}" \
"<br/>"
return html.format(visits=visits)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=80)

12
docker-compose.test.yml Normal file
View File

@ -0,0 +1,12 @@
sut:
build: .
dockerfile: Dockerfile.test
links:
- web
web:
build: .
dockerfile: Dockerfile
links:
- redis
redis:
image: redis

9
docker-compose.yml Normal file
View File

@ -0,0 +1,9 @@
web:
build: .
dockerfile: Dockerfile
links:
- redis
ports:
- "80:80"
redis:
image: redis

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
Flask
Redis

8
test.sh Normal file
View File

@ -0,0 +1,8 @@
sleep 5
if curl web | grep -q '<b>Visits:</b> '; then
echo "Tests passed!"
exit 0
else
echo "Tests failed!"
exit 1
fi