Skip to content

Commit

Permalink
Merge pull request #4 from FinnStutzenstein/openslides4-dev-integration
Browse files Browse the repository at this point in the history
Small rework regarding tests for the big setup.
  • Loading branch information
FinnStutzenstein committed Jul 29, 2020
2 parents 20b2282 + a260377 commit 400d869
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 31 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ RUN apt-get -y update && apt-get -y upgrade && \
postgresql-client

WORKDIR /app
#ENV FLASK_APP mediafileserver.py

COPY requirements_production.txt requirements_production.txt
RUN pip install -r requirements_production.txt
Expand Down
9 changes: 5 additions & 4 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ RUN apt-get -y update && apt-get -y upgrade && \

WORKDIR /app

COPY requirements_production.txt requirements_production.txt
RUN pip install -r requirements_production.txt
COPY requirements_development.txt requirements_development.txt
COPY requirements_production.txt .
COPY requirements_development.txt .
RUN pip install -r requirements_development.txt

COPY entrypoint.sh .
COPY execute-cleanup.sh .
COPY setup.cfg .

EXPOSE 9006
# TODO: Make the port configurable via ENV
ENTRYPOINT ["./entrypoint.sh"]

ENV FLASK_APP ./src/mediaserver.py
ENV FLASK_ENV development

ENTRYPOINT ["./entrypoint.sh"]
CMD ["flask", "run", "--host", "0.0.0.0", "--port", "9006"]
7 changes: 1 addition & 6 deletions Dockerfile.tests
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,5 @@ WORKDIR /app

COPY requirements_tests.txt requirements_tests.txt
RUN pip install -r requirements_tests.txt
COPY requirements_development.txt requirements_development.txt
RUN pip install -r requirements_development.txt

COPY entrypoint-tests.sh .
COPY setup.cfg .

ENTRYPOINT ["./entrypoint-tests.sh"]
CMD ["bash", "-c", "sleep infinity"]
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ build-dev:

build-tests:
docker build . -f Dockerfile.tests --tag openslides-media-tests

run-tests: | build-dev build-tests
docker-compose -f docker-compose.test.yml up -d
docker-compose -f docker-compose.test.yml exec tests wait-for-it "media:9006"
docker-compose -f docker-compose.test.yml exec tests pytest
docker-compose -f docker-compose.test.yml down

run-cleanup: | build-dev
docker run -ti --entrypoint="" -v `pwd`/src:/app/src -v `pwd`/tests:/app/tests openslides-media-dev bash -c "./execute-cleanup.sh"
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ variables. Configs without default must be specified. All configs (see

- `URL_PREFIX`: Default `/media/`. The prefix, the server listens to. E.g. for
the default, all files must be requested this way: `/media/<path>`.
- `CHECK_REQUEST_URL`: The url to make the chack request to. The host and port
must be given. E.g.: `worker:9006/check-media/`
- `DB_HOST`, `DB_PORT`, `DB_NAME`, `DB_USER`, `DB_PASSWORD`: The host, port,
database name, user and password for the mediafile db
- `BLOCK_SIZE`: Default 4096. The size of the blocks, the file is chunked into.
Expand Down
2 changes: 0 additions & 2 deletions docker-compose-test.yml → docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ services:
- MEDIA_DATABASE_NAME=openslides
- MEDIA_DATABASE_USER=openslides
- MEDIA_DATABASE_PASSWORD=openslides
- CHECK_REQUEST_URL=test/
volumes:
- ./src:/app/src
ports:
Expand All @@ -26,4 +25,3 @@ services:
- media-postgresql
volumes:
- ./tests:/app/tests
- ./src:/app/src
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ services:
- MEDIA_DATABASE_NAME=openslides
- MEDIA_DATABASE_USER=openslides
- MEDIA_DATABASE_PASSWORD=openslides
- CHECK_REQUEST_URL=test/
volumes:
- ./src:/app/src
ports:
Expand Down
6 changes: 0 additions & 6 deletions entrypoint-tests.sh

This file was deleted.

1 change: 1 addition & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -e

export MEDIA_DATABASE_HOST="${MEDIA_DATABASE_HOST:-db}"
export MEDIA_DATABASE_PORT="${MEDIA_DATABASE_PORT:-5432}"
Expand Down
8 changes: 8 additions & 0 deletions execute-cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

printf "Black:\n"
black src/ tests/
printf "\nIsort:\n"
isort src/ tests/
printf "\nFlake8:\n"
flake8 src/ tests/
2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

2 changes: 2 additions & 0 deletions requirements_development.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-r requirements_production.txt

flake8
black
isort
11 changes: 6 additions & 5 deletions src/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

def get_mediafile_id(meeting_id, path, app, cookie):
return meeting_id

# TODO: Enable the call to the presenter
check_request_url = get_check_request_url(meeting_id, path, app)
app.logger.debug(f"Send check request: {check_request_url}")

Expand All @@ -29,8 +31,7 @@ def get_mediafile_id(meeting_id, path, app, cookie):
return id


def get_check_request_url(meeting_id, path, app):
check_request_url = app.config["CHECK_REQUEST_URL"]
if not check_request_url.endswith("/"):
raise ServerError("The CHECK_REQUEST_URL must end with an slash.")
return f"http://{check_request_url}/{meeting_id}/{path}"
def get_check_request_url():
presenter_host = "todo"
presenter_port = "todo"
return f"http://{presenter_host}:{presenter_port}/system/presenter"
3 changes: 1 addition & 2 deletions src/config_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


def get_type_for(config_value):
if config_value in ["MEDIA_DATABASE_PORT", "BLOCK_SIZE"]:
if config_value in ("MEDIA_DATABASE_PORT", "BLOCK_SIZE"):
return int
return str

Expand All @@ -15,7 +15,6 @@ def get_default_for(config_value):

def init_config(app):
all_configs = (
"CHECK_REQUEST_URL",
"MEDIA_DATABASE_HOST",
"MEDIA_DATABASE_PORT",
"MEDIA_DATABASE_NAME",
Expand Down

0 comments on commit 400d869

Please sign in to comment.