From b8d7048eb402000a9c50102067e2175727aead1b Mon Sep 17 00:00:00 2001 From: Patrick Uiterwijk Date: May 30 2017 16:26:04 +0000 Subject: Use createdb and alembic during docker-composer Signed-off-by: Patrick Uiterwijk --- diff --git a/docker-compose.yml b/docker-compose.yml index 2c363a4..4876c68 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,7 @@ version: '3.2' volumes: repos: attachments: + postgres: services: web: build: @@ -68,4 +69,4 @@ services: - POSTGRES_DB=pagure - PGDATA=/var/lib/postgresql/data/pgdata volumes: - - ./docker/volumes/postgres:/var/lib/postgresql/data/pgdata + - postgres:/var/lib/postgresql/data/pgdata diff --git a/docker/web b/docker/web index 3f1d9e1..e0a14c1 100644 --- a/docker/web +++ b/docker/web @@ -11,13 +11,13 @@ RUN dnf install -y python2-devel python-setuptools python-nose py-bcrypt python- python-pygit2 python-pygments python-fedora python-openid python-openid-cla \ python-openid-teams python-straight-plugin python-wtforms python-munch \ python-enum34 python-redis python-sqlalchemy systemd gitolite3 python-filelock \ - python-fedora-flask python2-pillow python2-psycopg2 - -RUN dnf install -y python2-celery + python-fedora-flask python2-pillow python2-psycopg2 python2-celery \ + findutils +COPY web-run /run.sh WORKDIR /code # Openshift: --no-debug -ENTRYPOINT ["/usr/bin/python", "/code/runserver.py", "--host", "0.0.0.0", "--config", "/code/openshift.cfg"] +ENTRYPOINT ["/usr/bin/bash", "/run.sh"] EXPOSE 5000 # Code injection is last to make optimal use of caches diff --git a/docker/web-run b/docker/web-run new file mode 100644 index 0000000..7ca36a8 --- /dev/null +++ b/docker/web-run @@ -0,0 +1,14 @@ +#!/bin/bash -xe +if [ ! -f /attachments/inited ]; +then + echo "Giving Postgres time to start" + sleep 10 + PAGURE_CONFIG=/code/openshift.cfg python createdb.py + alembic --config /code/openshift_alembic.ini heads | awk '{print $1}' | \ + xargs alembic --config /code/openshift_alembic.ini stamp + touch /attachments/inited +else + alembic --config /code/openshift_alembic.ini upgrade head +fi + +exec /usr/bin/python /code/runserver.py --host 0.0.0.0 --config /code/openshift.cfg diff --git a/openshift_alembic.ini b/openshift_alembic.ini new file mode 100644 index 0000000..a1c8d53 --- /dev/null +++ b/openshift_alembic.ini @@ -0,0 +1,60 @@ +# A generic, single database configuration. + +[alembic] +# path to migration scripts +script_location = /code/alembic + +# template used to generate migration files +# file_template = %%(rev)s_%%(slug)s + +# max length of characters to apply to the +# "slug" field +#truncate_slug_length = 40 + +# set to 'true' to run the environment during +# the 'revision' command, regardless of autogenerate +# revision_environment = false + +# set to 'true' to allow .pyc and .pyo files without +# a source .py file to be detected as revisions in the +# versions/ directory +# sourceless = false + +#sqlalchemy.url = driver://user:pass@localhost/dbname +sqlalchemy.url = postgresql://pagure:pagure@postgresql/pagure + + +# Logging configuration +[loggers] +keys = root,sqlalchemy,alembic + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = WARN +handlers = console +qualname = + +[logger_sqlalchemy] +level = WARN +handlers = +qualname = sqlalchemy.engine + +[logger_alembic] +level = INFO +handlers = +qualname = alembic + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(levelname)-5.5s [%(name)s] %(message)s +datefmt = %H:%M:%S