From 1a7aada5725cd456ae9f4f7436d022823bcd4b1a Mon Sep 17 00:00:00 2001 From: petrelevich Date: Wed, 25 Jun 2025 07:33:21 +0300 Subject: [PATCH] spring cloud --- .../api-gateway/build.gradle.kts | 25 +++++++ .../api-gateway/runApiGateway.sh | 16 +++++ .../config-server/runConfigServer.sh | 2 +- .../elk/docker-compose.yml | 68 +++++------------- .../elk/docker-compose_opensearch.yml | 70 +++++++++++++++++++ .../elk/logstash.conf | 2 +- .../eureka-server/runEurekaServer.sh | 16 +++++ 7 files changed, 145 insertions(+), 54 deletions(-) create mode 100755 2025-01/spring-35-36-spring-cloud/api-gateway/runApiGateway.sh create mode 100755 2025-01/spring-35-36-spring-cloud/elk/docker-compose_opensearch.yml create mode 100755 2025-01/spring-35-36-spring-cloud/eureka-server/runEurekaServer.sh diff --git a/2025-01/spring-35-36-spring-cloud/api-gateway/build.gradle.kts b/2025-01/spring-35-36-spring-cloud/api-gateway/build.gradle.kts index 5c900b18..bd891347 100755 --- a/2025-01/spring-35-36-spring-cloud/api-gateway/build.gradle.kts +++ b/2025-01/spring-35-36-spring-cloud/api-gateway/build.gradle.kts @@ -1,3 +1,7 @@ +plugins { + id("com.google.cloud.tools.jib") +} + dependencies { implementation(project(":kafka-log-appender")) implementation("net.logstash.logback:logstash-logback-encoder") @@ -13,3 +17,24 @@ dependencies { implementation("io.micrometer:micrometer-tracing-bridge-otel") // bridges the Micrometer Observation API to OpenTelemetry. implementation("io.opentelemetry:opentelemetry-exporter-zipkin") // reports traces to Zipkin. } + +jib { + container { + creationTime.set("USE_CURRENT_TIMESTAMP") + } + from { + image = "bellsoft/liberica-openjdk-alpine-musl:21.0.1" + } + + to { + image = "localrun/api-gateway" + tags = setOf(project.version.toString()) + } +} + +tasks { + build { + dependsOn(spotlessApply) + dependsOn(jibBuildTar) + } +} diff --git a/2025-01/spring-35-36-spring-cloud/api-gateway/runApiGateway.sh b/2025-01/spring-35-36-spring-cloud/api-gateway/runApiGateway.sh new file mode 100755 index 00000000..45350fd6 --- /dev/null +++ b/2025-01/spring-35-36-spring-cloud/api-gateway/runApiGateway.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +../gradlew :api-gateway:build + +docker load --input build/jib-image.tar + +docker stop api-gateway + +docker run --rm -d --name api-gateway \ +--memory=512m \ +--cpus 1 \ +--network="host" \ +-v $HOME/.ssh:/root/.ssh \ +-e JAVA_TOOL_OPTIONS="-XX:InitialRAMPercentage=80 -XX:MaxRAMPercentage=80" \ +localrun/api-gateway:latest + diff --git a/2025-01/spring-35-36-spring-cloud/config-server/runConfigServer.sh b/2025-01/spring-35-36-spring-cloud/config-server/runConfigServer.sh index fa1c72f0..5cb30633 100755 --- a/2025-01/spring-35-36-spring-cloud/config-server/runConfigServer.sh +++ b/2025-01/spring-35-36-spring-cloud/config-server/runConfigServer.sh @@ -7,7 +7,7 @@ docker load --input build/jib-image.tar docker stop config-server docker run --rm -d --name config-server \ ---memory=256m \ +--memory=1024m \ --cpus 1 \ --network="host" \ -v $HOME/.ssh:/root/.ssh \ diff --git a/2025-01/spring-35-36-spring-cloud/elk/docker-compose.yml b/2025-01/spring-35-36-spring-cloud/elk/docker-compose.yml index e0a6b822..a310e807 100755 --- a/2025-01/spring-35-36-spring-cloud/elk/docker-compose.yml +++ b/2025-01/spring-35-36-spring-cloud/elk/docker-compose.yml @@ -1,52 +1,14 @@ services: - opensearch-node1: - image: opensearchproject/opensearch:2.18.0 - container_name: opensearch-node1 - environment: - - cluster.name=opensearch-cluster # Name the cluster - - node.name=opensearch-node1 # Name the node that will run in this container - - discovery.seed_hosts=opensearch-node1 # Nodes to look for when discovering the cluster - - cluster.initial_cluster_manager_nodes=opensearch-node1 # Nodes eligibile to serve as cluster manager - - bootstrap.memory_lock=true # Disable JVM heap memory swapping - - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # Set min and max JVM heap sizes to at least 50% of system RAM - - "DISABLE_INSTALL_DEMO_CONFIG=true" # Prevents execution of bundled demo script which installs demo certificates and security configurations to OpenSearch - - "DISABLE_SECURITY_PLUGIN=true" # Disables Security plugin - ulimits: - memlock: - soft: -1 # Set memlock to unlimited (no soft or hard limit) - hard: -1 - nofile: - soft: 65536 # Maximum number of open files for the opensearch user - set to at least 65536 - hard: 65536 - volumes: - - opensearch-data1:/usr/share/opensearch/data # Creates volume called opensearch-data1 and mounts it to the container - ports: - - 9200:9200 # REST API - - 9600:9600 # Performance Analyzer - networks: - - opensearch-net # All of the containers will join the same Docker bridge network - opensearch-dashboards: - image: opensearchproject/opensearch-dashboards:2.18.0 - container_name: opensearch-dashboards - ports: - - 5601:5601 # Map host port 5601 to container port 5601 - expose: - - "5601" # Expose port 5601 for web access to OpenSearch Dashboards - environment: - - 'OPENSEARCH_HOSTS=["http://opensearch-node1:9200","http://opensearch-node2:9200"]' - - "DISABLE_SECURITY_DASHBOARDS_PLUGIN=true" # disables security dashboards plugin in OpenSearch Dashboards - networks: - - opensearch-net - -#logstash logstash: image: opensearchproject/logstash-oss-with-opensearch-output-plugin:7.16.2 container_name: logstash volumes: - ./logstash.conf:/usr/share/logstash/pipeline/logstash.conf - networks: - - opensearch-net + deploy: + resources: + limits: + memory: "512M" zookeeper: image: confluentinc/cp-zookeeper:6.2.0 @@ -54,8 +16,10 @@ services: environment: ZOOKEEPER_CLIENT_PORT: 2181 ZOOKEEPER_TICK_TIME: 2000 - networks: - - opensearch-net + deploy: + resources: + limits: + memory: "256M" broker: image: confluentinc/cp-kafka:7.0.0 @@ -72,8 +36,10 @@ services: KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 - networks: - - opensearch-net + deploy: + resources: + limits: + memory: "512M" kafka-ui: container_name: kafka-ui @@ -83,6 +49,10 @@ services: DYNAMIC_CONFIG_ENABLED: 'true' KAFKA_CLUSTERS_0_NAME: local KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: localhost:9092 + deploy: + resources: + limits: + memory: "256M" zipkin: container_name: zipkin @@ -90,9 +60,3 @@ services: network_mode: "host" expose: - "9411" - -volumes: - opensearch-data1: - -networks: - opensearch-net: \ No newline at end of file diff --git a/2025-01/spring-35-36-spring-cloud/elk/docker-compose_opensearch.yml b/2025-01/spring-35-36-spring-cloud/elk/docker-compose_opensearch.yml new file mode 100755 index 00000000..3d16ad60 --- /dev/null +++ b/2025-01/spring-35-36-spring-cloud/elk/docker-compose_opensearch.yml @@ -0,0 +1,70 @@ + +services: + opensearch-node1: + image: opensearchproject/opensearch:2.18.0 + container_name: opensearch-node1 + environment: + - cluster.name=opensearch-cluster # Name the cluster + - node.name=opensearch-node1 # Name the node that will run in this container + - discovery.seed_hosts=opensearch-node1,opensearch-node2 # Nodes to look for when discovering the cluster + - cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2 # Nodes eligibile to serve as cluster manager + - bootstrap.memory_lock=true # Disable JVM heap memory swapping + - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # Set min and max JVM heap sizes to at least 50% of system RAM + - "DISABLE_INSTALL_DEMO_CONFIG=true" # Prevents execution of bundled demo script which installs demo certificates and security configurations to OpenSearch + - "DISABLE_SECURITY_PLUGIN=true" # Disables Security plugin + ulimits: + memlock: + soft: -1 # Set memlock to unlimited (no soft or hard limit) + hard: -1 + nofile: + soft: 65536 # Maximum number of open files for the opensearch user - set to at least 65536 + hard: 65536 + volumes: + - opensearch-data1:/usr/share/opensearch/data # Creates volume called opensearch-data1 and mounts it to the container + ports: + - 9200:9200 # REST API + - 9600:9600 # Performance Analyzer + networks: + - opensearch-net # All of the containers will join the same Docker bridge network + opensearch-node2: + image: opensearchproject/opensearch:2.18.0 + container_name: opensearch-node2 + environment: + - cluster.name=opensearch-cluster # Name the cluster + - node.name=opensearch-node2 # Name the node that will run in this container + - discovery.seed_hosts=opensearch-node1,opensearch-node2 # Nodes to look for when discovering the cluster + - cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2 # Nodes eligibile to serve as cluster manager + - bootstrap.memory_lock=true # Disable JVM heap memory swapping + - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # Set min and max JVM heap sizes to at least 50% of system RAM + - "DISABLE_INSTALL_DEMO_CONFIG=true" # Prevents execution of bundled demo script which installs demo certificates and security configurations to OpenSearch + - "DISABLE_SECURITY_PLUGIN=true" # Disables Security plugin + ulimits: + memlock: + soft: -1 # Set memlock to unlimited (no soft or hard limit) + hard: -1 + nofile: + soft: 65536 # Maximum number of open files for the opensearch user - set to at least 65536 + hard: 65536 + volumes: + - opensearch-data2:/usr/share/opensearch/data # Creates volume called opensearch-data2 and mounts it to the container + networks: + - opensearch-net # All of the containers will join the same Docker bridge network + opensearch-dashboards: + image: opensearchproject/opensearch-dashboards:2.18.0 + container_name: opensearch-dashboards + ports: + - 5601:5601 # Map host port 5601 to container port 5601 + expose: + - "5601" # Expose port 5601 for web access to OpenSearch Dashboards + environment: + - 'OPENSEARCH_HOSTS=["http://opensearch-node1:9200","http://opensearch-node2:9200"]' + - "DISABLE_SECURITY_DASHBOARDS_PLUGIN=true" # disables security dashboards plugin in OpenSearch Dashboards + networks: + - opensearch-net + +volumes: + opensearch-data1: + opensearch-data2: + +networks: + opensearch-net: \ No newline at end of file diff --git a/2025-01/spring-35-36-spring-cloud/elk/logstash.conf b/2025-01/spring-35-36-spring-cloud/elk/logstash.conf index 35bb470e..9ac0abd3 100644 --- a/2025-01/spring-35-36-spring-cloud/elk/logstash.conf +++ b/2025-01/spring-35-36-spring-cloud/elk/logstash.conf @@ -14,7 +14,7 @@ input { output { opensearch { - hosts => "http://opensearch-node1:9200" + hosts => "http://178.130.58.173:9200" user => "admin" password => "admin" index => "logstash-logs-%{+YYYY.MM.dd}" diff --git a/2025-01/spring-35-36-spring-cloud/eureka-server/runEurekaServer.sh b/2025-01/spring-35-36-spring-cloud/eureka-server/runEurekaServer.sh new file mode 100755 index 00000000..8fefacd5 --- /dev/null +++ b/2025-01/spring-35-36-spring-cloud/eureka-server/runEurekaServer.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +../gradlew :eureka-server:build + +docker load --input build/jib-image.tar + +docker stop eureka-server + +docker run --rm -d --name eureka-server \ +--memory=512m \ +--cpus 1 \ +--network="host" \ +-v $HOME/.ssh:/root/.ssh \ +-e JAVA_TOOL_OPTIONS="-XX:InitialRAMPercentage=80 -XX:MaxRAMPercentage=80" \ +localrun/eureka-server:latest +