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 all 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 ./project-tests.sh
- docker-compose run app ./project-tests.sh
- ./.docker/smoke-tests.sh

after_script:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ COPY project-tests.sh \
./
# if there is work to be done here, move the venv copying after it

CMD ["python"]
CMD ["uwsgi", "--ini=uwsgi.ini"]
11 changes: 7 additions & 4 deletions Dockerfile.venv
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
ARG python_base_image_tag
FROM python:${python_base_image_tag}
RUN pip install --no-cache-dir --only-binary --upgrade pipenv

RUN apk --no-cache add linux-headers g++
# uwsgi and pylint build dependencies
RUN apk add --no-cache gcc g++ libc-dev linux-headers \
&& pip install --no-cache-dir --only-binary --upgrade pipenv \
&& python -m venv /.venv

COPY Pipfile Pipfile.lock ./
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 @@ -10,7 +10,8 @@ pylint = "~=2.1"

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

[requires]
python_version = "3.6"
21 changes: 11 additions & 10 deletions Pipfile.lock

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

11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,25 @@ docker-compose up -d
```

Running the application locally (to be removed when Docker becomes the primary development mode):
For non-development configuration set APP_SETTINGS environment variable to the module to use. Defaults to `content_store.api.config.DevelopmentConfig`

```
FLASK_APP=content_store/api/api.py PYTHONPATH=. pipenv run flask run
```

For non-development configuration set APP_SETTINGS environment variable to the module to use. Defaults to `content_store.api.config.DevelopmentConfig`.

Checking the application is responding:
```
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/
9 changes: 4 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ 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
stop_signal: SIGINT
volumes:
- ./.docker/uwsgi.ini:/app/uwsgi.ini
ports:
- 5000:5000
- 5000:80
depends_on:
- venv