Browse Source

write software versions file if it does not exist

tags/v1.1.4
Jonathan Cobb 4 years ago
parent
commit
47e5852598
3 changed files with 15 additions and 4 deletions
  1. +11
    -3
      bubble-server/src/main/java/bubble/server/BubbleConfiguration.java
  2. +4
    -0
      bubble-server/src/main/java/bubble/service/packer/PackerJob.java
  3. +0
    -1
      bubble-server/src/main/java/bubble/service/packer/PackerService.java

+ 11
- 3
bubble-server/src/main/java/bubble/server/BubbleConfiguration.java View File

@@ -52,9 +52,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;


import java.beans.Transient; import java.beans.Transient;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.*;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -185,6 +183,16 @@ public class BubbleConfiguration extends PgRestServerConfiguration
} }
} }


public void saveSoftwareVersions (Properties softwareVersions) {
if (!SOFTWARE_VERSIONS_FILE.exists()) {
try (OutputStream out = new FileOutputStream(SOFTWARE_VERSIONS_FILE)) {
softwareVersions.store(out, null);
} catch (Exception e) {
log.error("saveSoftwareVersions: "+shortError(e));
}
}
}

@Setter private String localStorageDir = DEFAULT_LOCAL_STORAGE_DIR; @Setter private String localStorageDir = DEFAULT_LOCAL_STORAGE_DIR;
public String getLocalStorageDir () { return empty(localStorageDir) ? DEFAULT_LOCAL_STORAGE_DIR : localStorageDir; } public String getLocalStorageDir () { return empty(localStorageDir) ? DEFAULT_LOCAL_STORAGE_DIR : localStorageDir; }




+ 4
- 0
bubble-server/src/main/java/bubble/service/packer/PackerJob.java View File

@@ -295,6 +295,7 @@ public class PackerJob implements Callable<List<PackerImage>> {
private void writeBubbleVersions(TempDir tempDir, Map<String, String> versions) { private void writeBubbleVersions(TempDir tempDir, Map<String, String> versions) {
final File varsDir = mkdirOrDie(abs(tempDir) + "/roles/"+ROLE_BUBBLE+"/vars"); final File varsDir = mkdirOrDie(abs(tempDir) + "/roles/"+ROLE_BUBBLE+"/vars");
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
final Properties softwareProps = new Properties();
for (Map.Entry<String, String> var : versions.entrySet()) { for (Map.Entry<String, String> var : versions.entrySet()) {
final String roleName = var.getKey(); final String roleName = var.getKey();
final String version = var.getValue().trim(); final String version = var.getValue().trim();
@@ -302,8 +303,11 @@ public class PackerJob implements Callable<List<PackerImage>> {
final String hash = packerService.getSoftwareHash(roleName, version); final String hash = packerService.getSoftwareHash(roleName, version);
b.append(roleBase).append("_version : '").append(version).append("'\n") b.append(roleBase).append("_version : '").append(version).append("'\n")
.append(roleBase).append("_sha : '").append(hash).append("'\n"); .append(roleBase).append("_sha : '").append(hash).append("'\n");
softwareProps.setProperty(roleBase+"_version", version);
softwareProps.setProperty(roleBase+"_sha", hash);
} }
FileUtil.toFileOrDie(new File(varsDir, "main.yml"), b.toString()); FileUtil.toFileOrDie(new File(varsDir, "main.yml"), b.toString());
configuration.saveSoftwareVersions(softwareProps);
} }


private Map<String, String> getSoftwareVersion(String roleName, TempDir tempDir) throws IOException { private Map<String, String> getSoftwareVersion(String roleName, TempDir tempDir) throws IOException {


+ 0
- 1
bubble-server/src/main/java/bubble/service/packer/PackerService.java View File

@@ -165,7 +165,6 @@ public class PackerService {
case ROLE_DNSCRYPT: return ""; case ROLE_DNSCRYPT: return "";
default: return die("getSoftwareSuffix: unrecognized roleName: "+roleName); default: return die("getSoftwareSuffix: unrecognized roleName: "+roleName);
} }

} }


} }

Loading…
Cancel
Save