Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix local setup #82

Merged
merged 6 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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!")
Loading