use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class DockerFileUtilTest method testCreateSimpleDockerfileConfig.
@Test
public void testCreateSimpleDockerfileConfig() throws IOException {
// Given
File dockerFile = File.createTempFile("Dockerfile", "-test");
// When
ImageConfiguration imageConfiguration1 = DockerFileUtil.createSimpleDockerfileConfig(dockerFile, null);
ImageConfiguration imageConfiguration2 = DockerFileUtil.createSimpleDockerfileConfig(dockerFile, "someImage:0.0.1");
// Then
assertNotNull(imageConfiguration1);
assertEquals("%g/%a:%l", imageConfiguration1.getName());
assertEquals(dockerFile.getPath(), imageConfiguration1.getBuild().getDockerFileRaw());
assertNotNull(imageConfiguration2);
assertEquals("someImage:0.0.1", imageConfiguration2.getName());
assertEquals(dockerFile.getPath(), imageConfiguration2.getBuild().getDockerFileRaw());
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class DockerFileUtilTest method testAddSimpleDockerfileConfig.
@Test
public void testAddSimpleDockerfileConfig() throws IOException {
// Given
ImageConfiguration imageConfiguration = ImageConfiguration.builder().name("test-image").build();
File dockerFile = File.createTempFile("Dockerfile", "-test");
// When
ImageConfiguration result = DockerFileUtil.addSimpleDockerfileConfig(imageConfiguration, dockerFile);
// Then
assertNotNull(result.getBuild());
assertEquals(dockerFile.getPath(), result.getBuild().getDockerFileRaw());
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class WatchService method createCopyWatchTask.
private Runnable createCopyWatchTask(final ImageWatcher watcher, final JKubeConfiguration jKubeConfiguration) throws IOException {
final ImageConfiguration imageConfig = watcher.getImageConfiguration();
final AssemblyFiles files = archiveService.getAssemblyFiles(imageConfig, jKubeConfiguration);
return () -> {
List<AssemblyFileEntry> entries = files.getUpdatedEntriesAndRefresh();
if (!entries.isEmpty()) {
try {
log.info("%s: Assembly changed. Copying changed files to container...", imageConfig.getDescription());
File changedFilesArchive = archiveService.createChangedFilesArchive(entries, files.getAssemblyDirectory(), imageConfig.getName(), jKubeConfiguration);
copyFilesToContainer(changedFilesArchive, watcher);
callPostExec(watcher);
} catch (IOException | WatchException e) {
log.error("%s: Error when copying files to container %s: %s", imageConfig.getDescription(), watcher.getContainerId(), e.getMessage());
}
}
};
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class OpenShiftResourceTaskTest method runTask_resolvesGroupInImageNameToNamespaceSetViaConfiguration_whenNoNamespaceDetected.
@Test
public void runTask_resolvesGroupInImageNameToNamespaceSetViaConfiguration_whenNoNamespaceDetected() {
try (MockedStatic<KubernetesHelper> kubernetesHelper = Mockito.mockStatic(KubernetesHelper.class)) {
// Given
kubernetesHelper.when(KubernetesHelper::getDefaultNamespace).thenReturn("test-custom-namespace");
kubernetesHelper.when(() -> KubernetesHelper.getKind(any())).thenReturn("DeploymentConfig");
kubernetesHelper.when(() -> KubernetesHelper.getName((HasMetadata) any())).thenReturn("test-project");
ImageConfiguration imageConfiguration = ImageConfiguration.builder().name("%g/%a").build(BuildConfiguration.builder().from("test-base-image:latest").build()).build();
extension.images = Collections.singletonList(imageConfiguration);
OpenShiftResourceTask resourceTask = new OpenShiftResourceTask(OpenShiftExtension.class);
// When
resourceTask.runTask();
// Then
assertThat(resourceTask.resolvedImages).hasSize(1).singleElement().hasFieldOrPropertyWithValue("name", "test-custom-namespace/test-project");
}
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class OpenshiftBuildService method checkOrCreatePullSecret.
private boolean checkOrCreatePullSecret(OpenShiftClient client, KubernetesListBuilder builder, String pullSecretName, ImageConfiguration imageConfig) throws Exception {
BuildConfiguration buildConfig = imageConfig.getBuildConfiguration();
String fromImage;
if (buildConfig.isDockerFileMode()) {
fromImage = extractBaseFromDockerfile(jKubeConfiguration, buildConfig);
} else {
fromImage = extractBaseFromConfiguration(buildConfig);
}
String pullRegistry = EnvUtil.firstRegistryOf(new ImageName(fromImage).getRegistry(), jKubeConfiguration.getRegistryConfig().getRegistry(), jKubeConfiguration.getRegistryConfig().getRegistry());
if (pullRegistry != null) {
RegistryConfig registryConfig = jKubeConfiguration.getRegistryConfig();
final AuthConfig authConfig = new AuthConfigFactory(log).createAuthConfig(false, registryConfig.isSkipExtendedAuth(), registryConfig.getAuthConfig(), registryConfig.getSettings(), null, pullRegistry, registryConfig.getPasswordDecryptionMethod());
final Secret secret = Optional.ofNullable(pullSecretName).map(psn -> client.secrets().inNamespace(applicableOpenShiftNamespace).withName(psn).get()).orElse(null);
if (secret != null) {
log.info("Adding to Secret %s", pullSecretName);
return updateSecret(client, pullSecretName, secret.getData());
}
if (authConfig != null) {
JsonObject auths = new JsonObject();
JsonObject auth = new JsonObject();
JsonObject item = new JsonObject();
String authString = authConfig.getUsername() + ":" + authConfig.getPassword();
item.add("auth", new JsonPrimitive(Base64.encodeBase64String(authString.getBytes(StandardCharsets.UTF_8))));
auth.add(pullRegistry, item);
auths.add("auths", auth);
String credentials = Base64.encodeBase64String(auths.toString().getBytes(StandardCharsets.UTF_8));
Map<String, String> data = new HashMap<>();
data.put(".dockerconfigjson", credentials);
log.info("Creating Secret");
builder.addNewSecretItem().withNewMetadata().withName(pullSecretName).endMetadata().withData(data).withType("kubernetes.io/dockerconfigjson").endSecretItem();
return true;
}
}
return false;
}
Aggregations