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 (#37)

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.

Attempt to fix problem with port mapping in docker-compose in Makefile (in original version service is unavailable when called from local grpc stub).

Co-authored-by: Lev Sabantsev <[email protected]>
  • Loading branch information
LeoSabantsev and Lev Sabantsev authored Jun 21, 2024
1 parent 815537d commit 0405d00
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,20 @@ 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_grpc_service_template_db_1' -f ./postgresql/data/initial_data.sql
psql ${DB_CONNECTION} -f ./postgresql/data/initial_data.sql
/home/user/.local/bin/pg_grpc_service_template \
--config /home/user/.local/etc/pg_grpc_service_template/static_config.yaml \
--config_vars /home/user/.local/etc/pg_grpc_service_template/config_vars.docker.yaml

# Build and run service in docker environment
.PHONY: docker-start-service-debug docker-start-service-release
docker-start-service-debug docker-start-service-release: docker-start-service-%:
$(DOCKER_COMPOSE) run -p 8080:8080 --rm pg_grpc_service_template-container make -- --in-docker-start-$*
$(DOCKER_COMPOSE) run -p 8080:8080 -p 8081:8081 --rm pg_grpc_service_template-container make -- --in-docker-start-$*

# Start targets makefile in docker environment
.PHONY: docker-cmake-debug docker-build-debug docker-test-debug docker-clean-debug docker-install-debug docker-cmake-release docker-build-release docker-test-release docker-clean-release docker-install-release
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 @@ -9,5 +9,3 @@ server-port: 8080
server-grpc-port: 8081

hello-endpoint: '[::1]:8081'

dbconnection: 'postgresql://user:password@service-postgres:5432/pg_grpc_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 @@ -76,6 +76,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_grpc_service_template_db_1
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
environment: &db_env
POSTGRES_DB: pg_grpc_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_grpc_service_template_db_1
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
- PREFIX=${PREFIX:-~/.local}
- CCACHE_DIR=/pg_grpc_service_template/.ccache
- CORES_DIR=/cores
<<: *db_env
PREFIX: ${PREFIX:-~/.local}
CCACHE_DIR: /pg_grpc_service_template/.ccache
CORES_DIR: /cores
volumes:
- .:/pg_grpc_service_template:rw
- ${TC_CORES_DIR:-./.cores}:/cores:rw
Expand Down

0 comments on commit 0405d00

Please sign in to comment.