From 66b40df0340198971d003e75f711b30d0e67ab8a Mon Sep 17 00:00:00 2001 From: Timur Demin Date: Fri, 14 Jun 2019 11:05:05 +0500 Subject: [PATCH] Add an example docker-compose config * Make uwsgi use its own proto, and not http * Bundle psycopg2 with the image * Add an example nginx config --- Dockerfile | 7 ++++--- bin/run_uwsgi.sh | 3 +-- doc/nginx.conf.example | 8 ++++++++ docker-compose.yml | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 doc/nginx.conf.example create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile index 6495a9a..5297370 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,12 +10,13 @@ COPY bin /app/bin COPY --chown=0:0 doc/config.json.example /etc/amber.json COPY project_amber /app/project_amber -# we need gcc to build cffi, which is required by bcrypt +# we do not remove postgresql-dev after installation, as psycopg2 needs libpq +# present on the system RUN adduser -D -u 1000 amber && \ mkdir -p /data && chown amber /data && chmod 700 /data && \ - apk add --no-cache build-base libffi-dev && \ + apk add --no-cache build-base libffi-dev postgresql-dev && \ pip install -r requirements.txt && \ - pip install uwsgi && \ + pip install uwsgi psycopg2 && \ apk del build-base libffi-dev && \ chmod +x /app/bin/run_uwsgi.sh diff --git a/bin/run_uwsgi.sh b/bin/run_uwsgi.sh index dd9490a..be40f49 100644 --- a/bin/run_uwsgi.sh +++ b/bin/run_uwsgi.sh @@ -1,9 +1,8 @@ #!/bin/sh /usr/local/bin/uwsgi \ - --http :${UWSGI_PORT} \ + --socket :${UWSGI_PORT} \ --master \ - --plugin python,http \ --manage-script-name \ --mount /=project_amber:app \ --processes ${UWSGI_PROCESSES} \ diff --git a/doc/nginx.conf.example b/doc/nginx.conf.example new file mode 100644 index 0000000..f1ccfdd --- /dev/null +++ b/doc/nginx.conf.example @@ -0,0 +1,8 @@ +server { + listen 80 default_server; + location / { try_files $uri @amber; } + location @amber { + include uwsgi_params; + uwsgi_pass amber:8080; + } +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1c27cba --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +version: "3" + +volumes: + postgres: + +services: + amber: + build: . + restart: always + # You'll likely need to add other drivers, like mysql-connector-python, to + # connect to databases other than the default SQLite and PostgreSQL. See: + # https://docs.sqlalchemy.org/en/13/core/engines.html#database-urls + environment: + - AMBER_DATABASE=postgres://amber:CHANGEME@database:5432/amber + - AMBER_LOGLEVEL=2 + - AMBER_ALLOW_SIGNUP=0 + - UWSGI_PORT=8080 + - UWSGI_PROCESSES=1 + - UWSGI_THREADS=2 + depends_on: + - database + database: + image: postgres:11-alpine + restart: always + environment: + - POSTGRES_DB=amber + - POSTGRES_USER=amber + - POSTGRES_PASSWORD=CHANGEME + volumes: + - postgres:/var/lib/postgresql/data + web: + image: nginx:1.16-alpine + ports: + - 80:80 + depends_on: + - amber + volumes: + - ./doc/nginx.conf.example:/etc/nginx/conf.d/default.conf:ro