mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(core): report the build version when FLOCI_VERSION is unset (#5768)
/health, /_floci/health and the TLS certificate metadata read FLOCI_VERSION and fell back to "dev". Only the Docker images set it, so a native binary run on the host reported "dev" and the floci-cli version check skipped it. One FlociVersion helper now resolves FLOCI_VERSION first, then the version the Maven build stamps into floci/version.properties (filtered, and included in the native image), and "dev" only when neither is known. It replaces five copies of the lookup. Refs #5767 Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
1 parent
21184df828
commit
db8c441ed4
12 files changed
+126
-48
No files matched your search
@@ -440,6 +440,16 @@
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
</resource>
|
||||
<!-- Only the build version is filtered; everything else is copied as is. -->
|
||||
<resource>
|
||||
<directory>src/main/resources-filtered</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>io.quarkus.platform</groupId>
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package io.github.hectorvent.floci.config;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* The version this Floci build reports on {@code /health}, {@code /_floci/health} and in its
|
||||
* certificate metadata.
|
||||
*
|
||||
* <p>{@code FLOCI_VERSION} wins when set, so an image can still override it. Otherwise the
|
||||
* version stamped into {@code floci/version.properties} by the Maven build is used, which is what
|
||||
* a standalone native binary reports. {@code "dev"} remains only for a build that carries no
|
||||
* stamped version, such as an IDE run without resource processing.
|
||||
*
|
||||
* <p>Plain static code on purpose: {@link TlsConfigSource} runs while the configuration is still
|
||||
* being assembled, before CDI or {@code ConfigProvider} can be used.
|
||||
*/
|
||||
public final class FlociVersion {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(FlociVersion.class);
|
||||
|
||||
static final String RESOURCE = "floci/version.properties";
|
||||
static final String FALLBACK = "dev";
|
||||
|
||||
private static final String BUILD_VERSION = loadBuildVersion();
|
||||
|
||||
private FlociVersion() {
|
||||
}
|
||||
|
||||
public static String current() {
|
||||
return resolve(System.getenv("FLOCI_VERSION"), BUILD_VERSION);
|
||||
}
|
||||
|
||||
static String resolve(String override, String buildVersion) {
|
||||
if (override != null && !override.isBlank()) {
|
||||
return override;
|
||||
}
|
||||
if (buildVersion != null && !buildVersion.isBlank()) {
|
||||
return buildVersion;
|
||||
}
|
||||
return FALLBACK;
|
||||
}
|
||||
|
||||
private static String loadBuildVersion() {
|
||||
try (InputStream in = FlociVersion.class.getClassLoader().getResourceAsStream(RESOURCE)) {
|
||||
if (in == null) {
|
||||
return null;
|
||||
}
|
||||
Properties properties = new Properties();
|
||||
properties.load(in);
|
||||
String version = properties.getProperty("version");
|
||||
// An unfiltered copy (resources not processed by Maven) still holds the placeholder.
|
||||
if (version == null || version.startsWith("${")) {
|
||||
return null;
|
||||
}
|
||||
return version.trim();
|
||||
} catch (IOException e) {
|
||||
LOG.debugv("Could not read {0}: {1}", RESOURCE, e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -206,7 +206,7 @@ public class TlsCertificateManager implements Resettable {
|
||||
CertificateGenerator.GeneratedCertificate issued = ca.issueServerCertificate("localhost", sans, keyAlgorithm, keyPair);
|
||||
|
||||
Path dir = tlsDir();
|
||||
CertificateMetadata metadata = CertificateMetadata.create(configuredHostnames, resolveFlociVersion());
|
||||
CertificateMetadata metadata = CertificateMetadata.create(configuredHostnames, FlociVersion.current());
|
||||
metadata.setLearnedHostnames(new ArrayList<>(learned));
|
||||
writeAtomically(dir.resolve(CERT_NAME), issued.certificatePem());
|
||||
writeAtomically(dir.resolve(METADATA_NAME), OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(metadata));
|
||||
@@ -302,9 +302,4 @@ public class TlsCertificateManager implements Resettable {
|
||||
Files.deleteIfExists(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
private static String resolveFlociVersion() {
|
||||
String env = System.getenv("FLOCI_VERSION");
|
||||
return env == null || env.isBlank() ? "dev" : env;
|
||||
}
|
||||
}
|
||||
@@ -533,7 +533,7 @@ public class TlsConfigSource implements ConfigSource {
|
||||
private void persistMetadata(Path tlsDir, List<String> hostnames, List<String> learnedHostnames) {
|
||||
Path metadataFile = tlsDir.resolve(SERVER_METADATA_NAME);
|
||||
try {
|
||||
String version = resolveFlociVersion();
|
||||
String version = FlociVersion.current();
|
||||
CertificateMetadata metadata = CertificateMetadata.create(hostnames, version);
|
||||
metadata.setLearnedHostnames(learnedHostnames);
|
||||
|
||||
@@ -547,19 +547,6 @@ public class TlsConfigSource implements ConfigSource {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the Floci version from environment variable or defaults to "dev".
|
||||
*
|
||||
* @return Floci version string
|
||||
*/
|
||||
private static String resolveFlociVersion() {
|
||||
String env = System.getenv("FLOCI_VERSION");
|
||||
if (env != null && !env.isBlank()) {
|
||||
return env;
|
||||
}
|
||||
return "dev";
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the hostname configuration has changed since the last certificate generation.
|
||||
* Loads the metadata file and compares the hostnames with the current configuration.
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.lifecycle;
|
||||
import io.github.hectorvent.floci.config.ContainerCaBundle;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.config.FlociCertificateAuthority;
|
||||
import io.github.hectorvent.floci.config.FlociVersion;
|
||||
import io.github.hectorvent.floci.core.common.ContainerTeardown;
|
||||
import io.github.hectorvent.floci.core.common.ContainerTeardowns;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
@@ -63,7 +64,7 @@ public class EmulatorInfoController {
|
||||
this.certificateAuthority = certificateAuthority;
|
||||
this.config = config;
|
||||
this.dynamoDbBackendSelector = dynamoDbBackendSelector;
|
||||
this.version = resolveVersion();
|
||||
this.version = FlociVersion.current();
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -207,12 +208,4 @@ public class EmulatorInfoController {
|
||||
throw failure;
|
||||
}
|
||||
}
|
||||
|
||||
static String resolveVersion() {
|
||||
String env = System.getenv("FLOCI_VERSION");
|
||||
if (env != null && !env.isBlank()) {
|
||||
return env;
|
||||
}
|
||||
return "dev";
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.lifecycle;
|
||||
|
||||
import io.github.hectorvent.floci.config.FlociVersion;
|
||||
import io.github.hectorvent.floci.core.common.ServiceRegistry;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.GET;
|
||||
@@ -20,7 +21,7 @@ public class HealthController {
|
||||
@Inject
|
||||
public HealthController(ServiceRegistry serviceRegistry) {
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.version = resolveVersion();
|
||||
this.version = FlociVersion.current();
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -31,12 +32,4 @@ public class HealthController {
|
||||
"original_edition", "floci-always-free",
|
||||
"version", version)).build();
|
||||
}
|
||||
|
||||
static String resolveVersion() {
|
||||
String env = System.getenv("FLOCI_VERSION");
|
||||
if (env != null && !env.isBlank()) {
|
||||
return env;
|
||||
}
|
||||
return "dev";
|
||||
}
|
||||
}
|
||||
+2
-6
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.rds.proxy;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.config.CertificateMetadata;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.config.FlociVersion;
|
||||
import io.github.hectorvent.floci.core.common.Pem;
|
||||
import io.github.hectorvent.floci.services.acm.CertificateGenerator;
|
||||
import io.github.hectorvent.floci.services.acm.model.KeyAlgorithm;
|
||||
@@ -225,13 +226,8 @@ public class RdsProxyTlsCertificates {
|
||||
}
|
||||
|
||||
private void writeMetadata(Path metadataFile, List<String> sans) throws IOException {
|
||||
CertificateMetadata metadata = CertificateMetadata.create(sans, resolveFlociVersion());
|
||||
CertificateMetadata metadata = CertificateMetadata.create(sans, FlociVersion.current());
|
||||
String json = OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(metadata);
|
||||
Files.writeString(metadataFile, json);
|
||||
}
|
||||
|
||||
private static String resolveFlociVersion() {
|
||||
String env = System.getenv("FLOCI_VERSION");
|
||||
return (env != null && !env.isBlank()) ? env : "dev";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
version=${project.version}
|
||||
@@ -76,6 +76,7 @@ quarkus:
|
||||
- cloudformation/*.json
|
||||
- redshift/*.sql
|
||||
- i18n/*.properties
|
||||
- floci/version.properties
|
||||
- org/apache/velocity/runtime/defaults/*.properties
|
||||
# DriverManager finds the JDBC drivers through ServiceLoader, and the MySQL
|
||||
# driver reads its time zone table at connect time.
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package io.github.hectorvent.floci.config;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.matchesPattern;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
class FlociVersionTest {
|
||||
|
||||
@Test
|
||||
void overrideWinsOverBuildVersion() {
|
||||
assertThat(FlociVersion.resolve("nightly-10152026", "2.3.0"), equalTo("nightly-10152026"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void blankOverrideFallsBackToBuildVersion() {
|
||||
assertThat(FlociVersion.resolve(" ", "2.3.0"), equalTo("2.3.0"));
|
||||
assertThat(FlociVersion.resolve(null, "2.3.0"), equalTo("2.3.0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void devOnlyWhenNoVersionIsKnown() {
|
||||
assertThat(FlociVersion.resolve(null, null), equalTo("dev"));
|
||||
assertThat(FlociVersion.resolve("", " "), equalTo("dev"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildStampsTheProjectVersion() {
|
||||
// Only meaningful when FLOCI_VERSION is unset, which is how the suite runs.
|
||||
String version = FlociVersion.current();
|
||||
assertThat(version, not(equalTo("dev")));
|
||||
assertThat(version, matchesPattern("\\d+\\.\\d+\\.\\d+.*"));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -179,8 +179,8 @@ class TlsConfigSourceMetadataPersistenceTest {
|
||||
|
||||
assertNotNull(metadata.getFlociVersion(),
|
||||
"Metadata should contain flociVersion");
|
||||
assertEquals("dev", metadata.getFlociVersion(),
|
||||
"Version should default to 'dev' when FLOCI_VERSION not set");
|
||||
assertEquals(FlociVersion.current(), metadata.getFlociVersion(),
|
||||
"Metadata should record the version this build reports");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-2
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.lifecycle;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.config.FlociVersion;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
@@ -57,7 +58,7 @@ class EmulatorInfoControllerIntegrationTest {
|
||||
JsonNode tree = MAPPER.readTree(body);
|
||||
assertEquals("community", tree.get("edition").asText());
|
||||
assertEquals("floci-always-free", tree.get("original_edition").asText());
|
||||
assertEquals("dev", tree.get("version").asText());
|
||||
assertEquals(FlociVersion.current(), tree.get("version").asText());
|
||||
|
||||
JsonNode services = tree.get("services");
|
||||
assertNotNull(services, "services field must be present");
|
||||
@@ -94,7 +95,7 @@ class EmulatorInfoControllerIntegrationTest {
|
||||
.statusCode(200)
|
||||
.contentType("application/json")
|
||||
.body("edition", equalTo("community"))
|
||||
.body("version", notNullValue())
|
||||
.body("version", allOf(equalTo(FlociVersion.current()), not(equalTo("dev"))))
|
||||
.body("dynamodb_backend", equalTo("native"));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user