remove sqlite everywhere, only use postgres. Do not use 5432 port to avoid conflict

This commit is contained in:
Son 2021-08-15 17:41:16 +02:00
parent 4cbbf260d4
commit d9c682a23e
5 changed files with 28 additions and 40 deletions

View File

@ -25,12 +25,11 @@ jobs:
# required # required
POSTGRES_PASSWORD: test POSTGRES_PASSWORD: test
# optional (defaults to `5432`) # optional (defaults to `5432`)
POSTGRES_PORT: 5432 POSTGRES_PORT: 15432
# optional (defaults to `postgres`) # optional (defaults to `postgres`)
POSTGRES_USER: test POSTGRES_USER: test
ports: ports:
# maps tcp port 5432 on service container to the host - 15432:15432
- 5432:5432
# set health checks to wait until postgres has started # set health checks to wait until postgres has started
options: >- options: >-
--health-cmd pg_isready --health-cmd pg_isready

View File

@ -1,21 +1,6 @@
Thanks for taking the time to contribute! 🎉👍 Thanks for taking the time to contribute! 🎉👍
The project uses Flask and requires Python3.7+. The project uses Flask, Python3.7+ and requires Postgres 12+ as dependency.
## Quick start
If you have Docker installed, run the following command to start SimpleLogin local server:
```bash
docker run --name sl -it --rm \
-e RESET_DB=true \
-e CONFIG=/code/example.env \
-p 7777:7777 \
simplelogin/app:3.4.0 python server.py
```
Then open http://localhost:7777, you should be able to login with `john@wick.com/password` account.
## General Architecture ## General Architecture
@ -25,15 +10,16 @@ Then open http://localhost:7777, you should be able to login with `john@wick.com
SimpleLogin backend consists of 2 main components: SimpleLogin backend consists of 2 main components:
- the `webapp` used by several clients: web UI (the dashboard), browser extension (Chrome & Firefox for now), OAuth clients (apps that integrate "Login with SimpleLogin" button) and mobile app (work in progress). - the `webapp` used by several clients: the web app, the browser extensions (Chrome & Firefox for now), OAuth clients (apps that integrate "Sign in with SimpleLogin" button) and mobile apps.
- the `email handler`: implements the email forwarding (i.e. alias receiving email) and email sending (i.e. alias sending email). - the `email handler`: implements the email forwarding (i.e. alias receiving email) and email sending (i.e. alias sending email).
## Run code locally ## Install dependencies
The project uses The project requires:
- Python 3.7+ and [poetry](https://python-poetry.org/) to manage dependencies - Python 3.7+ and [poetry](https://python-poetry.org/) to manage dependencies
- Node v10 for front-end. - Node v10 for front-end.
- Postgres 12+
First, install all dependencies by running the following command. First, install all dependencies by running the following command.
Feel free to use `virtualenv` or similar tools to isolate development environment. Feel free to use `virtualenv` or similar tools to isolate development environment.
@ -42,22 +28,24 @@ Feel free to use `virtualenv` or similar tools to isolate development environmen
poetry install poetry install
``` ```
On Mac, sometimes you might need to install some other packages like On Mac, sometimes you might need to install some other packages via `brew`:
```bash ```bash
brew install pkg-config libffi openssl postgresql brew install pkg-config libffi openssl postgresql
``` ```
You also need to install `gpg`, on Mac it can be done with: You also need to install `gpg` tool, on Mac it can be done with:
```bash ```bash
brew install gnupg brew install gnupg
``` ```
Then make sure all tests pass. You need to run a local postgres database to run tests, it can be run with docker with: ## Run tests
Running test requires a Postgres database. You can run one with docker:
```bash ```bash
docker run -e POSTGRES_PASSWORD=test -e POSTGRES_USER=test -e POSTGRES_DB=test -p 5432:5432 postgres:13 docker run -e POSTGRES_PASSWORD=test -e POSTGRES_USER=test -e POSTGRES_DB=test -p 15432:5432 postgres:13
``` ```
then run all tests then run all tests
@ -66,6 +54,8 @@ then run all tests
pytest pytest
``` ```
## Run the code locally
Install npm packages Install npm packages
```bash ```bash
@ -78,17 +68,19 @@ To run the code locally, please create a local setting file based on `example.en
cp example.env .env cp example.env .env
``` ```
Run the postgres database:
```bash
docker run -e POSTGRES_PASSWORD=mypassword -e POSTGRES_USER=myuser -e POSTGRES_DB=simplelogin -p 35432:5432 postgres:13
```
To run the server: To run the server:
``` ```
python3 server.py flask db upgrade && flask dummy-data && python3 server.py
``` ```
then open http://localhost:7777, you should be able to login with the following account then open http://localhost:7777, you should be able to login with `john@wick.com / password` account.
```
john@wick.com / password
```
You might need to change the `.env` file for developing certain features. This file is ignored by git. You might need to change the `.env` file for developing certain features. This file is ignored by git.

View File

@ -75,10 +75,7 @@ EMAIL_SERVERS_WITH_PRIORITY=[(10, "email.hostname.")]
# DKIM_PRIVATE_KEY_PATH=local_data/dkim.key # DKIM_PRIVATE_KEY_PATH=local_data/dkim.key
# DB Connection # DB Connection
# Local SQLite database DB_URI=postgresql://myuser:mypassword@localhost:35432/simplelogin
DB_URI=sqlite:///db.sqlite
# Postgres
# DB_URI=postgresql://myuser:mypassword@sl-db:5432/simplelogin
FLASK_SECRET=secret FLASK_SECRET=secret

View File

@ -4,13 +4,13 @@
# create a postgres database for SimpleLogin # create a postgres database for SimpleLogin
docker rm -f sl-db docker rm -f sl-db
docker run -p 15432:5432 --name sl-db -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=sl -d postgres docker run -p 25432:5432 --name sl-db -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=sl -d postgres:13
# run run `flask db upgrade` to upgrade the DB to the latest stage and # run run `flask db upgrade` to upgrade the DB to the latest stage and
env DB_URI=postgresql://postgres:postgres@127.0.0.1:15432/sl flask db upgrade env DB_URI=postgresql://postgres:postgres@127.0.0.1:25432/sl flask db upgrade
# finally `flask db migrate` to generate the migration script. # finally `flask db migrate` to generate the migration script.
env DB_URI=postgresql://postgres:postgres@127.0.0.1:15432/sl flask db migrate env DB_URI=postgresql://postgres:postgres@127.0.0.1:25432/sl flask db migrate
# remove the db # remove the db
docker rm -f sl-db docker rm -f sl-db

View File

@ -14,7 +14,7 @@ MAX_NB_EMAIL_FREE_PLAN=3
EMAIL_SERVERS_WITH_PRIORITY=[(10, "email.hostname.")] EMAIL_SERVERS_WITH_PRIORITY=[(10, "email.hostname.")]
DKIM_PRIVATE_KEY_PATH=local_data/dkim.key DKIM_PRIVATE_KEY_PATH=local_data/dkim.key
DB_URI=postgresql://test:test@localhost:5432/test DB_URI=postgresql://test:test@localhost:15432/test
# Flask # Flask
FLASK_SECRET=secret FLASK_SECRET=secret