Skip to content

Commit

Permalink
feat configs: don't duplicate dbconnection in config_vars, pass it th…
Browse files Browse the repository at this point in the history
…rough env (#54)

DB env variables for 'pg_service_template-container' service in docker-compose.yml are not used at all. This is misleading and leads to the need to look for errors and change the code in several places if the database has changed.

Co-authored-by: Lev Sabantsev <[email protected]>
  • Loading branch information
LeoSabantsev and Lev Sabantsev authored Jun 21, 2024
1 parent 4682ad4 commit 6934b33
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ format:
find src -name '*pp' -type f | xargs $(CLANG_FORMAT) -i
find tests -name '*.py' -type f | xargs autopep8 -i

# Set environment for --in-docker-start
export DB_CONNECTION := postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@service-postgres:5432/${POSTGRES_DB}

# Internal hidden targets that are used only in docker environment
--in-docker-start-debug --in-docker-start-release: --in-docker-start-%: install-%
psql 'postgresql://user:password@service-postgres:5432/pg_service_template_db_1' -f ./postgresql/data/initial_data.sql
psql ${DB_CONNECTION} -f ./postgresql/data/initial_data.sql
/home/user/.local/bin/pg_service_template \
--config /home/user/.local/etc/pg_service_template/static_config.yaml \
--config_vars /home/user/.local/etc/pg_service_template/config_vars.docker.yaml
Expand Down
2 changes: 0 additions & 2 deletions configs/config_vars.docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ logger-level: debug
is-testing: false

server-port: 8080

dbconnection: 'postgresql://user:password@service-postgres:5432/pg_service_template_db_1'
1 change: 1 addition & 0 deletions configs/static_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ components_manager:

postgres-db-1:
dbconnection: $dbconnection
dbconnection#env: DB_CONNECTION
blocking_task_processor: fs-task-processor
dns_resolver: async
sync-start: false
Expand Down
18 changes: 8 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ services:
postgres:
container_name: service-postgres
image: postgres:12
environment:
- POSTGRES_DB=pg_service_template_db_1
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
environment: &db_env
POSTGRES_DB: pg_service_template_db_1
POSTGRES_USER: user
POSTGRES_PASSWORD: password
ports:
- 5432
volumes:
Expand All @@ -20,12 +20,10 @@ services:
image: ghcr.io/userver-framework/ubuntu-22.04-userver-pg:latest
privileged: true
environment:
- POSTGRES_DB=pg_service_template_db_1
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
- PREFIX=${PREFIX:-~/.local}
- CCACHE_DIR=/pg_service_template/.ccache
- CORES_DIR=/cores
<<: *db_env
PREFIX: ${PREFIX:-~/.local}
CCACHE_DIR: /pg_service_template/.ccache
CORES_DIR: /cores
volumes:
- .:/pg_service_template:rw
- ${TC_CORES_DIR:-./.cores}:/cores:rw
Expand Down

0 comments on commit 6934b33

Please sign in to comment.