From 951d817a6aeb1297874e8b05a5bed0c50d82c5c4 Mon Sep 17 00:00:00 2001 From: Eduard Kaverinskyi Date: Fri, 1 Nov 2024 20:08:36 +0100 Subject: [PATCH] Fix local setup (#82) * pyproject.toml: Add whois to the list of packages. This fixes the db_create.py helper script being unable to import modules from whois. * whois/settings.py: add 192.168.88.1-255 as the default IP mask * README.md: Extend the local setup guide * whois/settings.py: Raise ValueError is the APP_IP_MASK variable was not set * README.md: Add guide to set APP_IP_MASK variable --------- Co-authored-by: Norbert Szulc --- README.md | 58 ++++++++++++++++++++++++++++++++++++----------- pyproject.toml | 1 + whois/settings.py | 4 +++- 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index fa5d5fb..609b8bb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # whohacks @ hsp.sh? + [![Build status](https://github.com/hspsh/whohacks/actions/workflows/build.yml/badge.svg)](https://github.com/hspsh/whohacks/actions/workflows/build.yml) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black) ## Prerequisities @@ -7,32 +8,63 @@ ## Instalation -- Dependencies +### Install dependencies ```shell poetry install ``` +## Setup whohacks locally + +### Create the database + +Local setup involves using the sqlite3 database. Before running the web server, +we need to create the database with helper script: + +```shell +poetry run python helpers/db_create.py +``` + +### Setup Environment Variables + +Set the following environment variables: + +1. `SECRET_KEY` +2. `APP_IP_MASK` - A mask that filters the allowed IP's, allowing blocking + requests outside of the accepted network. For the local development purposes + this can be set to `127.0.0.1` to allow requests only from the host machine. + +Example of setting environemnt variables: + +- Windows: `set SECRET_KEY=example123`. + +- Linux: `export SECRET_KEY=example123`. + +### Launch the web server + +```shell +poetry run python -m whois +``` + +You can access the webpage by the `localhost:5000` (default settings). + +## Setup via Docker + - Create .env file, buy it doesn't work. Go figure ```shell source env.sh ``` -- Create database +### Create the database ```shell -# if running web app locally -poetry run python helpers/db_create.py -# if running web app in docker docker compose run web python helpers/db_create.py ``` -## Running +### Deploy via docker-compose ```shell -poetry run python -m whois -# or docker compose up ``` @@ -43,6 +75,7 @@ see: https://github.com/navikt/mock-oauth2-server configuration can be found in ./tests/resources If you want for redirects to work properly you need to add mock oauth to `/etc/hosts` + ```bash echo "127.0.0.1 oauth.localhost" >> /etc/hosts ``` @@ -67,13 +100,13 @@ This: `-v /etc/localtime:/etc/localtime:ro` is required to match the timezone in Sample: ```yaml -version: '3' +version: "3" services: rabbitmq: - image: 'rabbitmq:3.6-management-alpine' + image: "rabbitmq:3.6-management-alpine" ports: - - '5672:5672' - - '15672:15672' + - "5672:5672" + - "15672:15672" web: build: ./docker/web environment: @@ -98,7 +131,6 @@ services: volumes: database: - ``` ### Envvars diff --git a/pyproject.toml b/pyproject.toml index 264185a..9a4ca55 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,6 +3,7 @@ name = "whohacks" version = "1.5.0" description = "" authors = ["Norbert Szulc "] +packages = [{ include = "whois" }] package-mode = false [tool.poetry.dependencies] diff --git a/whois/settings.py b/whois/settings.py index 92680f3..3c49619 100644 --- a/whois/settings.py +++ b/whois/settings.py @@ -43,4 +43,6 @@ # production # ip_mask = "192.168.88.1-255" -ip_mask = os.environ.get("APP_IP_MASK") \ No newline at end of file +ip_mask = os.environ.get("APP_IP_MASK", None) +if not ip_mask: + raise ValueError("ERROR: APP_IP_MASK environment variable was not set!") \ No newline at end of file