Dockerize the Application.

This commit is contained in:
Patrick Jentsch 2019-09-06 11:38:35 +02:00
parent 1044674074
commit b9a8c63aee
4 changed files with 46 additions and 59 deletions

View File

@ -1,6 +1,12 @@
FROM python:3.6-alpine FROM python:3.6-alpine
EXPOSE 5000
ENV FLASK_APP=opaque.py
RUN apk add \ RUN apk add \
build-base \ build-base \
postgresql-dev postgresql-dev
@ -8,28 +14,15 @@ RUN apk add \
RUN adduser -D opaque RUN adduser -D opaque
USER opaque USER opaque
WORKDIR /home/opaque WORKDIR /home/opaque
COPY app app COPY app app
COPY migrations migrations copy migrations migrations
COPY config.py opaque.py ./ COPY config.py opaque.py requirements.txt ./
COPY requirements.txt requirements.txt
ENV FLASK_APP=opaque.py
RUN python -m venv venv && \ RUN python -m venv venv && \
venv/bin/pip install -r requirements.txt venv/bin/pip install -r requirements.txt
COPY docker-entrypoint.sh /usr/local/bin/ COPY docker-entrypoint.sh /usr/local/bin/
EXPOSE 5000
ENTRYPOINT ["docker-entrypoint.sh"] ENTRYPOINT ["docker-entrypoint.sh"]

View File

@ -1,42 +1,38 @@
version: '3.7' version: '3'
services: services:
web: opaque:
build: . container_name: opaque
container_name: opaque_flask depends_on:
image: gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/opaque - opaque_database
volumes: - opaque_redis
- .:/opaque
- $HOME/opaque_test:/home/compute/mnt/opaque
env_file: env_file:
- .env - opaque_database_env
- .env_database - opaque_env
image: gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/opaque:latest
ports: ports:
- 5000:5000 - 5000:5000
depends_on:
- db
links:
- db
command: bash flask-entrypoint.sh
daemon:
container_name: opaque_daemon
image: gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/daemon_opaque
network_mode: "host"
volumes:
- /home/stephan/Repos/own/opaque/data_dev.sqlite:/daemon/db/data_dev.sqlite
- $HOME/.docker/config.json:/root/.docker/config.json
depends_on:
- db
db:
container_name: opaque_db
image: postgres:11.5
env_file:
- .env_database
ports:
- 5432:5432
volumes:
- postgres_data:/var/lib/postgresql/data
restart: always restart: always
volumes: volumes:
postgres_data: - /opaque_storage:/opaque_storage
opaque_daemon:
container_name: opaque_daemon
depends_on:
- opaque_database
env_file:
- opaque_database_env
image: gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/opaque_daemon:latest
restart: always
volumes:
- $HOME/.docker/config.json:/home/opaque_daemon/.docker/config.json
opaque_database:
container_name: opaque_database
env_file: opaque_database_env
image: postgres:alpine
restart: always
volumes:
- /opaque_database:/var/lib/postgresql/data
opaque_redis:
container_name: opaque_redis
image: redis:alpine
restart: always

View File

@ -2,14 +2,12 @@
if [ $# -eq 0 ] if [ $# -eq 0 ]
then then
# If no argument is given, start Opaque
venv/bin/python opaque.py venv/bin/python opaque.py
else else
if [[ $1 == "--create-db" ]] if [[ $1 == "--setup-database" ]]
then then
source venv/bin/activate venv/bin/python -m flask db init
flask db init venv/bin/python -m flask db upgrade
flask db upgrade venv/bin/python -m flask insert-initial-database-entries
flask foo
fi fi
fi fi

View File

@ -28,8 +28,8 @@ def test():
unittest.TextTestRunner(verbosity=2).run(tests) unittest.TextTestRunner(verbosity=2).run(tests)
@app.cli.command() @app.cli.command('insert-initial-database-entries')
def foo(): def insert_initial_database_entries():
Role.insert_roles() Role.insert_roles()