use of io.fabric8.crd.generator.visitor in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildService method checkOrCreatePullSecret.
private Boolean checkOrCreatePullSecret(BuildServiceConfig config, OpenShiftClient client, KubernetesListBuilder builder, String pullSecretName, ImageConfiguration imageConfig) throws MojoExecutionException, UnsupportedEncodingException {
io.fabric8.maven.docker.service.BuildService.BuildContext dockerBuildContext = config.getDockerBuildContext();
BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
String fromImage;
if (buildConfig.isDockerFileMode()) {
fromImage = extractBaseFromDockerfile(buildConfig, dockerBuildContext);
} else {
fromImage = extractBaseFromConfiguration(buildConfig);
}
String pullRegistry = EnvUtil.firstRegistryOf(new ImageName(fromImage).getRegistry(), dockerBuildContext.getRegistryConfig().getRegistry(), dockerBuildContext.getRegistryConfig().getRegistry());
if (pullRegistry != null) {
RegistryService.RegistryConfig registryConfig = dockerBuildContext.getRegistryConfig();
AuthConfig authConfig = registryConfig.getAuthConfigFactory().createAuthConfig(false, registryConfig.isSkipExtendedAuth(), registryConfig.getAuthConfig(), registryConfig.getSettings(), null, pullRegistry);
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("UTF-8"))));
auth.add(pullRegistry, item);
auths.add("auths", auth);
String credentials = Base64.encodeBase64String(auths.toString().getBytes("UTF-8"));
Map<String, String> data = new HashMap<>();
data.put(".dockerconfigjson", credentials);
boolean hasPullSecret = client.secrets().withName(pullSecretName).get() != null;
if (!hasPullSecret) {
log.info("Creating Secret %s", hasPullSecret);
builder.addNewSecretItem().withNewMetadata().withName(pullSecretName).endMetadata().withData(data).withType("kubernetes.io/dockerconfigjson").endSecretItem();
} else {
log.info("Adding to Secret %s", pullSecretName);
return updateSecret(client, pullSecretName, data);
}
return true;
} else {
return false;
}
}
return false;
}
use of io.fabric8.crd.generator.visitor in project fabric8-maven-plugin by fabric8io.
the class DeploymentConfigEnricher method convertFromExtensionsV1Beta1Deployment.
private DeploymentConfig convertFromExtensionsV1Beta1Deployment(HasMetadata item) {
io.fabric8.kubernetes.api.model.extensions.Deployment resource = (io.fabric8.kubernetes.api.model.extensions.Deployment) item;
DeploymentConfigBuilder builder = new DeploymentConfigBuilder();
builder.withMetadata(resource.getMetadata());
io.fabric8.kubernetes.api.model.extensions.DeploymentSpec spec = resource.getSpec();
if (spec != null) {
builder.withSpec(getDeploymentConfigSpec(spec.getReplicas(), spec.getRevisionHistoryLimit(), spec.getSelector(), spec.getTemplate(), spec.getStrategy() != null ? spec.getStrategy().getType() : null));
}
return builder.build();
}
use of io.fabric8.crd.generator.visitor in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildServiceTest method init.
@Before
public void init() throws Exception {
final File dockerFile = new File(baseDir, "Docker.tar");
dockerFile.getParentFile().mkdirs();
dockerFile.createNewFile();
imageStreamFile.delete();
new Expectations() {
{
dockerServiceHub.getArchiveService();
result = archiveService;
archiveService.createDockerBuildArchive(withAny(ImageConfiguration.class.cast(null)), withAny(MojoParameters.class.cast(null)));
result = dockerFile;
minTimes = 0;
project.getArtifact();
result = "myapp";
minTimes = 0;
dockerMojoParameters.getProject();
result = project;
minTimes = 0;
}
};
image = new ImageConfiguration.Builder().name(projectName).buildConfig(new BuildImageConfiguration.Builder().from(projectName).build()).build();
final io.fabric8.maven.docker.service.BuildService.BuildContext context = new io.fabric8.maven.docker.service.BuildService.BuildContext.Builder().registryConfig(new RegistryService.RegistryConfig.Builder().build()).build();
defaultConfig = new BuildService.BuildServiceConfig.Builder().buildDirectory(baseDir).buildRecreateMode(BuildRecreateMode.none).dockerBuildContext(context).s2iBuildNameSuffix("-s2i-suffix2").openshiftBuildStrategy(OpenShiftBuildStrategy.s2i).dockerMojoParameters(dockerMojoParameters);
defaultConfigSecret = new BuildService.BuildServiceConfig.Builder().buildDirectory(baseDir).buildRecreateMode(BuildRecreateMode.none).dockerBuildContext(context).s2iBuildNameSuffix("-s2i-suffix2").openshiftPullSecret("pullsecret-fabric8").openshiftBuildStrategy(OpenShiftBuildStrategy.s2i).dockerMojoParameters(dockerMojoParameters);
}
use of io.fabric8.crd.generator.visitor in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildServiceTest method testDockerBuild.
@Test
public void testDockerBuild() throws Exception {
retryInMockServer(() -> {
final io.fabric8.maven.docker.service.BuildService.BuildContext context = new io.fabric8.maven.docker.service.BuildService.BuildContext.Builder().registryConfig(new RegistryService.RegistryConfig.Builder().build()).build();
BuildService.BuildServiceConfig.Builder dockerConfig = new BuildService.BuildServiceConfig.Builder().buildDirectory(baseDir).dockerBuildContext(context).buildRecreateMode(BuildRecreateMode.none).s2iBuildNameSuffix("-docker").openshiftBuildStrategy(OpenShiftBuildStrategy.docker).dockerMojoParameters(dockerMojoParameters);
BuildService.BuildServiceConfig config = dockerConfig.build();
WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, true, 50, false, false);
OpenShiftMockServer mockServer = collector.getMockServer();
DefaultOpenShiftClient client = (DefaultOpenShiftClient) mockServer.createOpenShiftClient();
OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
service.build(image);
assertTrue(mockServer.getRequestCount() > 8);
collector.assertEventsRecordedInOrder("build-config-check", "new-build-config", "pushed");
assertEquals("{\"apiVersion\":\"build.openshift.io/v1\",\"kind\":\"BuildConfig\",\"metadata\":{\"name\":\"myapp-docker\"},\"spec\":{\"output\":{\"to\":{\"kind\":\"ImageStreamTag\",\"name\":\"myapp:latest\"}},\"source\":{\"type\":\"Binary\"},\"strategy\":{\"dockerStrategy\":{\"from\":{\"kind\":\"DockerImage\",\"name\":\"myapp\"}},\"type\":\"Docker\"}}}", collector.getBodies().get(1));
collector.assertEventsNotRecorded("patch-build-config");
});
}
use of io.fabric8.crd.generator.visitor in project fabric8-maven-plugin by fabric8io.
the class DockerBuildServiceTest method testSuccessfulBuild.
@Test
public void testSuccessfulBuild() throws Exception {
final BuildService.BuildContext context = new BuildService.BuildContext.Builder().build();
final io.fabric8.maven.core.service.BuildService.BuildServiceConfig config = new io.fabric8.maven.core.service.BuildService.BuildServiceConfig.Builder().dockerBuildContext(context).imagePullManager(new ImagePullManager(new TestCacheStore(), ImagePullPolicy.Always.name(), AutoPullMode.ALWAYS.name())).build();
final String imageName = "image-name";
final ImageConfiguration image = new ImageConfiguration.Builder().name(imageName).buildConfig(new BuildImageConfiguration.Builder().from("from").build()).build();
DockerBuildService service = new DockerBuildService(hub, config);
service.build(image);
new VerificationsInOrder() {
{
buildService.buildImage(image, config.getImagePullManager(), context);
buildService.tagImage(imageName, image);
}
};
}
Aggregations