From 135cfab94b7b09233142eaead562bcab4a126984 Mon Sep 17 00:00:00 2001 From: Johanna Siegel Date: Mon, 25 Nov 2024 18:34:01 +0100 Subject: [PATCH] add spring profiles to change the redis host depending on whether the application runs in docker or locally. --- .github/workflows/ci.yml | 3 +++ docker-compose.yaml | 5 ++--- src/main/resources/application-docker.properties | 2 ++ src/main/resources/application-local.properties | 2 ++ src/main/resources/application.properties | 6 ++++-- 5 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/application-docker.properties create mode 100644 src/main/resources/application-local.properties diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 539d36f..9807a35 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,6 +44,9 @@ on: pull_request: branches: [ "main" ] + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + jobs: build: name: Maven Build diff --git a/docker-compose.yaml b/docker-compose.yaml index b43f552..92c354c 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,7 +2,7 @@ version: "3.8" services: redis: - image: redis:7.4.0-alpine + image: redis:7.4.0 container_name: redis restart: always ports: @@ -36,8 +36,7 @@ services: depends_on: - redis environment: - SPRING_DATA_REDIS_HOST: redis - SPRING_DATA_REDIS_PORT: 6379 + - SPRING_PROFILES_ACTIVE=docker # select active profile in spring networks: - app-network diff --git a/src/main/resources/application-docker.properties b/src/main/resources/application-docker.properties new file mode 100644 index 0000000..c1deb6a --- /dev/null +++ b/src/main/resources/application-docker.properties @@ -0,0 +1,2 @@ +# Redis configuration for Docker +spring.data.redis.host=redis \ No newline at end of file diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties new file mode 100644 index 0000000..cf34cbe --- /dev/null +++ b/src/main/resources/application-local.properties @@ -0,0 +1,2 @@ +# Redis configuration for local deployment +spring.data.redis.host=127.0.0.1 \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 39e4235..8622510 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,7 +2,9 @@ # Redis Database # for local deplyoment change redis.host to 127.0.0.1 (when the application runs inside docker redis.host neds to be redis) -spring.data.redis.host=redis +#spring.data.redis.host=redis +# Default profile (common settings) +spring.data.redis.host=127.0.0.1 spring.data.redis.port=6379 spring.data.redis.username= spring.data.redis.password= @@ -21,4 +23,4 @@ management.endpoint.health.show-details=always management.endpoints.web.exposure.include=health # Define timeout setting for TLR services (in seconds) -tlr.timeout.seconds=60 \ No newline at end of file +tlr.timeout.seconds=60