Stop not configured Deployments

This commit is contained in:
DerDavidBohl
2025-01-15 08:24:25 +01:00
parent 16a02d44f9
commit 73a8a8dfe2
2 changed files with 24 additions and 1 deletions

View File

@@ -1,2 +1,2 @@
POST http://localhost:8080/deployments/all/start
POST http://localhost:8080/api/v1/deployments/all/start

View File

@@ -40,6 +40,29 @@ public class DeploymentsService {
DeploynentConfiguration deploymentsConfiguration = tryGetConfiguration();
deployAll(deploymentsConfiguration.deployments());
stopNotConfiguredDeployments(deploymentsConfiguration.deployments());
}
private void stopNotConfiguredDeployments(List<Deployment> deployments) {
File deploymentsDir = new File("deployments");
File[] files = deploymentsDir.listFiles();
if(files == null)
return;
for (File file : files) {
if (file.isDirectory() && !deployments.stream().anyMatch(d -> d.name().equals(file.getName()))) {
try {
new ProcessBuilder(composeCommand, "down")
.directory(file.getAbsoluteFile())
.start()
.waitFor();
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
private void deployAll(List<Deployment> deployments) {