Skip to content

Commit

Permalink
Remove deprecated auto-build CLI option (keycloak#23361)
Browse files Browse the repository at this point in the history
  • Loading branch information
mabartos authored Sep 27, 2023
1 parent 6946677 commit c9d9301
Show file tree
Hide file tree
Showing 16 changed files with 17 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,11 @@ New code example:
When running on OpenShift, with ingress enabled, and with the spec.ingress.classname set to openshift-default, you may leave the spec.hostname.hostname unpopulated in the Keycloak CR.
The operator will assign a default hostname to the stored version of the CR similar to what would be created by an OpenShift Route without an explicit host - that is ingress-namespace.appsDomain
If the appsDomain changes, or should you need a different hostname for any reason, then update the Keycloak CR.

= The deprecated `auto-build` CLI option was removed

The `auto-build` CLI option has been marked as deprecated for a long time.
In this release, it was completely removed, and it is no longer supported.

When executing the `start` command, the server is automatically built based on the configuration.
In order to prevent this behavior, set the `--optimized` flag.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
import static org.keycloak.quarkus.runtime.Environment.isImportExportMode;
import static org.keycloak.quarkus.runtime.Environment.isTestLaunchMode;
import static org.keycloak.quarkus.runtime.cli.Picocli.parseAndRun;
import static org.keycloak.quarkus.runtime.cli.command.AbstractStartCommand.*;
import static org.keycloak.quarkus.runtime.cli.command.AbstractStartCommand.OPTIMIZED_BUILD_OPTION_LONG;
import static org.keycloak.quarkus.runtime.cli.command.Start.isDevProfileNotAllowed;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import jakarta.enterprise.context.ApplicationScoped;
Expand Down Expand Up @@ -74,7 +73,7 @@ public static void main(String[] args) {
ExecutionExceptionHandler errorHandler = new ExecutionExceptionHandler();
PrintWriter errStream = new PrintWriter(System.err, true);

if (isDevProfileNotAllowed(Arrays.asList(args))) {
if (isDevProfileNotAllowed()) {
errorHandler.error(errStream, Messages.devProfileNotAllowedError(Start.NAME), null);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import static java.util.stream.StreamSupport.stream;
import static org.keycloak.quarkus.runtime.Environment.isRebuildCheck;
import static org.keycloak.quarkus.runtime.Environment.isRebuilt;
import static org.keycloak.quarkus.runtime.cli.command.AbstractStartCommand.*;
import static org.keycloak.quarkus.runtime.cli.command.AbstractStartCommand.AUTO_BUILD_OPTION_LONG;
import static org.keycloak.quarkus.runtime.cli.command.AbstractStartCommand.OPTIMIZED_BUILD_OPTION_LONG;
import static org.keycloak.quarkus.runtime.configuration.ConfigArgsConfigSource.parseConfigArgs;
import static org.keycloak.quarkus.runtime.configuration.Configuration.OPTION_PART_SEPARATOR;
Expand Down Expand Up @@ -57,7 +55,6 @@
import org.keycloak.config.MultiOption;
import org.keycloak.config.OptionCategory;
import org.keycloak.quarkus.runtime.cli.command.AbstractCommand;
import org.keycloak.quarkus.runtime.cli.command.AbstractStartCommand;
import org.keycloak.quarkus.runtime.cli.command.Build;
import org.keycloak.quarkus.runtime.cli.command.ImportRealmMixin;
import org.keycloak.quarkus.runtime.cli.command.Main;
Expand Down Expand Up @@ -527,10 +524,6 @@ public static List<String> parseArgs(String[] rawArgs) {
}
}
}

if (!isRebuildCheck() && (arg.startsWith(AbstractStartCommand.AUTO_BUILD_OPTION_SHORT) || arg.startsWith(AUTO_BUILD_OPTION_LONG))) {
System.out.println(DEFAULT_WARN_MESSAGE_REPEATED_AUTO_BUILD_OPTION);
}
}

return args;
Expand All @@ -544,11 +537,6 @@ private static String replaceCommandWithBuild(String commandName, String arg) {
}

private static boolean isRuntimeOption(String arg) {
// remove this once auto-build option is removed
if (AUTO_BUILD_OPTION_LONG.equals(arg) || AUTO_BUILD_OPTION_SHORT.equals(arg)) {
return true;
}

return arg.startsWith(ImportRealmMixin.IMPORT_REALM);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@
import picocli.CommandLine;

public abstract class AbstractStartCommand extends AbstractCommand implements Runnable {

// remove this once auto-build is removed
public static final String AUTO_BUILD_OPTION_LONG = "--auto-build";
public static final String AUTO_BUILD_OPTION_SHORT = "-b";
public static final String OPTIMIZED_BUILD_OPTION_LONG = "--optimized";
public static final String DEFAULT_WARN_MESSAGE_REPEATED_AUTO_BUILD_OPTION = "WARNING: The '" + AUTO_BUILD_OPTION_LONG + "' option for 'start' command is DEPRECATED and no longer needed. When executing the '" + Start.NAME + "' command, a new server image is automatically built based on the configuration. If you want to disable this behavior and achieve an optimal startup time, use the '" + OPTIMIZED_BUILD_OPTION_LONG + "' option instead.";

@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.keycloak.quarkus.runtime.cli.command;

import static org.keycloak.quarkus.runtime.Environment.setProfile;
import static org.keycloak.quarkus.runtime.cli.Picocli.NO_PARAM_LABEL;
import static org.keycloak.quarkus.runtime.cli.command.AbstractStartCommand.OPTIMIZED_BUILD_OPTION_LONG;
import static org.keycloak.quarkus.runtime.configuration.Configuration.getRawPersistedProperty;

Expand All @@ -45,14 +44,6 @@ public final class Start extends AbstractStartCommand implements Runnable {

public static final String NAME = "start";

@CommandLine.Option(names = {AUTO_BUILD_OPTION_SHORT, AUTO_BUILD_OPTION_LONG},
description = "(Deprecated) Automatically detects whether the server configuration changed and a new server image must be built" +
" prior to starting the server. This option provides an alternative to manually running the '" + Build.NAME + "'" +
" prior to starting the server. Use this configuration carefully in production as it might impact the startup time.",
paramLabel = NO_PARAM_LABEL,
order = 1)
Boolean autoConfig;

@CommandLine.Mixin
OptimizedMixin optimizedMixin;

Expand All @@ -68,22 +59,18 @@ protected void doBeforeRun() {
}

private void devProfileNotAllowedError() {
if (isDevProfileNotAllowed(spec.commandLine().getParseResult().expandedArgs())) {
if (isDevProfileNotAllowed()) {
executionError(spec.commandLine(), Messages.devProfileNotAllowedError(NAME));
}
}

public static boolean isDevProfileNotAllowed(List<String> currentCliArgs) {
public static boolean isDevProfileNotAllowed() {
Optional<String> currentProfile = Optional.ofNullable(Environment.getProfile());
Optional<String> persistedProfile = getRawPersistedProperty("kc.profile");

setProfile(currentProfile.orElse(persistedProfile.orElse("prod")));

if (Environment.isDevProfile() && (!currentCliArgs.contains(AUTO_BUILD_OPTION_LONG) || !currentCliArgs.contains(AUTO_BUILD_OPTION_SHORT))) {
return true;
}

return false;
return Environment.isDevProfile();
}

public List<OptionCategory> getOptionCategories() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Mixin;
import picocli.CommandLine.Option;

import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -39,9 +38,6 @@ public final class StartDev extends AbstractStartCommand implements Runnable {

public static final String NAME = "start-dev";

@Option(names = AUTO_BUILD_OPTION_LONG, hidden = true)
Boolean autoConfig;

@Mixin
HelpAllMixin helpAllMixin;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import static java.util.Arrays.asList;
import static org.keycloak.quarkus.runtime.cli.Picocli.ARG_SHORT_PREFIX;
import static org.keycloak.quarkus.runtime.cli.command.AbstractStartCommand.AUTO_BUILD_OPTION_LONG;
import static org.keycloak.quarkus.runtime.cli.command.AbstractStartCommand.AUTO_BUILD_OPTION_SHORT;
import static org.keycloak.quarkus.runtime.configuration.Configuration.OPTION_PART_SEPARATOR_CHAR;
import static org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX;

Expand All @@ -35,6 +33,7 @@

import org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper;
import org.keycloak.quarkus.runtime.configuration.mappers.PropertyMappers;
import org.keycloak.utils.StringUtil;

/**
* <p>A configuration source for mapping configuration arguments to their corresponding properties so that they can be recognized
Expand Down Expand Up @@ -134,10 +133,10 @@ public void accept(String key, String value) {

public static void parseConfigArgs(BiConsumer<String, String> cliArgConsumer) {
// init here because the class might be loaded by CL without init
List<String> ignoredArgs = asList("--verbose", "-v", "--help", "-h", AUTO_BUILD_OPTION_LONG, AUTO_BUILD_OPTION_SHORT);
List<String> ignoredArgs = asList("--verbose", "-v", "--help", "-h");
String rawArgs = getRawConfigArgs();

if (rawArgs == null || "".equals(rawArgs.trim())) {
if (StringUtil.isBlank(rawArgs)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@
import org.keycloak.it.junit5.extension.DistributionTest;
import org.keycloak.it.junit5.extension.RawDistOnly;
import org.keycloak.it.utils.KeycloakDistribution;
import org.keycloak.quarkus.runtime.cli.command.AbstractStartCommand;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.keycloak.quarkus.runtime.cli.command.AbstractStartCommand.DEFAULT_WARN_MESSAGE_REPEATED_AUTO_BUILD_OPTION;
import static org.keycloak.quarkus.runtime.cli.command.AbstractStartCommand.OPTIMIZED_BUILD_OPTION_LONG;

@DistributionTest
Expand All @@ -40,7 +38,7 @@
public class StartAutoBuildDistTest {

@Test
@Launch({ "start", AbstractStartCommand.AUTO_BUILD_OPTION_LONG, "--http-enabled=true", "--hostname-strict=false" })
@Launch({ "start", "--http-enabled=true", "--hostname-strict=false" })
@Order(1)
void testStartAutoBuild(LaunchResult result) {
CLIResult cliResult = (CLIResult) result;
Expand All @@ -50,7 +48,6 @@ void testStartAutoBuild(LaunchResult result) {
cliResult.assertMessage(KeycloakDistribution.SCRIPT_CMD + " show-config");
cliResult.assertMessage("Next time you run the server, just run:");
cliResult.assertMessage(KeycloakDistribution.SCRIPT_CMD + " start " + OPTIMIZED_BUILD_OPTION_LONG + " --http-enabled=true --hostname-strict=false");
cliResult.assertMessage(DEFAULT_WARN_MESSAGE_REPEATED_AUTO_BUILD_OPTION);
assertFalse(cliResult.getOutput().contains("--cache"));
cliResult.assertStarted();
}
Expand Down Expand Up @@ -104,7 +101,6 @@ void testReAugWhenNoOptionAfterBuild(LaunchResult result) {
@Order(7)
void testShouldReAugWithoutAutoBuildOptionAfterDatabaseChange(LaunchResult result) {
CLIResult cliResult = (CLIResult) result;
cliResult.assertNoMessage(DEFAULT_WARN_MESSAGE_REPEATED_AUTO_BUILD_OPTION);
cliResult.assertBuild();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ Use this command to run the server in production.

Options:

-b, --auto-build (Deprecated) Automatically detects whether the server configuration changed
and a new server image must be built prior to starting the server. This
option provides an alternative to manually running the 'build' prior to
starting the server. Use this configuration carefully in production as it
might impact the startup time.
-h, --help This help message.
--help-all This same help message but with additional options.
--import-realm Import realms during startup by reading any realm configuration file from the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ Use this command to run the server in production.

Options:

-b, --auto-build (Deprecated) Automatically detects whether the server configuration changed
and a new server image must be built prior to starting the server. This
option provides an alternative to manually running the 'build' prior to
starting the server. Use this configuration carefully in production as it
might impact the startup time.
-h, --help This help message.
--help-all This same help message but with additional options.
--import-realm Import realms during startup by reading any realm configuration file from the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ Use this command to run the server in production.

Options:

-b, --auto-build (Deprecated) Automatically detects whether the server configuration changed
and a new server image must be built prior to starting the server. This
option provides an alternative to manually running the 'build' prior to
starting the server. Use this configuration carefully in production as it
might impact the startup time.
-h, --help This help message.
--help-all This same help message but with additional options.
--import-realm Import realms during startup by reading any realm configuration file from the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ Use this command to run the server in production.

Options:

-b, --auto-build (Deprecated) Automatically detects whether the server configuration changed
and a new server image must be built prior to starting the server. This
option provides an alternative to manually running the 'build' prior to
starting the server. Use this configuration carefully in production as it
might impact the startup time.
-h, --help This help message.
--help-all This same help message but with additional options.
--import-realm Import realms during startup by reading any realm configuration file from the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ Use this command to run the server in production.

Options:

-b, --auto-build (Deprecated) Automatically detects whether the server configuration changed
and a new server image must be built prior to starting the server. This
option provides an alternative to manually running the 'build' prior to
starting the server. Use this configuration carefully in production as it
might impact the startup time.
-h, --help This help message.
--help-all This same help message but with additional options.
--import-realm Import realms during startup by reading any realm configuration file from the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ Use this command to run the server in production.

Options:

-b, --auto-build (Deprecated) Automatically detects whether the server configuration changed
and a new server image must be built prior to starting the server. This
option provides an alternative to manually running the 'build' prior to
starting the server. Use this configuration carefully in production as it
might impact the startup time.
-h, --help This help message.
--help-all This same help message but with additional options.
--import-realm Import realms during startup by reading any realm configuration file from the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ Use this command to run the server in production.

Options:

-b, --auto-build (Deprecated) Automatically detects whether the server configuration changed
and a new server image must be built prior to starting the server. This
option provides an alternative to manually running the 'build' prior to
starting the server. Use this configuration carefully in production as it
might impact the startup time.
-h, --help This help message.
--help-all This same help message but with additional options.
--import-realm Import realms during startup by reading any realm configuration file from the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ Use this command to run the server in production.

Options:

-b, --auto-build (Deprecated) Automatically detects whether the server configuration changed
and a new server image must be built prior to starting the server. This
option provides an alternative to manually running the 'build' prior to
starting the server. Use this configuration carefully in production as it
might impact the startup time.
-h, --help This help message.
--help-all This same help message but with additional options.
--import-realm Import realms during startup by reading any realm configuration file from the
Expand Down

0 comments on commit c9d9301

Please sign in to comment.