diff --git a/.github/workflows/twoops-tracker-cd.yml b/.github/workflows/twoops-tracker-cd.yml index 51f42901..44c6aa23 100644 --- a/.github/workflows/twoops-tracker-cd.yml +++ b/.github/workflows/twoops-tracker-cd.yml @@ -4,7 +4,7 @@ on: branches: - main paths: - - 'twoops_tracker/py/VERSION' + - "twoops_tracker/py/VERSION" env: DOKKU_REMOTE_BRANCH: "master" DOKKU_REMOTE_URL: "ssh://dokku@dokku-1.dev.codeforafrica.org/twoopstracker" @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.10.7",] + python-version: ["3.10"] steps: - name: Cancel Previous Runs uses: styfle/cancel-workflow-action@0.11.0 @@ -32,17 +32,23 @@ jobs: - name: Set env run: echo "VERSION=$(cat twoops_tracker/py/VERSION)" >> $GITHUB_ENV - - name: Initialize Pants - uses: pantsbuild/actions/init-pants@main + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 with: - pants-python-version: ${{ matrix.python-version }} - pants-ci-config: "pants.toml" + python-version: ${{ matrix.python-version }} + + - name: Bootstrap Pants + run: | + ./pants --version + + - name: Check BUILD files + run: ./pants tailor --check update-build-files --check - name: Lint run: | - ./pants lint twoops_tracker/py:: + ./pants lint --lint-skip-formatters twoops_tracker/:: - - name: Build + - name: Build Docker image run: | VERSION=${{ env.VERSION }} ./pants package twoops_tracker/docker/:: @@ -51,7 +57,7 @@ jobs: with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - + - name: Push to DockerHub run: | docker push ${{ env.IMAGE_NAME }}:${{ env.VERSION }} diff --git a/.github/workflows/twoops-tracker-ci.yml b/.github/workflows/twoops-tracker-ci.yml index a52389e6..f71137c1 100644 --- a/.github/workflows/twoops-tracker-ci.yml +++ b/.github/workflows/twoops-tracker-ci.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.10.7", ] + python-version: ["3.10"] steps: - name: Cancel Previous Runs uses: styfle/cancel-workflow-action@0.11.0 @@ -20,16 +20,22 @@ jobs: with: fetch-depth: 0 - - name: Initialize Pants - uses: pantsbuild/actions/init-pants@main + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 with: - pants-python-version: ${{ matrix.python-version }} - pants-ci-config: "pants.toml" + python-version: ${{ matrix.python-version }} + + - name: Bootstrap Pants + run: | + ./pants --version + + - name: Check BUILD files + run: ./pants tailor --check update-build-files --check - name: Lint run: | - ./pants lint twoops_tracker/py:: + ./pants lint --lint-skip-formatters twoops_tracker/:: - name: Build run: | - ./pants package twoops_tracker/py:main + ./pants package twoops_tracker/py:twoopstracker-deps twoops_tracker/py:twoopstracker-srcs diff --git a/README.md b/README.md index d4132eda..89f2f21c 100644 --- a/README.md +++ b/README.md @@ -1 +1,13 @@ -# Commons API +# COMMONS API + +## Applications + +| Name | Description | +| ----------------------------------------------- | -------------------------------------------- | +| [**TwoopsTracker**](./twoops_tracker/README.md) | A Twitter-based disinformation tracking tool | + +## Packages + +| Name | Description | +| ---------------------------------- | -------------------------------------------------------------- | +| [**`dj-cmd`**](./dj-cmd/README.md) | Command-line utility for running Django when bundled in `pex`. | diff --git a/contrib/docker-compose/nginx/default.conf b/contrib/docker-compose/nginx/default.conf index f3e65a66..e745232b 100644 --- a/contrib/docker-compose/nginx/default.conf +++ b/contrib/docker-compose/nginx/default.conf @@ -1,5 +1,5 @@ -upstream twoops_tracker { - server twoops_tracker:8000; +upstream twoopstracker_app { + server twoopstracker_app:8000; } server { @@ -7,7 +7,7 @@ server { listen 80; location / { - proxy_pass http://twoops_tracker; + proxy_pass http://twoopstracker_app; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_redirect off; diff --git a/dj-cmd/README.md b/dj-cmd/README.md new file mode 100644 index 00000000..e89af7ef --- /dev/null +++ b/dj-cmd/README.md @@ -0,0 +1,3 @@ +## `dj-cmd` + +Command-line utility for running Django & company entry point tasks when bundled in a single `pex` binary. diff --git a/dj-cmd/py/BUILD b/dj-cmd/py/BUILD index 5b831295..3fa7a4b7 100644 --- a/dj-cmd/py/BUILD +++ b/dj-cmd/py/BUILD @@ -1,6 +1,6 @@ resources( - name = "resources", - sources = [ + name="resources", + sources=[ "pyproject.toml", "setup.cfg", "README.md", @@ -9,13 +9,13 @@ resources( ) python_distribution( - name = "dj-cmd", - dependencies = [ + name="dj-cmd", + dependencies=[ "dj-cmd/py/dj_cmd:dj_cmd", ":resources", ], - provides = setup_py( - name = "dj-cmd", + provides=setup_py( + name="dj-cmd", ), - sdist = False, + sdist=False, ) diff --git a/dj-cmd/py/dj_cmd/BUILD b/dj-cmd/py/dj_cmd/BUILD index db46e8d6..9a0e1a1a 100644 --- a/dj-cmd/py/dj_cmd/BUILD +++ b/dj-cmd/py/dj_cmd/BUILD @@ -1 +1,6 @@ python_sources() + +pex_binary( + name="cmd", + entry_point="cmd.py", +) diff --git a/docker-compose.yml b/docker-compose.yml index 2d194d98..43ce7add 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,30 +24,30 @@ services: # Allow Redis access from outside the container - "63791:6379" - twoops_tracker: - image: codeforafrica/twoops-tracker:latest + twoopstracker_app: + image: codeforafrica/twoopstracker:latest depends_on: - db - redis - environment: - - TWOOPSTRACKER_DATABASE_URL=postgres://${PGUSER:-twoops_tracker}:${PGPASSWORD:-twoops_tracker}@db:5432/${PGDATABASE:-twoops_tracker} - - TWOOPSTRACKER_CELERY_BROKER_URL=${TWOOPSTRACKER_CELERY_BROKER_URL:-redis://redis:6379/0} env_file: - - ./twoops_tracker/.env + - ./twoops_tracker/.env.template volumes: + - app-media:/app/media - app-staticfiles:/app/staticfiles - - nginx: + + twoopstracker: image: nginx:1.20 restart: unless-stopped volumes: - ./contrib/docker-compose/nginx:/etc/nginx/conf.d + - app-media:/var/www/media - app-staticfiles:/var/www/static ports: - 8000:80 depends_on: - - twoops_tracker + - twoopstracker_app volumes: - db-data: + app-media: app-staticfiles: + db-data: diff --git a/pants-plugins/BUILD b/pants-plugins/BUILD index 8425232b..a6d76d89 100644 --- a/pants-plugins/BUILD +++ b/pants-plugins/BUILD @@ -1 +1 @@ -pants_requirements(name = "pants") +pants_requirements(name="pants") diff --git a/pants-plugins/internal_plugins/versioned_setup/register.py b/pants-plugins/internal_plugins/versioned_setup/register.py index 2d46477f..0b5cee3e 100644 --- a/pants-plugins/internal_plugins/versioned_setup/register.py +++ b/pants-plugins/internal_plugins/versioned_setup/register.py @@ -49,9 +49,9 @@ async def setup_kwargs_plugin(request: VersionedSetupKwargsRequest) -> SetupKwar version_file = kwargs.pop("version_file", None) if version and version_file: raise ValueError( - f"The python_distribution target {request.target.address} has supplied both " - "`version` and `version_file` in its setup_py's kwargs. Only one of these " - "should be supplied." + f"The python_distribution target {request.target.address} has supplied both" + " `version` and `version_file` in its setup_py's kwargs. Only one of these" + " should be supplied." ) # we default to checking VERSION file if both version and version_file are not set if not version: @@ -62,7 +62,9 @@ async def setup_kwargs_plugin(request: VersionedSetupKwargsRequest) -> SetupKwar DigestContents, PathGlobs( [version_path], - description_of_origin=f"the 'version_file' kwarg in {request.target.address}", + description_of_origin=( + f"the 'version_file' kwarg in {request.target.address}" + ), glob_match_error_behavior=GlobMatchErrorBehavior.error, ), ) diff --git a/pants.toml b/pants.toml index eba82d9c..0909a69f 100644 --- a/pants.toml +++ b/pants.toml @@ -1,7 +1,7 @@ [GLOBAL] -pants_version = "2.10.0" -use_deprecated_python_macros = false - +pants_version = "2.13.0" +use_deprecated_directory_cli_args_semantics = false +use_deprecated_pex_binary_run_semantics = false pythonpath = ["%(buildroot)s/pants-plugins"] backend_packages = [ diff --git a/twoops_tracker/.env.template b/twoops_tracker/.env.template index 41a15b52..1d114f12 100644 --- a/twoops_tracker/.env.template +++ b/twoops_tracker/.env.template @@ -1,27 +1,46 @@ +# This is the exhaustive list of all environment variables used by +# TwoopsTracker. If a variable is not declared here, docker-compose +# will not pass it to the container at runtime. +# +# Do not assign values here. This *MUST* remain just a list. +# Do not even do empty assignments e.g. +# +# TWOOPSTRACKER_DATABASE_URL= +# +# If you do the above, TWOOPSTRACKER_DATABASE_URL will be set to empty +# string even when a different --env-file is passed to docker-compose + # Required -TWOOPSTRACKER_DATABASE_URL= -TWOOPSTRACKER_SECRET_KEY= -TWOOPSTRACKER_CONSUMER_KEY= -TWOOPSTRACKER_CONSUMER_SECRET= -TWOOPSTRACKER_ACCESS_TOKEN= -TWOOPSTRACKER_ACCESS_TOKEN_SECRET= -TWOOPTRACKER_STREAM_LISTENER_INTERVAL= +TWOOPSTRACKER_ACCESS_TOKEN +TWOOPSTRACKER_ACCESS_TOKEN_SECRET +TWOOPSTRACKER_CELERY_BROKER_URL +TWOOPSTRACKER_CONSUMER_KEY +TWOOPSTRACKER_CONSUMER_SECRET +TWOOPSTRACKER_DATABASE_URL +TWOOPSTRACKER_GOOGLE_OAUTH2_CLIENT_ID +TWOOPSTRACKER_GOOGLE_OAUTH2_CLIENT_SECRET +TWOOPSTRACKER_SECRET_KEY +TWOOPSTRACKER_STREAM_LISTENER_INTERVAL # End of Required # Optional -TWOOPSTRACKER_ALLOWED_HOSTS= -TWOOPSTRACKER_DEBUG=False -TWOOPSTRACKER_CORS_ALLOWED_ORIGINS= -TWOOPSTRACKER_SENTRY_DSN= -TWOOPSTRACKER_EMAIL_CONFIRMATION_URL= -TWOOPSTRACKER_PASSWORD_RESET_URL= -ACCOUNT_EMAIL_VERIFICATION= -SOCIALACCOUNT_EMAIL_VERIFICATION = -LOGIN_URL= - -DEFAULT_FROM_EMAIL= -EMAIL_USE_TLS= -EMAIL_PORT= -EMAIL_HOST_USER= -EMAIL_HOST_PASSWORD= +TWOOPSTRACKER_ACCOUNT_EMAIL_VERIFICATION +TWOOPSTRACKER_ALLOWED_HOSTS +TWOOPSTRACKER_BASE_DIR +TWOOPSTRACKER_CORS_ALLOWED_ORIGINS +TWOOPSTRACKER_DEBUG +TWOOPSTRACKER_DEFAULT_FROM_EMAIL +TWOOPSTRACKER_EMAIL_HOST_USER +TWOOPSTRACKER_EMAIL_HOST_PASSWORD +TWOOPSTRACKER_EMAIL_PORT +TWOOPSTRACKER_EMAIL_USE_TLS +TWOOPSTRACKER_EMAIL_CONFIRMATION_URL +TWOOPSTRACKER_GUNICORN_EXTRA_CONFIG +TWOOPSTRACKER_GUNICORN_LOG_LEVEL +TWOOPSTRACKER_GUNICORN_TIMEOUT +TWOOPSTRACKER_GUNICORN_WORKERS +TWOOPSTRACKER_LOGIN_URL +TWOOPSTRACKER_PASSWORD_RESET_URL +TWOOPSTRACKER_SENTRY_DSN +TWOOPSTRACKER_SOCIALACCOUNT_EMAIL_VERIFICATION diff --git a/twoops_tracker/README.md b/twoops_tracker/README.md new file mode 100644 index 00000000..45bbcdf8 --- /dev/null +++ b/twoops_tracker/README.md @@ -0,0 +1,50 @@ +## TwoopsTracker + +A Twitter-based disinformation tracking tool built on a web-based dashboard that collects deleted tweet content from previously identified trolls and disinformation actors. The project seeks to help monitor the social posts of known disinfo actors. The primary tangible output of the project is to expose trolls behind toxic disinformation campaigns who routinely cover their tracks by deleting original inflammatory social media posts that sparked hate speech, disinformation campaigns or conspiracy theories. + +## Getting Started + +First create `.env` file in the app directory. From project root directory, + +```sh +cp twoops_tracker/.env.template twoops_tracker/.env +``` + +and modify the `.env` file according to your needs. + +## Build + +To build a pex binary, run: + +```sh +./pants package twoops_tracker/py:twoopstracker +``` + +To build the docker image, run: + +```sh +VERSION=$(cat twoops_tracker/py/VERSION) ./pants package twoops_tracker/docker:twoopstracker +``` + +## Run + +To run pex binary, execute: + +```sh +./pants run twoops_tracker/py:twoopstracker +``` + +To run the built docker image, execute: + +```sh +docker-compose --env-file ./twoops_tracker/.env up twoopstracker +``` + +**NOTE**: You may need to run `postres` container first to make sure database +is ready to receive connections _before_ starting the `twoopstracker` app. + +To do so, run: + +```sh +docker-compose --env-file ./twoops_tracker/.env up db +``` diff --git a/twoops_tracker/contrib/dokku/BUILD b/twoops_tracker/contrib/dokku/BUILD new file mode 100644 index 00000000..3a1b556b --- /dev/null +++ b/twoops_tracker/contrib/dokku/BUILD @@ -0,0 +1,3 @@ +docker_image( + name="docker", +) diff --git a/twoops_tracker/contrib/dokku/Dockerfile b/twoops_tracker/contrib/dokku/Dockerfile index e9845e31..9c9f2168 100644 --- a/twoops_tracker/contrib/dokku/Dockerfile +++ b/twoops_tracker/contrib/dokku/Dockerfile @@ -1 +1 @@ -FROM codeforafrica/twoopstracker:2.0.0a5 +FROM codeforafrica/twoopstracker:2.0.0a6 diff --git a/twoops_tracker/docker/BUILD b/twoops_tracker/docker/BUILD index 40e7ee71..db97d822 100644 --- a/twoops_tracker/docker/BUILD +++ b/twoops_tracker/docker/BUILD @@ -1,10 +1,31 @@ docker_image( - name = "twoopstracker", - dependencies = [ - "twoops_tracker/py:main", - "twoops_tracker/sh:sh", + name="twoopstracker-deps", + image_tags=["deps"], + # We just need to hardcode something in the registries so that we can + # reference it the final image's COPY instructions. Can be anything + registries=["twoopstracker"], + repository="app", + skip_push=True, + source="Dockerfile.deps", +) + +docker_image( + name="twoopstracker-srcs", + image_tags=["srcs"], + registries=["twoopstracker"], + repository="app", + skip_push=True, + source="Dockerfile.srcs", +) + +docker_image( + name="twoopstracker", + dependencies=[ + ":twoopstracker-deps", + ":twoopstracker-srcs", + "twoops_tracker/sh/cmd.sh", ], - image_tags = [ + image_tags=[ "{build_args.VERSION}", "latest", ], diff --git a/twoops_tracker/docker/Dockerfile b/twoops_tracker/docker/Dockerfile index fd9cc32c..ae3dddc4 100644 --- a/twoops_tracker/docker/Dockerfile +++ b/twoops_tracker/docker/Dockerfile @@ -1,26 +1,26 @@ -FROM python:3.10-slim +FROM python:3.10-slim-bullseye AS python-base -### Arg -ARG DEBIAN_FRONTEND=noninteractive +RUN apt-get update \ + && apt-get -y upgrade \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* -### Env -ENV APP_HOST=. -ENV APP_DOCKER=/app -ENV PYTHONDONTWRITEBYTECODE 1 -ENV PYTHONUNBUFFERED 1 -ENV STATIC_ROOT=/app/staticfiles +FROM twoopstracker/app:deps AS app-deps -COPY twoops_tracker.py/main.pex /bin/dj +FROM twoopstracker/app:srcs AS app-srcs -# Expose server port -EXPOSE 8000 +FROM python-base AS python-app + +WORKDIR /app -### Volumes -WORKDIR ${APP_DOCKER} RUN mkdir -p media staticfiles logs -COPY twoops_tracker/sh/*.sh / -RUN chmod +x /cmd.sh +COPY --from=app-deps /app ./ +COPY --from=app-srcs /app ./ + +COPY twoops_tracker/sh/cmd.sh ./ +RUN chmod +x ./cmd.sh + +EXPOSE 8000 -### Run app -CMD ["/cmd.sh"] +ENTRYPOINT ["./cmd.sh"] \ No newline at end of file diff --git a/twoops_tracker/docker/Dockerfile.deps b/twoops_tracker/docker/Dockerfile.deps new file mode 100644 index 00000000..0f0efa8d --- /dev/null +++ b/twoops_tracker/docker/Dockerfile.deps @@ -0,0 +1,4 @@ +FROM python:3.10-slim-bullseye + +COPY twoops_tracker.py/twoopstracker-deps.pex /twoopstracker-deps.pex +RUN PEX_TOOLS=1 /usr/local/bin/python3.10 /twoopstracker-deps.pex venv --scope=deps --compile /app diff --git a/twoops_tracker/docker/Dockerfile.srcs b/twoops_tracker/docker/Dockerfile.srcs new file mode 100644 index 00000000..5785fb75 --- /dev/null +++ b/twoops_tracker/docker/Dockerfile.srcs @@ -0,0 +1,4 @@ +FROM python:3.10-slim-bullseye + +COPY twoops_tracker.py/twoopstracker-srcs.pex /twoopstracker-srcs.pex +RUN PEX_TOOLS=1 /usr/local/bin/python3.10 /twoopstracker-srcs.pex venv --scope=srcs --compile /app diff --git a/twoops_tracker/py/BUILD b/twoops_tracker/py/BUILD index b90d2756..f4759c66 100644 --- a/twoops_tracker/py/BUILD +++ b/twoops_tracker/py/BUILD @@ -1,6 +1,6 @@ python_sources( - name = "lib", - dependencies = [ + name="lib", + dependencies=[ "twoops_tracker/py/twoopstracker", "3rdparty/py:requirements-all#django-cors-headers", "3rdparty/py:requirements-all#django-storages", @@ -21,9 +21,23 @@ python_sources( ) pex_binary( - name = "main", - dependencies = [ + name="twoopstracker-deps", + dependencies=[ ":lib", ], - entry_point = "main.py", + entry_point="main.py", + include_sources=False, + include_tools=True, + layout="packed", +) + +pex_binary( + name="twoopstracker-srcs", + dependencies=[ + ":lib", + ], + entry_point="main.py", + include_requirements=False, + include_tools=True, + layout="packed", ) diff --git a/twoops_tracker/py/VERSION b/twoops_tracker/py/VERSION index 0691e44f..758664df 100644 --- a/twoops_tracker/py/VERSION +++ b/twoops_tracker/py/VERSION @@ -1 +1 @@ -2.0.0a5 +2.0.0a6 diff --git a/twoops_tracker/py/twoopstracker/authentication/BUILD b/twoops_tracker/py/twoopstracker/authentication/BUILD index 771fa403..db351e28 100644 --- a/twoops_tracker/py/twoopstracker/authentication/BUILD +++ b/twoops_tracker/py/twoopstracker/authentication/BUILD @@ -1,5 +1,5 @@ python_sources( - dependencies = [ + dependencies=[ "twoops_tracker/py/twoopstracker/authentication/migrations", ], ) diff --git a/twoops_tracker/py/twoopstracker/authentication/forms.py b/twoops_tracker/py/twoopstracker/authentication/forms.py index aec8866c..bd7cf7cc 100644 --- a/twoops_tracker/py/twoopstracker/authentication/forms.py +++ b/twoops_tracker/py/twoopstracker/authentication/forms.py @@ -14,7 +14,6 @@ def save(self, request, **kwargs): token_generator = kwargs.get("token_generator", default_token_generator) for user in self.users: - uid = user_pk_to_url_str(user) token = token_generator.make_token(user) frontend_url = settings.TWOOPSTRACKER_PASSWORD_RESET_URL.rstrip("/") diff --git a/twoops_tracker/py/twoopstracker/authentication/migrations/0001_user_model.py b/twoops_tracker/py/twoopstracker/authentication/migrations/0001_user_model.py index ecc35bc1..df61541f 100644 --- a/twoops_tracker/py/twoopstracker/authentication/migrations/0001_user_model.py +++ b/twoops_tracker/py/twoopstracker/authentication/migrations/0001_user_model.py @@ -7,7 +7,6 @@ class Migration(migrations.Migration): - initial = True dependencies = [ diff --git a/twoops_tracker/py/twoopstracker/authentication/migrations/0002_auto_20211110_1812.py b/twoops_tracker/py/twoopstracker/authentication/migrations/0002_auto_20211110_1812.py index 25aab5fb..cdb4374e 100644 --- a/twoops_tracker/py/twoopstracker/authentication/migrations/0002_auto_20211110_1812.py +++ b/twoops_tracker/py/twoopstracker/authentication/migrations/0002_auto_20211110_1812.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [ ("authentication", "0001_user_model"), ] diff --git a/twoops_tracker/py/twoopstracker/celery.py b/twoops_tracker/py/twoopstracker/celery.py index 03833aa8..6afffbbe 100644 --- a/twoops_tracker/py/twoopstracker/celery.py +++ b/twoops_tracker/py/twoopstracker/celery.py @@ -31,7 +31,7 @@ def start_stream_listener(): "start_stream_listener": { "task": "start_stream_listener", "schedule": crontab( - minute=f"*/{settings.TWOOPTRACKER_STREAM_LISTENER_INTERVAL}" + minute=f"*/{settings.TWOOPSTRACKER_STREAM_LISTENER_INTERVAL}" ), }, } diff --git a/twoops_tracker/py/twoopstracker/settings.py b/twoops_tracker/py/twoopstracker/settings.py index d4396156..f35e9d67 100644 --- a/twoops_tracker/py/twoopstracker/settings.py +++ b/twoops_tracker/py/twoopstracker/settings.py @@ -23,8 +23,11 @@ # Core Settings # https://docs.djangoproject.com/en/3.2/ref/settings/#core-settings + +BASE_DIR = env.path("TWOOPSTRACKER_BASE_DIR", None) +if not BASE_DIR: + BASE_DIR = Path(__file__).resolve().parent.parent # Build paths inside the project like this: BASE_DIR / 'subdir'. -BASE_DIR = Path(__file__).resolve().parent.parent # Sentry SENTRY_DSN = env.str("TWOOPSTRACKER_SENTRY_DSN", "") @@ -159,7 +162,7 @@ # https://docs.djangoproject.com/en/3.2/howto/static-files/ STATIC_URL = "/static/" -STATIC_ROOT = env.str("STATIC_ROOT", BASE_DIR / "staticfiles") +STATIC_ROOT = BASE_DIR / "staticfiles" # Default primary key field type # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field @@ -178,8 +181,8 @@ # Celery CELERY_BROKER_URL = env.str("TWOOPSTRACKER_CELERY_BROKER_URL", "") -TWOOPTRACKER_STREAM_LISTENER_INTERVAL = env.int( - "TWOOPTRACKER_STREAM_LISTENER_INTERVAL", 15 +TWOOPSTRACKER_STREAM_LISTENER_INTERVAL = env.int( + "TWOOPSTRACKER_STREAM_LISTENER_INTERVAL", 15 ) # Static Files @@ -223,11 +226,13 @@ # some to env vars. ACCOUNT_AUTHENTICATION_METHOD = "email" ACCOUNT_EMAIL_REQUIRED = True -ACCOUNT_EMAIL_VERIFICATION = env.str("ACCOUNT_EMAIL_VERIFICATION", "none") -SOCIALACCOUNT_EMAIL_VERIFICATION = env.str("SOCIALACCOUNT_EMAIL_VERIFICATION", "none") +ACCOUNT_EMAIL_VERIFICATION = env.str("TWOOPSTRACKER_ACCOUNT_EMAIL_VERIFICATION", "none") +SOCIALACCOUNT_EMAIL_VERIFICATION = env.str( + "TWOOPSTRACKER_SOCIALACCOUNT_EMAIL_VERIFICATION", "none" +) ACCOUNT_USER_MODEL_USERNAME_FIELD = None ACCOUNT_USERNAME_REQUIRED = False -LOGIN_URL = env("LOGIN_URL", "http://localhost:3000/login") +LOGIN_URL = env("TWOOPSTRACKER_LOGIN_URL", "http://localhost:3000/login") TWOOPSTRACKER_EMAIL_CONFIRMATION_URL = env.str( "TWOOPSTRACKER_EMAIL_CONFIRMATION_URL", "http://localhost:3000/api/auth/registration/confirm-email", @@ -254,12 +259,12 @@ # https://django-allauth.readthedocs.io/en/latest/advanced.html#custom-redirects ACCOUNT_ADAPTER = "twoopstracker.authentication.adapter.CustomAccountAdapter" -DEFAULT_FROM_EMAIL = env.str("DEFAULT_FROM_EMAIL", "webmaster@localhost") -EMAIL_HOST = env("EMAIL_HOST", "") -EMAIL_USE_TLS = env.bool("EMAIL_USE_TLS", True) -EMAIL_PORT = env.int("EMAIL_PORT", 587) -EMAIL_HOST_USER = env("EMAIL_HOST_USER", "") -EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD", "") +DEFAULT_FROM_EMAIL = env.str("TWOOPSTRACKER_DEFAULT_FROM_EMAIL", "webmaster@localhost") +EMAIL_HOST = env("TWOOPSTRACKER_EMAIL_HOST", "") +EMAIL_USE_TLS = env.bool("TWOOPSTRACKER_EMAIL_USE_TLS", True) +EMAIL_PORT = env.int("TWOOPSTRACKER_EMAIL_PORT", 587) +EMAIL_HOST_USER = env("TWOOPSTRACKER_EMAIL_HOST_USER", "") +EMAIL_HOST_PASSWORD = env("TWOOPSTRACKER_EMAIL_HOST_PASSWORD", "") REST_SESSION_LOGIN = False REST_USE_JWT = True diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0001_tweet_model.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0001_tweet_model.py index f87c81dd..d2da7297 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0001_tweet_model.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0001_tweet_model.py @@ -5,7 +5,6 @@ class Migration(migrations.Migration): - initial = True dependencies: List[str] = [] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0002_twitter_account.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0002_twitter_account.py index ae34b909..1ec2562a 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0002_twitter_account.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0002_twitter_account.py @@ -5,7 +5,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0001_tweet_model"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0003_userprofile.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0003_userprofile.py index 5d295bab..b26284f5 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0003_userprofile.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0003_userprofile.py @@ -5,7 +5,6 @@ class Migration(migrations.Migration): - dependencies = [ ("authentication", "0001_user_model"), ("twoops", "0002_twitter_account"), diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0004_list.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0004_list.py index bddd8d56..c0015b77 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0004_list.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0004_list.py @@ -5,7 +5,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0003_userprofile"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0005_add_default_values_for_fields.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0005_add_default_values_for_fields.py index 79a56846..d4c313aa 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0005_add_default_values_for_fields.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0005_add_default_values_for_fields.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0004_list"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0006_make_fields_optional.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0006_make_fields_optional.py index 78c139f3..9775aace 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0006_make_fields_optional.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0006_make_fields_optional.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0005_add_default_values_for_fields"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0007_allow_fields_to_be_null.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0007_allow_fields_to_be_null.py index 70deecac..945ae3d7 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0007_allow_fields_to_be_null.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0007_allow_fields_to_be_null.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0006_make_fields_optional"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0008_tweet_deleted_at.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0008_tweet_deleted_at.py index 94bdbdb0..ae19e1f4 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0008_tweet_deleted_at.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0008_tweet_deleted_at.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0007_allow_fields_to_be_null"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0009_tweet_retweeted_user_screen_name.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0009_tweet_retweeted_user_screen_name.py index ff3f2cbd..a5c8b16b 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0009_tweet_retweeted_user_screen_name.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0009_tweet_retweeted_user_screen_name.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0008_tweet_deleted_at"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0010_rename_fields_and_add_quote_count.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0010_rename_fields_and_add_quote_count.py index 53497304..a13712f9 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0010_rename_fields_and_add_quote_count.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0010_rename_fields_and_add_quote_count.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0009_tweet_retweeted_user_screen_name"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0010_tweetsearch.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0010_tweetsearch.py index 77965eba..3ee18f94 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0010_tweetsearch.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0010_tweetsearch.py @@ -5,7 +5,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0009_tweet_retweeted_user_screen_name"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0011_alter_tweet_content.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0011_alter_tweet_content.py index 74b8726e..60dcf091 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0011_alter_tweet_content.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0011_alter_tweet_content.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0010_rename_fields_and_add_quote_count"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0011_alter_tweetsearch_options.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0011_alter_tweetsearch_options.py index 67322310..b763bb69 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0011_alter_tweetsearch_options.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0011_alter_tweetsearch_options.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0010_tweetsearch"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0012_alter_twitteraccountslist_is_private.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0012_alter_twitteraccountslist_is_private.py index 59fd799f..2aa88938 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0012_alter_twitteraccountslist_is_private.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0012_alter_twitteraccountslist_is_private.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0011_alter_tweetsearch_options"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0013_auto_20211125_1324.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0013_auto_20211125_1324.py index 2ef7be6c..334ee0ba 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0013_auto_20211125_1324.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0013_auto_20211125_1324.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0012_alter_twitteraccountslist_is_private"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0014_alter_twitteraccountslist_unique_together.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0014_alter_twitteraccountslist_unique_together.py index fc34208b..e478ba2e 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0014_alter_twitteraccountslist_unique_together.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0014_alter_twitteraccountslist_unique_together.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0013_auto_20211125_1324"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0015_merge_20211201_0313.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0015_merge_20211201_0313.py index 0faf50d8..f5b61d06 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0015_merge_20211201_0313.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0015_merge_20211201_0313.py @@ -5,7 +5,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0011_alter_tweet_content"), ("twoops", "0014_alter_twitteraccountslist_unique_together"), diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0016_evidence.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0016_evidence.py index 6e3adb44..ce243590 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0016_evidence.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0016_evidence.py @@ -5,7 +5,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0015_merge_20211201_0313"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0017_auto_20211210_0103.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0017_auto_20211210_0103.py index 1aa6bdfb..ed6db721 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0017_auto_20211210_0103.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0017_auto_20211210_0103.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0016_evidence"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0018_auto_20211214_0803.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0018_auto_20211214_0803.py index b68a0745..c434461f 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0018_auto_20211214_0803.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0018_auto_20211214_0803.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0017_auto_20211210_0103"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0019_alter_category_name.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0019_alter_category_name.py index f6ef4814..be25b01a 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0019_alter_category_name.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0019_alter_category_name.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0018_auto_20211214_0803"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0020_team.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0020_team.py index be95aff8..c20648b4 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0020_team.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0020_team.py @@ -5,7 +5,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0019_alter_category_name"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0021_twitteraccount_profile_image_url_https.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0021_twitteraccount_profile_image_url_https.py index f47afe43..b06a95be 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0021_twitteraccount_profile_image_url_https.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0021_twitteraccount_profile_image_url_https.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0020_team"), ] diff --git a/twoops_tracker/py/twoopstracker/twoops/migrations/0022_make_lists_and_teams_nullable.py b/twoops_tracker/py/twoopstracker/twoops/migrations/0022_make_lists_and_teams_nullable.py index 8fb9516a..fa8a6e29 100644 --- a/twoops_tracker/py/twoopstracker/twoops/migrations/0022_make_lists_and_teams_nullable.py +++ b/twoops_tracker/py/twoopstracker/twoops/migrations/0022_make_lists_and_teams_nullable.py @@ -5,7 +5,6 @@ class Migration(migrations.Migration): - dependencies = [ ("twoops", "0021_twitteraccount_profile_image_url_https"), ] diff --git a/twoops_tracker/sh/cmd.sh b/twoops_tracker/sh/cmd.sh index 167055e6..d4c33f4f 100644 --- a/twoops_tracker/sh/cmd.sh +++ b/twoops_tracker/sh/cmd.sh @@ -1,32 +1,34 @@ #!/bin/sh -dj manage migrate --noinput # Apply database migrations -dj manage collectstatic --noinput # Collect static files +./pex manage migrate --noinput # Apply database migrations +./pex manage collectstatic --noinput # Collect static files # Prepare log files and start outputting logs to stdout -touch /app/logs/gunicorn.log -touch /app/logs/access.log -touch /app/logs/celery.log +touch ./logs/gunicorn.log +touch ./logs/access.log +touch ./logs/celery.log -tail -n 0 -f /app/logs/*.log & +tail -n 0 -f ./logs/*.log & # Start celery worker -dj celery -A twoopstracker worker -l INFO >/dev/null 2>/app/logs/celery.log & +echo Starting celery worker +./pex celery -A twoopstracker worker -l INFO >/dev/null 2>./logs/celery.log & # everytime the container is restarted, the scheduler will reset rm -rf celerybeat-schedule # Start celery beat service -dj celery -A twoopstracker beat -l INFO >/dev/null 2>/app/logs/celery.log & +echo Starting celery beat +./pex celery -A twoopstracker beat -l INFO >/dev/null 2>./logs/celery.log & # Start Gunicorn processes -echo Starting Gunicorn. -exec dj gunicorn \ +echo Starting gunicorn +exec ./pex gunicorn \ --bind 0.0.0.0:8000 \ - --workers="${TWOOPS_TRACKER_GUNICORN_WORKERS:-3}" \ + --workers="${TWOOPSTRACKER_GUNICORN_WORKERS:-3}" \ --worker-class gevent \ - --log-level="${TWOOPS_GUNICORN_LOG_LEVEL:-warning}" \ - --timeout="${TWOOPS_GUNICORN_TIMEOUT:-60}" \ - --log-file=/app/logs/gunicorn.log \ - --access-logfile=/app/logs/access.log \ - --name twoopsTracker \ - "${TWOOPSTRACKER_GUNICORN_EXTRA_CONFIG:-}" \ + --log-level="${TWOOPSTRACKER_GUNICORN_LOG_LEVEL:-warning}" \ + --timeout="${TWOOPSTRACKER_GUNICORN_TIMEOUT:-60}" \ + --log-file=./logs/gunicorn.log \ + --access-logfile=./logs/access.log \ + --name twoopstracker \ + "${TWOOPSTRACKER_GUNICORN_EXTRA_CONFIG:---reload}" \ twoopstracker.wsgi:application