Skip to content

Commit

Permalink
Added a target to build a docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignas committed Jan 6, 2024
1 parent 2ed9600 commit 251c5f2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
19 changes: 17 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ plugins {
id 'idea'
id 'maven-publish'
id 'com.ryandens.javaagent-application' version "0.4.2"
id 'com.bmuschko.docker-java-application' version '9.4.0'
}

String rawVersion = project.hasProperty('version') ? project.version : '0.1.0-SNAPSHOT'
String rawVersion = project.version != 'unspecified' ? project.version : '0.1.0-SNAPSHOT'
def versionWithoutPrefix = rawVersion.replaceAll('^v', '')
group = 'lt.pow.nukagit'
version = versionWithoutPrefix
Expand Down Expand Up @@ -152,4 +153,18 @@ publishing {
}
}
}
}
}

docker {
javaApplication {
baseImage = 'gcr.io/distroless/java17-debian12:latest'
maintainer = 'Ignas Mikalajunas "[email protected]"'
ports = [2222, 50051]
images = ["nukagit:${versionWithoutPrefix}", 'nukagit:latest']
args = ['serve']
}
}

dockerCreateDockerfile {
environmentVariable 'JAVA_OPTS', '-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap'
}
16 changes: 10 additions & 6 deletions src/main/java/lt/pow/nukagit/config/ConfigModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@ public class ConfigModule {

@Provides
Gestalt configurationProvider() {
String configPath = System.getProperty("nukagit.config_path", "config/application.yaml");
Path configPath = Path.of(System.getProperty("nukagit.config_path", "config/application.yaml"));
Gestalt gestalt;
try {
gestalt =
var gestaltBuilder =
new GestaltBuilder()
.addSource(
ClassPathConfigSourceBuilder.builder()
.setResource("/default.properties").build()) // Load the default property files from resources.
.addSource(FileConfigSourceBuilder.builder().setPath(Path.of(configPath)).build())
.addSource(EnvironmentConfigSourceBuilder.builder().setPrefix("NUKAGIT_").setRemovePrefix(true).build())
.build();
.setResource("/default.properties").build()); // Load the default property files from resources.

// check if the config file exists
if (configPath.toFile().exists()) {
gestaltBuilder.addSource(FileConfigSourceBuilder.builder().setPath(configPath).build());
}
gestaltBuilder.addSource(EnvironmentConfigSourceBuilder.builder().setPrefix("NUKAGIT_").setRemovePrefix(true).build());
gestalt = gestaltBuilder.build();
gestalt.loadConfigs();
} catch (GestaltException e) {
throw new RuntimeException("Failed to load configuration!", e);
Expand Down

0 comments on commit 251c5f2

Please sign in to comment.