Skip to content

Commit

Permalink
fix: images can be configured with properties
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Nuri <marc@marcnuri.com>
  • Loading branch information
manusa committed May 13, 2024
1 parent c8e5218 commit b62df78
Show file tree
Hide file tree
Showing 26 changed files with 952 additions and 1,557 deletions.
33 changes: 33 additions & 0 deletions gradle-plugin/it/src/it/image-from-properties/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2019 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at:
*
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
plugins {
id 'org.eclipse.jkube.kubernetes' version "${jKubeVersion}"
id 'java'
}

group = 'org.eclipse.jkube.integration.tests.gradle'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
mavenCentral()
}

kubernetes {
offline = true
images {
image {
}
}
}
22 changes: 22 additions & 0 deletions gradle-plugin/it/src/it/image-from-properties/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright (c) 2019 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at:
#
# https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#

jkube.build.strategy=jib
jkube.container-image.name=repository/image-from-properties:latest
jkube.container-image.from=quay.io/quay/busybox
jkube.container-image.env.JAVA_OPTIONS=-Xmx256m
jkube.container-image.labels.MAINTAINER=JKube testing team
jkube.container-image.assembly.targetDir='/deployments'
jkube.container-image.ports.1=8080
jkube.container-image.entrypoint=java -jar /app.jar
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2019 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at:
*
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.jkube.gradle.plugin.tests;

import org.gradle.testkit.runner.BuildResult;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

class ImageFromPropertiesIT {
@RegisterExtension
private final ITGradleRunnerExtension gradleRunner = new ITGradleRunnerExtension();

@Test
void k8sBuild_generatesConfiguredImage() throws IOException {
// When
final BuildResult result = gradleRunner.withITProject("image-from-properties")
.withArguments("clean", "build", "k8sBuild", "--stacktrace")
.build();
// Then
final File dockerFile = gradleRunner.resolveFile("build", "docker", "repository", "image-from-properties", "latest", "build", "Dockerfile");
assertThat(new String(Files.readAllBytes(dockerFile.toPath())))
.contains("FROM quay.io/quay/busybox")
.contains("ENV JAVA_OPTIONS=-Xmx256m")
.contains("LABEL MAINTAINER=\"JKube testing team\"")
.contains("EXPOSE 8080")
.contains("COPY /jkube-generated-layer-final-artifact/maven /maven/")
.contains("ENTRYPOINT java -jar /app.jar");
assertThat(result).extracting(BuildResult::getOutput).asString()
.contains("Building container image in Kubernetes mode")
.contains("JIB image build started");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.contains;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -86,7 +87,7 @@ void run_withImageConfiguration_shouldPushImage() throws JKubeServiceException {
// Then
assertThat(dockerBuildServiceMockedConstruction.constructed()).hasSize(1);
verify(dockerBuildServiceMockedConstruction.constructed().iterator().next(), times(1))
.push(eq(extension.images), eq(0), any(), eq(false));
.push(argThat(images -> images.iterator().next().getName().equals("foo/bar:latest")), eq(0), any(), eq(false));
}


Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.jkube.kit.build.api.config.handler.property;
package org.eclipse.jkube.kit.build.api.config.property;


/**
Expand All @@ -29,34 +29,19 @@ public enum ConfigKey {
ASSEMBLY_USER("assembly.user"),
ASSEMBLY_MODE("assembly.mode"),
ASSEMBLY_TARLONGFILEMODE("assembly.tarLongFileMode"),
AUTO_REMOVE,
BIND,
BUILD_OPTIONS,
CAP_ADD,
CAP_DROP,
CLEANUP,
CONTAINER_NAME_PATTERN,
CPUSHARES,
CPUS,
CPUSET,
NOCACHE,
CACHEFROM,
OPTIMISE,
CMD,
CONTEXT_DIR,
DEPENDS_ON,
DOMAINNAME,
DNS,
DNS_SEARCH,
DOCKER_ARCHIVE,
DOCKER_FILE,
ENTRYPOINT,
ENV,
ENV_PROPERTY_FILE,
ENV_BUILD("envBuild", ValueCombinePolicy.Merge),
ENV_RUN("envRun", ValueCombinePolicy.Merge),
EXPOSED_PROPERTY_KEY,
EXTRA_HOSTS,
FILTER,
FROM,
FROM_EXT,
Expand All @@ -67,67 +52,23 @@ public enum ConfigKey {
HEALTHCHECK_START_PERIOD("healthcheck.startPeriod"),
HEALTHCHECK_RETRIES("healthcheck.retries"),
HEALTHCHECK_CMD("healthcheck.cmd"),
HOSTNAME,
IMAGE_PULL_POLICY_BUILD("imagePullPolicy.build"),
IMAGE_PULL_POLICY_RUN("imagePullPolicy.run"),
IMAGE_PULL_POLICY,
LABELS(ValueCombinePolicy.Merge),
LINKS,
LOG_ENABLED("log.enabled"),
LOG_PREFIX("log.prefix"),
LOG_DATE("log.date"),
LOG_FILE("log.file"),
LOG_COLOR("log.color"),
LOG_DRIVER_NAME("log.driver.name"),
LOG_DRIVER_OPTS("log.driver.opts"),
MAINTAINER,
MEMORY,
MEMORY_SWAP,
NAME,
NET,
NETWORK_MODE("network.mode"),
NETWORK_NAME("network.name"),
NETWORK_ALIAS("network.alias"),
PORT_PROPERTY_FILE,
PORTS(ValueCombinePolicy.Merge),
PRIVILEGED,
READ_ONLY,
REGISTRY,
RESTART_POLICY_NAME("restartPolicy.name"),
RESTART_POLICY_RETRY("restartPolicy.retry"),
SHELL,
RUN,
SECURITY_OPTS,
SHMSIZE,
SKIP_BUILD("skip.build"),
SKIP_RUN("skip.run"),
SKIP,
TAGS(ValueCombinePolicy.Merge),
TMPFS,
ULIMITS,
USER,
VOLUMES,
VOLUMES_FROM,
WAIT_LOG("wait.log"),
WAIT_TIME("wait.time"),
WAIT_HEALTHY("wait.healthy"),
WAIT_URL("wait.url"),
WAIT_HTTP_URL("wait.http.url"),
WAIT_HTTP_METHOD("wait.http.method"),
WAIT_HTTP_STATUS("wait.http.status"),
WAIT_KILL("wait.kill"),
WAIT_EXEC_POST_START("wait.exec.postStart"),
WAIT_EXEC_PRE_STOP("wait.exec.preStop"),
WAIT_EXEC_BREAK_ON_ERROR("wait.exec.breakOnError"),
WAIT_EXIT("wait.exit"),
WAIT_SHUTDOWN("wait.shutdown"),
WAIT_TCP_MODE("wait.tcp.mode"),
WAIT_TCP_HOST("wait.tcp.host"),
WAIT_TCP_PORT("wait.tcp.port"),
WATCH_INTERVAL("watch.interval"),
WATCH_MODE("watch.mode"),
WATCH_POSTGOAL("watch.postGoal"),
WATCH_POSTEXEC("watch.postExec"),
WORKDIR,
WORKING_DIR;
WORKDIR;

ConfigKey() {
this(ValueCombinePolicy.Replace);
Expand Down
Loading

0 comments on commit b62df78

Please sign in to comment.