diff --git a/.dockerignore b/.dockerignore index 26a1f1b6a..5c496c43b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,9 @@ backup/** +*.pyc container_data .cache node_modules OpenOversight/app/static/dist/* /OpenOversight/tests/resources/.minio.sys/ +__pycache__ + diff --git a/Makefile b/Makefile index 29c195f58..b5b01b824 100644 --- a/Makefile +++ b/Makefile @@ -41,12 +41,12 @@ populate: create_db ## Build and run containers test: start ## Run tests if [ -z "$(name)" ]; then \ if [ "$$(uname)" == "Darwin" ]; then \ - FLASK_ENV=testing docker-compose run --rm web pytest --doctest-modules -n $$(sysctl -n hw.logicalcpu) --dist=loadfile -v tests/ app; \ + FLASK_ENV=testing docker-compose run --rm web /bin/bash -c 'scripts/minio_forward.sh & pytest --doctest-modules -n "$$(sysctl -n hw.logicalcpu)" --dist=loadfile -v tests/ app'; \ else \ - FLASK_ENV=testing docker-compose run --rm web pytest --doctest-modules -n $$(nproc --all) --dist=loadfile -v tests/ app; \ + FLASK_ENV=testing docker-compose run --rm web /bin/bash -c 'scripts/minio_forward.sh & pytest --doctest-modules -n "$$(nproc --all)" --dist=loadfile -v tests/ app'; \ fi; \ else \ - FLASK_ENV=testing docker-compose run --rm web pytest --doctest-modules -v tests/ app -k $(name); \ + FLASK_ENV=testing docker-compose run --rm web /bin/bash -c 'scripts/minio_forward.sh & pytest --doctest-modules -v tests/ app -k $(name)'; \ fi .PHONY: lint diff --git a/OpenOversight/scripts/entrypoint.sh b/OpenOversight/scripts/entrypoint.sh index 677931b40..7bf938374 100755 --- a/OpenOversight/scripts/entrypoint.sh +++ b/OpenOversight/scripts/entrypoint.sh @@ -2,6 +2,8 @@ if [ "${DOCKER_BUILD_ENV:-}" == "production" ]; then flask run --host=0.0.0.0 --port=3000 else + # forwarding port 9000 to minio for local S3 bucket + scripts/minio_forward.sh & yarn build yarn watch & flask run --host=0.0.0.0 --port=3000 diff --git a/OpenOversight/scripts/minio_forward.sh b/OpenOversight/scripts/minio_forward.sh new file mode 100755 index 000000000..67fd8e5e1 --- /dev/null +++ b/OpenOversight/scripts/minio_forward.sh @@ -0,0 +1 @@ +ncat -k -l localhost 9000 --sh-exec "ncat minio 9000" diff --git a/OpenOversight/tests/conftest.py b/OpenOversight/tests/conftest.py index 411ba1381..8266d9a0d 100644 --- a/OpenOversight/tests/conftest.py +++ b/OpenOversight/tests/conftest.py @@ -7,6 +7,7 @@ import random from selenium import webdriver import time +import threading from xvfbwrapper import Xvfb from faker import Faker import csv diff --git a/docker-compose.yml b/docker-compose.yml index 0750e7ee2..071aae473 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,7 +16,6 @@ services: - postgres:/var/lib/postgresql/data ports: - "5432:5432" - network_mode: "host" web: restart: always @@ -29,9 +28,9 @@ services: environment: AWS_ACCESS_KEY_ID: "${AWS_ACCESS_KEY_ID:-minio123}" AWS_SECRET_ACCESS_KEY: "${AWS_SECRET_ACCESS_KEY:-minio123}" - S3_ENDPOINT: "${S3_ENDPOINT:-'http://localhost:9000'}" - AWS_DEFAULT_REGION: "${AWS_DEFAULT_REGION:-'us-east-1'}" - S3_BUCKET_NAME: "${S3_BUCKET_NAME:-'openoversight-test'}" + S3_ENDPOINT: "${S3_ENDPOINT:-http://localhost:9000}" + AWS_DEFAULT_REGION: "${AWS_DEFAULT_REGION:-us-east-1}" + S3_BUCKET_NAME: "${S3_BUCKET_NAME:-openoversight-test}" APPROVE_REGISTRATIONS: "${APPROVE_REGISTRATIONS}" FLASK_APP: app FLASK_ENV: "${FLASK_ENV:-development}" @@ -41,19 +40,17 @@ services: command: scripts/entrypoint.sh ports: - "3000:3000" - network_mode: "host" minio: image: minio/minio environment: - MINIO_ACCESS_KEY: "${AWS_ACCESS_KEY_ID}" - MINIO_SECRET_KEY: "${AWS_SECRET_ACCESS_KEY}" + MINIO_ACCESS_KEY: "${AWS_ACCESS_KEY_ID:-minio123}" + MINIO_SECRET_KEY: "${AWS_SECRET_ACCESS_KEY:-minio123}" command: server /data volumes: - ./OpenOversight/tests/resources/:/data:rw ports: - "9000:9000" - network_mode: "host" mc: image: minio/mc @@ -62,7 +59,6 @@ services: entrypoint: > /bin/sh -c " sleep 10; - /usr/bin/mc config host add minio http://localhost:9000 ${AWS_ACCESS_KEY_ID} ${AWS_SECRET_ACCESS_KEY}; - /usr/bin/mc policy set public minio/${S3_BUCKET_NAME}; + /usr/bin/mc config host add minio http://minio:9000 ${AWS_ACCESS_KEY_ID:-minio123} ${AWS_SECRET_ACCESS_KEY:-minio123}; + /usr/bin/mc policy set public minio/${S3_BUCKET_NAME:-openoversight-test}; " - network_mode: "host" diff --git a/dockerfiles/web/Dockerfile b/dockerfiles/web/Dockerfile index dfea8e3a1..0b02582f9 100644 --- a/dockerfiles/web/Dockerfile +++ b/dockerfiles/web/Dockerfile @@ -9,7 +9,7 @@ ENV DISPLAY=:1 ENV GECKODRIVER_VERSION="v0.26.0" RUN echo "deb http://deb.debian.org/debian stretch-backports main" > /etc/apt/sources.list.d/backports.list RUN wget -O - https://deb.nodesource.com/setup_12.x | bash - -RUN apt-get update && apt-get install -y xvfb firefox-esr libpq-dev python3-dev nodejs && \ +RUN apt-get update && apt-get install -y xvfb firefox-esr libpq-dev python3-dev nodejs ncat && \ apt-get install -y -t stretch-backports libsqlite3-0 && apt-get clean RUN wget https://github.com/mozilla/geckodriver/releases/download/${GECKODRIVER_VERSION}/geckodriver-${GECKODRIVER_VERSION}-linux64.tar.gz @@ -38,7 +38,7 @@ EXPOSE 3000 ENV PATH="/usr/src/app/geckodriver:${PATH}" ENV SECRET_KEY 4Q6ZaQQdiqtmvZaxP1If -ENV SQLALCHEMY_DATABASE_URI postgresql://openoversight:terriblepassword@localhost:5432/openoversight-dev +ENV SQLALCHEMY_DATABASE_URI postgresql://openoversight:terriblepassword@postgres/openoversight-dev WORKDIR /usr/src/app/OpenOversight