Skip to content

Commit

Permalink
Improve s2i properties to use the standard ones
Browse files Browse the repository at this point in the history
The properties `ts.global.s2i.quarkus.jvm.builder.image` and `ts.global.s2i.quarkus.native.builder.image` properties have been deleted in favour of the Quarkus official ones:
- quarkus.s2i.base-jvm-image
- quarkus.s2i.base-native-image

Moreover, when using the OpenShift extension, if the user does not supply the `quarkus.openshift.base-xxx-image`, the framework will use the ones from `quarkus.s2i.base-xxx-image`.
  • Loading branch information
Sgitario committed Oct 15, 2021
1 parent b020088 commit 4b7c376
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 44 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,8 @@ public class OpenShiftPingPongResourceIT {
}
```
By default, the base native image to be used by this method is `quay.io/quarkus/ubi-quarkus-native-binary-s2i:1.0` and can be configured using the property `-Dts.global.quarkus.s2i.base-native-binary-image`.
The default template used by this strategy can be overwritten using the property `ts.global.openshift.template`.
- **OpenShift Extension**
Expand Down Expand Up @@ -1081,12 +1083,7 @@ public class OpenShiftS2iQuickstartIT {
//
```

This scenario will work for JVM and Native builds. In order to manage the base image in use, you need to provide the properties:
- For JVM: `ts.global.s2i.quarkus.jvm.builder.image`
- For Native: `ts.global.s2i.quarkus.native.builder.image`

