Skip to content

Commit

Permalink
Fix local setup (#82)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
EduKav1813 and not7cd authored Nov 1, 2024
1 parent 38ba92b commit 951d817
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
58 changes: 45 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
```

Expand All @@ -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
```
Expand All @@ -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:
Expand All @@ -98,7 +131,6 @@ services:

volumes:
database:

```
### Envvars
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "whohacks"
version = "1.5.0"
description = ""
authors = ["Norbert Szulc <[email protected]>"]
packages = [{ include = "whois" }]
package-mode = false

[tool.poetry.dependencies]
Expand Down
4 changes: 3 additions & 1 deletion whois/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@

# production
# ip_mask = "192.168.88.1-255"
ip_mask = os.environ.get("APP_IP_MASK")
ip_mask = os.environ.get("APP_IP_MASK", None)
if not ip_mask:
raise ValueError("ERROR: APP_IP_MASK environment variable was not set!")

0 comments on commit 951d817

Please sign in to comment.