Skip to content

Commit

Permalink
Merge pull request #8 from FinnStutzenstein/fixed-env-variables
Browse files Browse the repository at this point in the history
Unified env variable names
  • Loading branch information
FinnStutzenstein authored Feb 25, 2020
2 parents 693c49b + bf6817f commit 51af334
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion writer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ build-dev:
docker build -t openslides-datastore-writer-dev -f Dockerfile.dev .

run-dev: | build-dev
docker run -t -v `pwd`/writer:/app/writer -p 127.0.0.1:8000:8000/tcp openslides-datastore-writer-dev
docker run -t -v `pwd`/writer:/app/writer -p 127.0.0.1:8000:8000/tcp openslides-datastore-writer-dev
10 changes: 5 additions & 5 deletions writer/dc.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ services:
- postgresql
- redis
environment:
- db_host=postgresql
- db_user=openslides
- db_password=openslides
- db_database=openslides
- redis_host=redis
- DATASTORE_DATABASE_HOST=postgresql
- DATASTORE_DATABASE_USER=openslides
- DATASTORE_DATABASE_PASSWORD=openslides
- DATASTORE_DATABASE_NAME=openslides
- MESSAGE_BUS_HOST=redis
networks:
- postgresql
- redis
Expand Down
13 changes: 8 additions & 5 deletions writer/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/bin/bash

export DATASTORE_DATABASE_PORT="${DATASTORE_DATABASE_PORT:-5432}"

# TODO: read optional ports from env variables: db_port and redis_port
wait-for-it --timeout=10 "$db_host":5432
wait-for-it --timeout=10 "$redis_host":6379
wait-for-it --timeout=10 "$DATASTORE_DATABASE_HOST:$DATASTORE_DATABASE_PORT"
wait-for-it --timeout=10 "$MESSAGE_BUS_HOST:$MESSAGE_BUS_PORT"

# Create schema in postgresql
export PGPASSWORD="$db_password"
psql -h "$db_host" -U "$db_user" -d "$db_database" -f writer/postgresql_backend/schema.sql
export PGPASSWORD="$DATASTORE_DATABASE_PASSWORD"
psql -1 -h "$DATASTORE_DATABASE_HOST" -p "$DATASTORE_DATABASE_PORT" -U "$DATASTORE_DATABASE_USER" -d "$DATASTORE_DATABASE_NAME" -f writer/postgresql_backend/schema.sql

exec $*
exec "$@"
14 changes: 8 additions & 6 deletions writer/tests/system/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
SqlReadDatabaseBackendService,
setup_di as postgresql_setup_di,
)
from writer.postgresql_backend.pg_connection_handler import ENVIRONMENT_VARIABLES as POSTGRESQL_ENVIRONMENT_VARIABLES
from writer.redis_backend import (
RedisMessagingBackendService,
setup_di as redis_setup_di,
)
from writer.redis_backend.redis_connection_handler import ENVIRONMENT_VARIABLES as REDIS_ENVIRONMENT_VARIABLES
from writer.redis_backend.redis_messaging_backend_service import MODIFIED_FIELDS_TOPIC
from writer.shared import setup_di as shared_setup_di

Expand All @@ -44,11 +46,11 @@ def get_env(name):
def setup_db_connection():
global _db_connection
_db_connection = psycopg2.connect(
host=get_env("db_host"),
port=int(get_env("db_port") or 5432),
database=get_env("db_database"),
user=get_env("db_user"),
password=get_env("db_password"),
host=get_env(POSTGRESQL_ENVIRONMENT_VARIABLES.HOST),
port=int(get_env(POSTGRESQL_ENVIRONMENT_VARIABLES.PORT) or 5432),
database=get_env(POSTGRESQL_ENVIRONMENT_VARIABLES.NAME),
user=get_env(POSTGRESQL_ENVIRONMENT_VARIABLES.USER),
password=get_env(POSTGRESQL_ENVIRONMENT_VARIABLES.PASSWORD),
)
_db_connection.autocommit = False
yield _db_connection
Expand Down Expand Up @@ -116,7 +118,7 @@ def xadd_callback_noop(response, **options):
def setup_redis_connection():
global _redis_connection
_redis_connection = redis.Redis(
host=get_env("redis_host"), port=int(get_env("redis_port") or 6379),
host=get_env(REDIS_ENVIRONMENT_VARIABLES.HOST), port=int(get_env(REDIS_ENVIRONMENT_VARIABLES.PORT) or 6379),
)
_redis_connection.set_response_callback("XREAD", xadd_callback_noop)
yield _redis_connection
Expand Down
12 changes: 6 additions & 6 deletions writer/writer/postgresql_backend/pg_connection_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@


class ENVIRONMENT_VARIABLES:
HOST = "db_host"
PORT = "db_port"
DATABASE = "db_database"
USER = "db_user"
PASSWORD = "db_password"
HOST = "DATASTORE_DATABASE_HOST"
PORT = "DATASTORE_DATABASE_PORT"
NAME = "DATASTORE_DATABASE_NAME"
USER = "DATASTORE_DATABASE_USER"
PASSWORD = "DATASTORE_DATABASE_PASSWORD"


class ConnectionContext:
Expand Down Expand Up @@ -57,7 +57,7 @@ def get_connection_params(self):
return {
"host": self.environment.get(ENVIRONMENT_VARIABLES.HOST),
"port": int(self.environment.try_get(ENVIRONMENT_VARIABLES.PORT) or 5432),
"database": self.environment.get(ENVIRONMENT_VARIABLES.DATABASE),
"database": self.environment.get(ENVIRONMENT_VARIABLES.NAME),
"user": self.environment.get(ENVIRONMENT_VARIABLES.USER),
"password": self.environment.get(ENVIRONMENT_VARIABLES.PASSWORD),
}
Expand Down
4 changes: 2 additions & 2 deletions writer/writer/redis_backend/redis_connection_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@


class ENVIRONMENT_VARIABLES:
HOST = "redis_host"
PORT = "redis_port"
HOST = "MESSAGE_BUS_HOST"
PORT = "MESSAGE_BUS_PORT"


@service_as_singleton
Expand Down

0 comments on commit 51af334

Please sign in to comment.