Skip to content

Commit

Permalink
Merge pull request bluesky#382 from danielballan/no-gunicorn
Browse files Browse the repository at this point in the history
Switch to single-process (uvicorn) container
  • Loading branch information
danielballan authored Jan 31, 2023
2 parents 690e4d6 + e710514 commit f2369ce
Show file tree
Hide file tree
Showing 24 changed files with 217 additions and 253 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ["3.7", "3.8", "3.9", "3.10"]
fail-fast: false
steps:

Expand Down Expand Up @@ -40,9 +40,3 @@ jobs:
set -vxeuo pipefail
coverage run -m pytest -v
coverage report
- name: Test docker entrypoint configuration checker
shell: bash -l {0}
run: |
set -vxeuo pipefail
./docker/test_check_config.sh
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
- id: flake8

- repo: https://github.com/timothycrosley/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort

Expand Down
53 changes: 53 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
FROM node:16-alpine AS web_frontend_builder
WORKDIR /code
COPY web-frontend .
RUN npm install && npm run build

# We cannot upgrade to Python 3.11 until numba supports it.
# The `sparse` library relies on numba.
FROM python:3.10 as base
WORKDIR /code

# Ensure logs and error messages do not get stuck in a buffer.
ENV PYTHONUNBUFFERED=1

# Use a venv to avoid interfering with system Python.
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
# This is equivalent to `source $VIRTUAL_ENV/bin/activate` but it
# persists into the runtime so we avoid the need to account for it
# in ENTRYPOINT or CMD.
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# Copy requirements over first so this layer is cached and we don't have to
# reinstall dependencies when only the tiled source has changed.
COPY requirements-server.txt requirements-formats.txt requirements-dataframe.txt requirements-array.txt requirements-xarray.txt requirements-sparse.txt requirements-compression.txt /code/
RUN pip install --upgrade --no-cache-dir pip wheel
RUN pip install --upgrade --no-cache-dir \
-r /code/requirements-array.txt \
-r /code/requirements-compression.txt \
-r /code/requirements-dataframe.txt \
-r /code/requirements-formats.txt \
-r /code/requirements-server.txt \
-r /code/requirements-sparse.txt \
-r /code/requirements-xarray.txt

COPY --from=web_frontend_builder /code/build /code/share/tiled/ui
COPY . .

# note requirements listed here but all deps should be already satisfied
RUN pip install '.[array, compression, dataframe, formats, server, sparse, xarray]'

# FROM base as test
#
# RUN pip install '.[client]'
# RUN pip install -r requirements-dev.txt
# RUN pytest -v

FROM base as app

WORKDIR /deploy

EXPOSE 8000

CMD ["tiled", "serve", "config", "--host", "0.0.0.0", "--port", "8000", "--scalable"]
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ recursive-include docs *.yml *.rst conf.py Makefile make.bat
include versioneer.py
include tiled/_version.py
include tiled/config_schemas/*.yml
include tiled/_tests/test_configs/*.yml
prune web-frontend/node_modules

# If including data files in the package, add them like:
Expand Down
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: "3.2" # higher config versions may also work; lower will not
services:
tiled:
image: tiled
volumes:
- type: bind
source: .
target: /deploy
environment:
- TILED_CONFIG=/deploy/config.yml
ports:
- 8000:8000
56 changes: 0 additions & 56 deletions docker/Dockerfile

This file was deleted.

69 changes: 0 additions & 69 deletions docker/check_config.py

This file was deleted.

6 changes: 0 additions & 6 deletions docker/entrypoint.sh

This file was deleted.

32 changes: 0 additions & 32 deletions docker/gunicorn_config.py

This file was deleted.

1 change: 0 additions & 1 deletion docker/requirements-docker.txt

This file was deleted.

27 changes: 0 additions & 27 deletions docker/test_check_config.sh

This file was deleted.

7 changes: 2 additions & 5 deletions docs/source/how-to/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ and serve it using the docker container
```
docker run --rm -p 8000:8000 \
--mount type=bind,source="$(pwd)",target=/deploy \
--env TILED_CONFIG=/deploy/config.yml ghcr.io/bluesky/tiled:main
--env TILED_CONFIG=/deploy/config.yml \
ghcr.io/bluesky/tiled:main
```
Note that we make the data and the configuration file available to the
container via bind mounds and point tiled to the configuration file using the
Expand Down Expand Up @@ -62,7 +63,3 @@ services:
```
With this file the tiled server can be brought up by simply running `docker-compose up`.

To change the gunicorn configuration, to for example change the number of
workers or the port, set the environment variable `GUNICORN_CONF` to point to
a configuration file accessible in the container.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# config.yml
trees:
- path: /
tree: tiled.adapters.files:DirectoryAdapter.from_directory
args:
directory: "example_files"
tree: tiled.examples.generated_minimal:tree
uvicorn:
host: 0.0.0.0
port: 8000
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# config.yml
trees:
- path: /
tree: tiled.adapters.files:DirectoryAdapter.from_directory
args:
directory: "example_files"
tree: tiled.examples.generated_minimal:tree
uvicorn:
host: 0.0.0.0
port: 8000
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# config.yml
trees:
- path: /
tree: tiled.adapters.files:DirectoryAdapter.from_directory
args:
directory: "example_files"
tree: tiled.examples.generated_minimal:tree
uvicorn:
host: 0.0.0.0
port: 8000
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# config.yml
trees:
- path: /
tree: tiled.adapters.files:DirectoryAdapter.from_directory
args:
directory: "example_files"
tree: tiled.examples.generated_minimal:tree
uvicorn:
host: 0.0.0.0
port: 8000
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# config.yml
trees:
- path: /
tree: tiled.adapters.files:DirectoryAdapter.from_directory
args:
directory: "example_files"
tree: tiled.examples.generated_minimal:tree
uvicorn:
host: 0.0.0.0
port: 8000
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# config.yml
trees:
- path: /
tree: tiled.adapters.files:DirectoryAdapter.from_directory
args:
directory: "example_files"
tree: tiled.examples.generated_minimal:tree
uvicorn:
host: 0.0.0.0
port: 8000
Expand Down
Loading

0 comments on commit f2369ce

Please sign in to comment.