Skip to content

Commit

Permalink
Merge branch 'master' into slim-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
onigoetz authored Feb 8, 2024
2 parents c1a107a + 722053d commit 57c052d
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.stream.Collectors;

import com.github.swissquote.carnotzet.core.maven.CarnotzetModuleCoordinates;
import com.github.swissquote.carnotzet.core.maven.ComparableVersion;
import com.github.swissquote.carnotzet.core.maven.MavenDependencyResolver;
import com.github.swissquote.carnotzet.core.maven.ResourcesManager;

Expand Down Expand Up @@ -68,6 +67,12 @@ public class Carnotzet {
@Getter
private final Boolean attachToCarnotzetNetwork;

@Getter
private final Boolean useExternalNetwork;

@Getter
private final String externalNetworkName;

@Getter
private final Boolean supportLegacyDnsNames;

Expand Down Expand Up @@ -135,6 +140,18 @@ public Carnotzet(CarnotzetConfig config) {
this.attachToCarnotzetNetwork = true;
}

if (config.getUseExternalNetwork() != null) {
this.useExternalNetwork = config.getUseExternalNetwork();
} else {
this.useExternalNetwork = false;
}

if (config.getExternalNetworkName() != null) {
this.externalNetworkName = config.getExternalNetworkName();
} else {
this.externalNetworkName = CarnotzetConfig.DEFAULT_EXTERNAL_NETWORK_NAME;
}

if (config.getSupportLegacyDnsNames() != null) {
this.supportLegacyDnsNames = config.getSupportLegacyDnsNames();
} else {
Expand Down Expand Up @@ -167,7 +184,6 @@ public List<CarnotzetModule> getModules() {
}
}
assertNoDuplicateArtifactId(modules);
assertMinimalVersionOfCarnotzet(modules);
modules = selectModulesForUniqueServiceId(modules);
}
return modules;
Expand Down Expand Up @@ -219,38 +235,6 @@ private void assertNoDuplicateArtifactId(List<CarnotzetModule> modules) {
});
}

private void assertMinimalVersionOfCarnotzet(List<CarnotzetModule> modules) {
ComparableVersion actualVersion = getCarnotzetVersion();
log.debug("Version of carnotzet : {}", actualVersion);
for (CarnotzetModule module : modules) {
String minVersionForModuleStr = module.getProperties().get("carnotzet.min.version");
if (minVersionForModuleStr == null) {
continue;
}
ComparableVersion minVersionForModule = new ComparableVersion(minVersionForModuleStr);
log.debug("Min version of carnotzet for [{}] : {}", module.getName(), minVersionForModule);
log.debug("Comparison result : {}", minVersionForModule.compareTo(actualVersion));
if (minVersionForModule.compareTo(actualVersion) > 0) {
throw new CarnotzetDefinitionException("Module [" + module.getName() + "] requires features introduced "
+ "in carnotzet version [" + minVersionForModule + "] and you seem to be using "
+ "version [" + actualVersion + "]. Please upgrade your version of carnotzet and try again.");
}
}

}

