Skip to content

Commit

Permalink
CLI: local run without passing secrets (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoloboschi committed Sep 14, 2023
1 parent dbda4fd commit 6af7243
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ public void run() {
log("Running all the agents in the application");
}
log("Instance file: " + instanceFile.getAbsolutePath());
log("Secrets file: " + secretsFile.getAbsolutePath());
if (secretsFile != null) {
log("Secrets file: " + secretsFile.getAbsolutePath());
}
log("Start broker: " + startBroker);
log("Start S3: " + startS3);
log("Start Webservices " + startWebservices);
Expand All @@ -141,11 +143,10 @@ public void run() {

downloadDependencies(appDirectory.toPath());

String secretsContents;
String instanceContents;
final String secretsContents;
final String instanceContents;

try {

instanceContents =
LocalFileReferenceResolver.resolveFileReferencesInYAMLFile(
instanceFile.toPath());
Expand All @@ -157,16 +158,19 @@ public void run() {
throw e;
}

try {

secretsContents =
LocalFileReferenceResolver.resolveFileReferencesInYAMLFile(
secretsFile.toPath());
} catch (Exception e) {
log(
"Failed to resolve secrets file references. Please double check the file path: "
+ secretsFile.toPath());
throw e;
if (secretsFile != null) {
try {
secretsContents =
LocalFileReferenceResolver.resolveFileReferencesInYAMLFile(
secretsFile.toPath());
} catch (Exception e) {
log(
"Failed to resolve secrets file references. Please double check the file path: "
+ secretsFile.toPath());
throw e;
}
} else {
secretsContents = null;
}

executeOnDocker(
Expand Down Expand Up @@ -194,8 +198,11 @@ private void executeOnDocker(
throws Exception {
File tmpInstanceFile = Files.createTempFile("instance", ".yaml").toFile();
Files.write(tmpInstanceFile.toPath(), instanceContents.getBytes(StandardCharsets.UTF_8));
File tmpSecretsFile = Files.createTempFile("secrets", ".yaml").toFile();
Files.write(tmpSecretsFile.toPath(), secretsContents.getBytes(StandardCharsets.UTF_8));
File tmpSecretsFile = null;
if (secretsContents != null) {
tmpSecretsFile = Files.createTempFile("secrets", ".yaml").toFile();
Files.write(tmpSecretsFile.toPath(), secretsContents.getBytes(StandardCharsets.UTF_8));
}
String imageName = dockerImageName + ":" + dockerImageVersion;
List<String> commandLine = new ArrayList<>();
commandLine.add(dockerCommand);
Expand All @@ -222,8 +229,10 @@ private void executeOnDocker(
commandLine.add(appDirectory.getAbsolutePath() + ":/code/application");
commandLine.add("-v");
commandLine.add(tmpInstanceFile.getAbsolutePath() + ":/code/instance.yaml");
commandLine.add("-v");
commandLine.add(tmpSecretsFile.getAbsolutePath() + ":/code/secrets.yaml");
if (tmpSecretsFile != null) {
commandLine.add("-v");
commandLine.add(tmpSecretsFile.getAbsolutePath() + ":/code/secrets.yaml");
}
commandLine.add("--add-host");
commandLine.add("minio.minio-dev.svc.cluster.local:127.0.0.1");
commandLine.add("--add-host");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ public static void main(String... args) {
String secretsFile = "/code/secrets.yaml";
String agentsDirectory = "/app/agents";

String secrets = Files.readString(Paths.get(secretsFile));
final String secrets;
final Path secretsPath = Paths.get(secretsFile);
if (Files.exists(secretsPath)) {
secrets = Files.readString(secretsPath);
} else {
secrets = null;
}
String instance = Files.readString(Paths.get(instanceFile));

Path codeDirectory = Paths.get(applicationPath);
Expand Down

0 comments on commit 6af7243

Please sign in to comment.