The way these properties are up to users. In the examples, we supply this configuration in the pom.xml as part of system properties (in the Maven failsafe plugin).
But we can provide a custom property by service in the `test.properties` file. For further information about how to customise the properties, go to the [Configuration](#configuration) section.
This scenario will work for JVM and Native builds.

It's important to note that, by default, OpenShift will build the application's source code using the Red Hat maven repository `https://maven.repository.redhat.com/ga/`. However, some applications might require some dependencies from other remote Maven repositories. In order to allow us to add another remote Maven repository, you can use `-Dts.global.s2i.maven.remote.repository=http://host:port/repo/name`. If you only want to configure different maven repositories by service, you can do it by replacing `global` to the service name, for example: `-Dts.pingPong.s2i.maven.remote.repository=...`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import io.quarkus.test.scenarios.OpenShiftDeploymentStrategy;
import io.quarkus.test.scenarios.OpenShiftScenario;
import io.quarkus.test.scenarios.annotations.EnabledIfOpenShiftScenarioPropertyIsTrue;

@OpenShiftScenario(deployment = OpenShiftDeploymentStrategy.UsingContainerRegistry)
@EnabledIfOpenShiftScenarioPropertyIsTrue
public class OpenShiftUsingContainerRegistryPingPongResourceIT extends PingPongResourceIT {
}
13 changes: 0 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@
<checkstyle.version>9.0.1</checkstyle.version>
<!-- Code Coverage Properties-->
<jacoco.agent.argLine />
<!-- S2i configuration -->
<ts.global.s2i.quarkus.jvm.builder.image>registry.access.redhat.com/ubi8/openjdk-11:latest</ts.global.s2i.quarkus.jvm.builder.image>
<ts.global.s2i.quarkus.native.builder.image>quay.io/quarkus/ubi-quarkus-native-s2i:21.2-java11</ts.global.s2i.quarkus.native.builder.image>
</properties>
<distributionManagement>
<snapshotRepository>
Expand Down Expand Up @@ -213,16 +210,6 @@
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<configuration>
<systemProperties>
<ts.global.s2i.quarkus.jvm.builder.image>${ts.global.s2i.quarkus.jvm.builder.image}</ts.global.s2i.quarkus.jvm.builder.image>
<ts.global.s2i.quarkus.native.builder.image>${ts.global.s2i.quarkus.native.builder.image}</ts.global.s2i.quarkus.native.builder.image>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public final class QuarkusProperties {
public static final List<String> PACKAGE_TYPE_NATIVE_VALUES = Arrays.asList("native", "native-sources");
public static final List<String> PACKAGE_TYPE_LEGACY_JAR_VALUES = Arrays.asList("legacy-jar", "uber-jar", "mutable-jar");
public static final List<String> PACKAGE_TYPE_JVM_VALUES = Arrays.asList("fast-jar", "jar");
public static final PropertyLookup QUARKUS_JVM_S2I = new PropertyLookup("quarkus.s2i.base-jvm-image",
"registry.access.redhat.com/ubi8/openjdk-11:latest");
public static final PropertyLookup QUARKUS_NATIVE_S2I = new PropertyLookup("quarkus.s2i.base-native-image",
"quay.io/quarkus/ubi-quarkus-native-s2i:21.2-java11");

private QuarkusProperties() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.test.services.quarkus;

import static io.quarkus.test.services.quarkus.QuarkusApplicationManagedResourceBuilder.HTTP_PORT_DEFAULT;
import static io.quarkus.test.services.quarkus.model.QuarkusProperties.QUARKUS_JVM_S2I;
import static java.util.regex.Pattern.quote;
import static org.junit.jupiter.api.Assertions.fail;

Expand All @@ -15,14 +16,11 @@ public class BuildOpenShiftQuarkusApplicationManagedResource
private static final String S2I_DEFAULT_VERSION = "latest";

private static final String QUARKUS_OPENSHIFT_TEMPLATE = "/quarkus-build-openshift-template.yml";
private static final PropertyLookup QUARKUS_NATIVE_BINARY_S2I = new PropertyLookup(
"quarkus.s2i.base-native-binary-image", "quay.io/quarkus/ubi-quarkus-native-binary-s2i:1.0");

private static final String IMAGE_TAG_SEPARATOR = ":";

private static final PropertyLookup UBI_QUARKUS_JVM_S2I = new PropertyLookup("quarkus.s2i.base-jvm-image",
"registry.access.redhat.com/ubi8/openjdk-11:latest");
private static final PropertyLookup UBI_QUARKUS_NATIVE_S2I = new PropertyLookup("quarkus.s2i.base-native-image",
"quay.io/quarkus/ubi-quarkus-native-binary-s2i:1.0");

public BuildOpenShiftQuarkusApplicationManagedResource(ArtifactQuarkusApplicationManagedResourceBuilder model) {
super(model);
}
Expand Down Expand Up @@ -76,11 +74,8 @@ private String getS2iImageVersion(String s2iImage) {
}

private String getS2iImage() {
PropertyLookup s2iImageProperty = UBI_QUARKUS_JVM_S2I;
if (isNativeTest()) {
s2iImageProperty = UBI_QUARKUS_NATIVE_S2I;
}

return s2iImageProperty.get(model.getContext());
PropertyLookup s2iImageProperty = isNativeTest() ? QUARKUS_NATIVE_BINARY_S2I : QUARKUS_JVM_S2I;
return model.getContext().getOwner().getProperty(s2iImageProperty.getPropertyKey())
.orElseGet(() -> s2iImageProperty.get(model.getContext()));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.test.services.quarkus;

import static io.quarkus.test.services.quarkus.model.QuarkusProperties.QUARKUS_JVM_S2I;
import static io.quarkus.test.services.quarkus.model.QuarkusProperties.QUARKUS_NATIVE_S2I;
import static io.quarkus.test.utils.MavenUtils.BATCH_MODE;
import static io.quarkus.test.utils.MavenUtils.DISPLAY_VERSION;
import static io.quarkus.test.utils.MavenUtils.PACKAGE_GOAL;
Expand All @@ -21,6 +23,7 @@
import java.util.regex.Pattern;

import io.quarkus.test.bootstrap.inject.OpenShiftClient;
import io.quarkus.test.configuration.PropertyLookup;
import io.quarkus.test.utils.Command;
import io.quarkus.test.utils.FileUtils;
import io.quarkus.test.utils.PropertiesUtils;
Expand All @@ -38,6 +41,8 @@ public class ExtensionOpenShiftQuarkusApplicationManagedResource
private static final String QUARKUS_CONTAINER_IMAGE_GROUP = "quarkus.container-image.group";
private static final String QUARKUS_OPENSHIFT_ENV_VARS = "quarkus.openshift.env.vars.";
private static final String QUARKUS_OPENSHIFT_LABELS = "quarkus.openshift.labels.";
private static final String QUARKUS_OPENSHIFT_BASE_JAVA_IMAGE = "quarkus.openshift.base-jvm-image";
private static final String QUARKUS_OPENSHIFT_BASE_NATIVE_IMAGE = "quarkus.openshift.base-native-image";
private static final String QUARKUS_KNATIVE_ENV_VARS = "quarkus.knative.env.vars.";
private static final String QUARKUS_KNATIVE_LABELS = "quarkus.knative.labels.";
private static final String QUARKUS_KUBERNETES_DEPLOYMENT_TARGET = "quarkus.kubernetes.deployment-target";
Expand Down Expand Up @@ -108,7 +113,8 @@ private void deployProjectUsingMavenCommand() {
args.add(withContainerImageGroup(namespace));
args.add(withLabelsForWatching());
args.add(withLabelsForScenarioId());
withEnvVars(args, model.getContext().getOwner().getProperties());
withEnvVars(args);
withBaseImageProperties(args);
withAdditionalArguments(args);

try {
Expand All @@ -118,6 +124,23 @@ private void deployProjectUsingMavenCommand() {
}
}

private void withBaseImageProperties(List<String> args) {
// Resolve s2i property
boolean isNativeTest = isNativeTest();
PropertyLookup s2iImageProperty = isNativeTest ? QUARKUS_NATIVE_S2I : QUARKUS_JVM_S2I;
String baseImage = model.getContext().getOwner().getProperty(s2iImageProperty.getPropertyKey())
.orElseGet(() -> s2iImageProperty.get(model.getContext()));

// Set S2i property
args.add(withProperty(s2iImageProperty.getPropertyKey(), baseImage));

// If S2i is set and the openshift is not, we need to propagate it.
String openShiftImageProperty = isNativeTest ? QUARKUS_OPENSHIFT_BASE_NATIVE_IMAGE : QUARKUS_OPENSHIFT_BASE_JAVA_IMAGE;
if (model.getContext().getOwner().getProperty(openShiftImageProperty).isEmpty()) {
args.add(withProperty(openShiftImageProperty, baseImage));
}
}

private String withLabelsForWatching() {
return withLabels(OpenShiftClient.LABEL_TO_WATCH_FOR_LOGS, model.getContext().getOwner().getName());
}
Expand Down Expand Up @@ -151,7 +174,8 @@ private String withKubernetesClientTrustCerts() {
return withProperty(QUARKUS_KUBERNETES_CLIENT_TRUST_CERTS, Boolean.TRUE.toString());
}

private void withEnvVars(List<String> args, Map<String, String> envVars) {
private void withEnvVars(List<String> args) {
Map<String, String> envVars = model.getContext().getOwner().getProperties();
String property = QUARKUS_OPENSHIFT_ENV_VARS;
if (isKnativeDeployment()) {
property = QUARKUS_KNATIVE_ENV_VARS;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.quarkus.test.services.quarkus;

import static io.quarkus.test.services.quarkus.GitRepositoryQuarkusApplicationManagedResourceBuilder.QUARKUS_VERSION_PROPERTY;
import static io.quarkus.test.services.quarkus.model.QuarkusProperties.QUARKUS_JVM_S2I;
import static io.quarkus.test.services.quarkus.model.QuarkusProperties.QUARKUS_NATIVE_S2I;
import static java.util.regex.Pattern.quote;

import java.nio.file.Path;
Expand All @@ -19,10 +21,6 @@ public class OpenShiftS2iGitRepositoryQuarkusApplicationManagedResource
private static final String QUARKUS_SOURCE_S2I_BUILD_TEMPLATE_FILENAME = "/quarkus-s2i-source-build-template.yml";
private static final String QUARKUS_SOURCE_S2I_SETTINGS_MVN_FILENAME = "settings-mvn.yml";
private static final String INTERNAL_MAVEN_REPOSITORY_PROPERTY = "${internal.s2i.maven.remote.repository}";
private static final PropertyLookup QUARKUS_SOURCE_S2I_JVM_BUILDER_IMAGE = new PropertyLookup(
"s2i.quarkus.jvm.builder.image");
private static final PropertyLookup QUARKUS_SOURCE_S2I_NATIVE_BUILDER_IMAGE = new PropertyLookup(
"s2i.quarkus.native.builder.image");
private static final PropertyLookup MAVEN_REMOTE_REPOSITORY = new PropertyLookup("s2i.maven.remote.repository");

private final GitRepositoryQuarkusApplicationManagedResourceBuilder model;
Expand Down Expand Up @@ -89,12 +87,9 @@ protected String replaceDeploymentContent(String content) {
}

private String getQuarkusS2iBaseImage() {
PropertyLookup s2iBaseImage = QUARKUS_SOURCE_S2I_JVM_BUILDER_IMAGE;
if (isNativeTest()) {
s2iBaseImage = QUARKUS_SOURCE_S2I_NATIVE_BUILDER_IMAGE;
}

return s2iBaseImage.get(getContext());
PropertyLookup s2iImageProperty = isNativeTest() ? QUARKUS_NATIVE_S2I : QUARKUS_JVM_S2I;
return model.getContext().getOwner().getProperty(s2iImageProperty.getPropertyKey())
.orElseGet(() -> s2iImageProperty.get(model.getContext()));
}

private void createMavenSettings() {
Expand Down

0 comments on commit 4b7c376

Please sign in to comment.