Skip to content

Commit

Permalink
feat(openchallenges): make Eureka instance AWS-aware (IT-3800) (#2749)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaffter authored Jul 24, 2024
1 parent 2c52dde commit 0ac34b5
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 6 deletions.
3 changes: 2 additions & 1 deletion apps/openchallenges/service-registry/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
SERVER_PORT=8081
DEFAULT_ZONE=http://localhost:8081/eureka
DEFAULT_ZONE=http://localhost:8081/eureka
OPENCHALLENGES_SERVICE_REGISTRY_IS_DEPLOYED_ON_AWS=false
11 changes: 11 additions & 0 deletions apps/openchallenges/service-registry/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ buildscript {
}

plugins {
id 'com.diffplug.spotless' version "${spotlessVersion}"
id 'java'
id 'org.springframework.boot' version "${springBootVersion}"
id "io.spring.dependency-management" version "${springDependencyManagementVersion}"
Expand Down Expand Up @@ -41,3 +42,13 @@ tasks.withType(JavaCompile) {
bootBuildImage {
imageName = "ghcr.io/sage-bionetworks/${project.name}-base:local"
}

spotless {
java {
target 'src/*/java/**/*.java'

importOrder()
removeUnusedImports()
googleJavaFormat()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
openchallenges-service-registry:
welcome-message: 'Welcome to the service registry (local config).'
is-deployed-on-aws: false
1 change: 1 addition & 0 deletions apps/openchallenges/service-registry/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
openchallengesVersion=0.0.1-SNAPSHOT
spotlessVersion=6.11.0
springBootVersion=2.7.8
springCloudVersion=3.1.4
springDependencyManagementVersion=1.0.14.RELEASE
14 changes: 14 additions & 0 deletions apps/openchallenges/service-registry/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@
"command": "trivy image ghcr.io/sage-bionetworks/openchallenges-service-registry:local --quiet",
"color": true
}
},
"format": {
"executor": "nx:run-commands",
"options": {
"command": "./gradlew spotlessApply",
"cwd": "{projectRoot}"
}
},
"format-check": {
"executor": "nx:run-commands",
"options": {
"command": "./gradlew spotlessCheck",
"cwd": "{projectRoot}"
}
}
},
"tags": ["type:service", "scope:backend", "language:java", "package-manager:gradle"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ public static void main(String[] args) {
public void run(String... args) throws Exception {
LOG.info(serviceRegistryConfigData.getWelcomeMessage());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.sagebionetworks.openchallenges.service.registry.configuration;

import com.netflix.appinfo.AmazonInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class EurekaInstanceConfiguration {

private static final Logger LOGGER = LoggerFactory.getLogger(EurekaInstanceConfiguration.class);

/**
* If the application is planned to be deployed to an AWS cloud, the Eureka instance must be
* configured to be AWS-aware. This can be done by customizing the EurekaInstanceConfigBean.
*
* @see <a
* href="https://docs.spring.io/spring-cloud-netflix/docs/current/reference/html/#using-eureka-on-aws">Using
* Eureka on AWS</a>
*/
@Bean
@ConditionalOnProperty(
value = "openchallenges-service-registry.is-deployed-on-aws",
havingValue = "true",
matchIfMissing = false)
public EurekaInstanceConfigBean eurekaInstanceConfig(InetUtils inetUtils) {
LOGGER.info("Configuring the Eureka instance to be AWS-aware.");
EurekaInstanceConfigBean bean = new EurekaInstanceConfigBean(inetUtils);
AmazonInfo info = AmazonInfo.Builder.newBuilder().autoBuild("eureka");
bean.setDataCenterInfo(info);
return bean;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
@SpringBootTest
class ServiceRegistryApplicationTests {

@Test
void contextLoads() {
}

@Test
void contextLoads() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
public class ServiceRegistryConfigData {

private String welcomeMessage;
private boolean isDeployedOnAws;
}

0 comments on commit 0ac34b5

Please sign in to comment.