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 9a4de07
Show file tree
Hide file tree
Showing 27 changed files with 955 additions and 1,559 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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mockConstruction;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -71,7 +72,7 @@ void run_withImageConfigurationAndS2IBuildStrategy_shouldPushImage() throws JKub
// Then
assertThat(openshiftBuildServiceMockedConstruction.constructed()).hasSize(1);
verify(openshiftBuildServiceMockedConstruction.constructed().iterator().next())
.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));
}

@Test
Expand Down
Loading

0 comments on commit 9a4de07

Please sign in to comment.