private ComparableVersion getCarnotzetVersion() {
final Properties properties = new Properties();
try {
properties.load(this.getClass().getClassLoader().getResourceAsStream("maven.properties"));
String versionString = properties.getProperty("carnotzet.version");
return new ComparableVersion(versionString);
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
}

public Optional<CarnotzetModule> getModule(@NonNull String moduleName) {
return getModules().stream().filter(module -> moduleName.equals(module.getName())).findFirst();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class CarnotzetConfig {
public final static String DEFAULT_MODULE_FILTER_PATTERN = "(.*)-carnotzet";
public final static String DEFAULT_CLASSIFIER_INCLUDE_PATTERN = ".*carnotzet";
public final static String DEFAULT_DOCKER_REGISTRY = "docker.io";
public final static String DEFAULT_EXTERNAL_NETWORK_NAME = "docker-compose_jenkins-build-bridge";
public final static List<String> DEFAULT_PROP_FILE_NAMES = Collections.singletonList("carnotzet.properties");

@NonNull
Expand Down Expand Up @@ -81,6 +82,16 @@ public class CarnotzetConfig {
*/
private final Boolean attachToCarnotzetNetwork;

/**
* When running carnotzet inside a container, use existing external bridge network.
*/
private final Boolean useExternalNetwork;

/**
* When running carnotzet inside a container, use existing external bridge network.
*/
private final String externalNetworkName;

/**
* Enable or disable support for legacy DNS names (container_name.)image_name.docker<br>
* Support is enabled by default (true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
Expand All @@ -18,7 +19,7 @@ private PropertyUtils() {

// Inspired by java.utils.Properties#store0, but sorts lines in lexicographical order and doesn't output comments in the file
public static void outputCleanPropFile(Properties props, Path path) throws IOException {
try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(path), "8859_1"))) {
try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(path), StandardCharsets.ISO_8859_1))) {
synchronized (props) {
List<String> keys = Collections.list(props.keys()).stream().map(Object::toString).collect(Collectors.toList());
Collections.sort(keys);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private Node resolveDependencyTree(Path pomFile) {
+ " -DoutputType=text "
+ " -DoutputFile=" + treePath.toAbsolutePath().toString();
executeMavenBuild(Arrays.asList(command), null);
try (Reader r = new InputStreamReader(Files.newInputStream(treePath), "UTF-8")) {
try (Reader r = new InputStreamReader(Files.newInputStream(treePath), StandardCharsets.UTF_8)) {
return new TreeTextParser().parse(r);
}
catch (ParseException | IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ private static final class Sort {
private final Map<GA, Node> resolvedNodes = new HashMap<>();

// Only used to provide nice error messages in case of cycles
private Stack<Node> stack = new Stack<>();
private final Stack<Node> stack = new Stack<>();

// for cycles detection
private final Set<GA> temporaryMarkers = new HashSet<>();
private final Set<GA> permanentMarkers = new HashSet<>();

private List<Node> result = new ArrayList<>();
private final List<Node> result = new ArrayList<>();

private List<Node> compute() {
// sorting the resolved tree is not enough because of omitted nodes, see unit tests for counter examples.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public abstract class LogListenerBase implements LogListener {
/**
* Indicates how many lines of logs to get at max
*/
private Integer tail;
private final Integer tail;

/**
* Indicates if this listener should
*/
private boolean follow;
private final boolean follow;

@Setter
private Predicate<LogEvent> eventFilter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class StdOutLogPrinter extends LogListenerBase {

private final static List<Ansi.Color> UNICORN_RAINBOW_MAGIC = new ArrayList<>();

private Map<String, Ansi.Color> serviceColors = new HashMap<>();
private final Map<String, Ansi.Color> serviceColors = new HashMap<>();

private Integer longestServiceName = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static class StartupWrapper {
private String wrapperName = "wrapper";

// Local images may not be available for target runtime environment (ie : cloud)
private Boolean ignoreLocalImages = false;
private final Boolean ignoreLocalImages = false;

@SuppressFBWarnings("CT_CONSTRUCTOR_THROW")
public StartupWrapper(@NonNull CarnotzetModule moduleToWrap) {
Expand Down Expand Up @@ -183,7 +183,7 @@ public CarnotzetModule build() {
if (!wrapperScript.toFile().setExecutable(true, false)) {
throw new IOException("Could not make file executable : " + wrapperScript.toAbsolutePath());
}
allVolumes.add(wrapperScript.toString() + ":/" + scriptName);
allVolumes.add(wrapperScript + ":/" + scriptName);
}
catch (IOException e) {
throw new UncheckedIOException(e);
Expand All @@ -210,7 +210,7 @@ public enum DockerExecutionItem {
ENTRYPOINT("Entrypoint"), CMD("Cmd");

@Getter
private String jsonField;
private final String jsonField;

DockerExecutionItem(String fieldName) {
this.jsonField = fieldName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;
Expand Down Expand Up @@ -52,7 +52,7 @@ public T computeIfAbsent(String key, Function<String, String> mappingFunction) t
if (value == null) {
value = mappingFunction.apply(key);
this.cache.put(key, value);
try (Writer out = new OutputStreamWriter(new FileOutputStream(this.cachePath.toFile()), Charset.forName("UTF-8"))) {
try (Writer out = new OutputStreamWriter(new FileOutputStream(this.cachePath.toFile()), StandardCharsets.UTF_8)) {
this.cache.store(out, "Added value for key " + key);
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/welcome/before.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
</style>
</head>
<body>
<h1>Carnotzet Environment</h1>
<h1>Sandbox Home</h1>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</style>
</head>
<body>
<h1>Carnotzet Environment</h1><div>
<h1>Sandbox Home</h1><div>
This is the documentation for module 1
</div>
<div>
Expand Down
Loading

0 comments on commit 57c052d

Please sign in to comment.