Skip to content
This repository has been archived by the owner on Sep 25, 2018. It is now read-only.

Run with uWSGI usage #13

Merged
merged 17 commits into from
Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .docker/uwsgi.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[uwsgi]
chdir=/app
pythonpath=/app
virtualenv=/.venv
wsgi-file=content_store/api/wsgi.py
callable = APP

http=0.0.0.0:80
master=True
processes=4
max-requests=5000
#logto = uwsgi.log
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ install:
- docker-compose build

before_script:
- docker-compose up -d web
- docker-compose up -d app

script:
- docker-compose run web python -m pytest
- docker-compose run app python -m pytest
- ./.docker/smoke-tests.sh

after_script:
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ COPY content_store/ content_store/
COPY tests/ tests/
# if there is work to be done here, move the venv copying after it

CMD ["python"]
#USER nobody
CMD ["uwsgi", "--ini=uwsgi.ini"]
9 changes: 7 additions & 2 deletions Dockerfile.venv
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
ARG python_base_image_tag
FROM python:${python_base_image_tag}

# uwsgi build process dependencies
RUN apk update && apk add gcc libc-dev linux-headers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--no-cache

RUN pip install --no-cache-dir --only-binary --upgrade pipenv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should merge the two RUNs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do, although there's not particular trigger that would re-execute these outside of the package names

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(can even merge 3)


COPY Pipfile Pipfile.lock ./
RUN python -m venv /.venv
ENV VIRTUAL_ENV=/.venv PYTHONUSERBASE=/.venv PATH=/.venv/bin:$PATH
COPY Pipfile Pipfile.lock /pipfiles/

ARG pipenv_dev_arg
ENV PIPENV_VENV_IN_PROJECT=1
WORKDIR /pipfiles
RUN pipenv install ${pipenv_dev_arg} --deploy --ignore-pipfile
3 changes: 2 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ pytest = "~=3.7.1"

[packages]
flask = "~=1.0.2"
flask-sqlalchemy = "*"
flask-sqlalchemy = "~=2.3.2"
uwsgi = "~=2.0.17"

[requires]
python_version = "3.6"
19 changes: 13 additions & 6 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,11 @@ curl -v localhost:5000/ping

Running tests:
```
docker-compose run web python -m pytest
docker-compose run app python -m pytest
```

Installing a new package:
```
docker-compose build
docker-compose run --rm venv /bin/sh -c 'pipenv install requests && pipenv lock'
```
3 changes: 3 additions & 0 deletions content_store/api/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from content_store.api.api import create_app
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The app shouldn't be in the api namespace, let alone twice!

Copy link
Member Author

@giorgiosironi giorgiosironi Aug 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General structure (until there is logic to organize) still unclear, but a few (hopefully one) stable top-level package(s) is needed, the rest can be moved around


APP = create_app()
6 changes: 6 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '3'

services:
venv:
volumes:
- ./:/pipfiles/
10 changes: 5 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ services:
pipenv_dev_arg: ${PIPENV_DEV_ARG}
python_base_image_tag: ${PYTHON_BASE_IMAGE_TAG}
image: libero/content-store_venv:${IMAGE_TAG}
web:
app:
build:
context: .
dockerfile: Dockerfile
args:
image_tag: ${IMAGE_TAG}
python_base_image_tag: ${PYTHON_BASE_IMAGE_TAG}
image: libero/content-store:${IMAGE_TAG}
environment:
- FLASK_APP=content_store/api/api.py
command: flask run --host=0.0.0.0
# TODO: check what to use for uwsgi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this resolved?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works better with the current configuration, as the default SIGTERM is not handled. This can usually be tweaked with the uwsgi configuration but, not being in the container image, I want to see a real one first.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(by default it will handle SIGINT and SIGQUIT)

stop_signal: SIGINT
volumes:
- ./.docker/uwsgi.ini:/app/uwsgi.ini
ports:
- 5000:5000
- 5000:80
depends_on:
- venv