Search in sources :

Example 1 with DockerModel

use of org.ballerinax.docker.generator.models.DockerModel in project kubernetes by ballerinax.

the class JobHandler method getDockerModel.

private DockerModel getDockerModel(JobModel jobModel) throws DockerGenException {
    final KubernetesDataHolder dataHolder = KubernetesContext.getInstance().getDataHolder();
    DockerModel dockerModel = dataHolder.getDockerModel();
    String dockerImage = jobModel.getImage();
    String imageTag = dockerImage.substring(dockerImage.lastIndexOf(":") + 1);
    dockerImage = dockerImage.substring(0, dockerImage.lastIndexOf(":"));
    dockerModel.setBaseImage(jobModel.getBaseImage());
    dockerModel.setRegistry(jobModel.getRegistry());
    dockerModel.setName(dockerImage);
    dockerModel.setTag(imageTag);
    dockerModel.setUsername(jobModel.getUsername());
    dockerModel.setPassword(jobModel.getPassword());
    dockerModel.setPush(jobModel.isPush());
    dockerModel.setCmd(jobModel.getCmd());
    dockerModel.setJarFileName(extractJarName(this.dataHolder.getUberJarPath()) + EXECUTABLE_JAR);
    dockerModel.setService(false);
    dockerModel.setDockerHost(jobModel.getDockerHost());
    dockerModel.setDockerCertPath(jobModel.getDockerCertPath());
    dockerModel.setBuildImage(jobModel.isBuildImage());
    dockerModel.setPkgId(dataHolder.getPackageID());
    dockerModel.setCopyFiles(jobModel.getCopyFiles());
    dockerModel.setUberJar(jobModel.isUberJar());
    dockerModel.setDockerConfig(jobModel.getDockerConfigPath());
    return dockerModel;
}
Also used : DockerModel(org.ballerinax.docker.generator.models.DockerModel) KubernetesDataHolder(org.ballerinax.kubernetes.models.KubernetesDataHolder)

Example 2 with DockerModel

use of org.ballerinax.docker.generator.models.DockerModel in project kubernetes by ballerinax.

the class HelmChartGeneratorTests method testHelmGenerate.

@Test
public void testHelmGenerate() throws KubernetesPluginException {
    DockerModel dockerModel = new DockerModel();
    Set<Integer> ports = new HashSet<>();
    ports.add(9090);
    ports.add(9091);
    ports.add(9092);
    dockerModel.setPorts(ports);
    dockerModel.setService(true);
    dockerModel.setJarFileName("hello.jar");
    dockerModel.setEnableDebug(true);
    dockerModel.setBaseImage(OPENJDK_11_JRE_SLIM_BASE);
    dockerModel.setDebugPort(5005);
    dockerModel.setBuildImage(false);
    KubernetesContext context = KubernetesContext.getInstance();
    KubernetesDataHolder dataHolder = context.getDataHolder();
    dataHolder.setDockerModel(dockerModel);
    new DockerHandler().createArtifacts();
    new HelmChartHandler().createArtifacts();
    File charYaml = dataHolder.getK8sArtifactOutputPath().resolve(module.name.toString()).resolve("hello-deployment").resolve("Chart.yaml").toFile();
    Assert.assertTrue(charYaml.exists());
    charYaml.deleteOnExit();
}
Also used : DockerModel(org.ballerinax.docker.generator.models.DockerModel) KubernetesDataHolder(org.ballerinax.kubernetes.models.KubernetesDataHolder) KubernetesContext(org.ballerinax.kubernetes.models.KubernetesContext) File(java.io.File) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 3 with DockerModel

use of org.ballerinax.docker.generator.models.DockerModel in project kubernetes by ballerinax.

the class KnativeServiceHandler method getDockerModel.

/**
 * Create docker artifacts.
 *
 * @param serviceModel Service model
 */
private DockerModel getDockerModel(ServiceModel serviceModel) throws DockerGenException {
    DockerModel dockerModel = knativeDataHolder.getDockerModel();
    String dockerImage = serviceModel.getImage();
    String imageTag = "latest";
    if (dockerImage.contains(":")) {
        imageTag = dockerImage.substring(dockerImage.lastIndexOf(":") + 1);
        dockerImage = dockerImage.substring(0, dockerImage.lastIndexOf(":"));
    }
    dockerModel.setBaseImage(serviceModel.getBaseImage());
    dockerModel.setRegistry(serviceModel.getRegistry());
    dockerModel.setName(dockerImage);
    dockerModel.setTag(imageTag);
    dockerModel.setEnableDebug(false);
    dockerModel.setUsername(serviceModel.getUsername());
    dockerModel.setPassword(serviceModel.getPassword());
    dockerModel.setPush(serviceModel.isPush());
    dockerModel.setJarFileName(extractJarName(knativeDataHolder.getUberJarPath()) + EXECUTABLE_JAR);
    dockerModel.setPorts(serviceModel.getPorts());
    dockerModel.setService(true);
    dockerModel.setDockerHost(serviceModel.getDockerHost());
    dockerModel.setDockerCertPath(serviceModel.getDockerCertPath());
    dockerModel.setBuildImage(serviceModel.isBuildImage());
    dockerModel.addCommandArg(serviceModel.getCommandArgs());
    dockerModel.setCopyFiles(serviceModel.getCopyFiles());
    return dockerModel;
}
Also used : DockerModel(org.ballerinax.docker.generator.models.DockerModel)

Example 4 with DockerModel

use of org.ballerinax.docker.generator.models.DockerModel in project kubernetes by ballerinax.

the class DeploymentHandler method getDockerModel.

/**
 * Create docker artifacts.
 *
 * @param deploymentModel Deployment model
 */
private DockerModel getDockerModel(DeploymentModel deploymentModel) throws DockerGenException {
    final KubernetesDataHolder dataHolder = KubernetesContext.getInstance().getDataHolder();
    DockerModel dockerModel = dataHolder.getDockerModel();
    String dockerImage = deploymentModel.getImage();
    String imageTag = "latest";
    if (dockerImage.contains(":")) {
        imageTag = dockerImage.substring(dockerImage.lastIndexOf(":") + 1);
        dockerImage = dockerImage.substring(0, dockerImage.lastIndexOf(":"));
    }
    dockerModel.setPkgId(dataHolder.getPackageID());
    dockerModel.setBaseImage(deploymentModel.getBaseImage());
    dockerModel.setRegistry(deploymentModel.getRegistry());
    dockerModel.setName(dockerImage);
    dockerModel.setTag(imageTag);
    dockerModel.setEnableDebug(false);
    dockerModel.setUsername(deploymentModel.getUsername());
    dockerModel.setPassword(deploymentModel.getPassword());
    dockerModel.setPush(deploymentModel.isPush());
    if (isBlank(deploymentModel.getCmd()) && deploymentModel.isPrometheus()) {
        // Add cmd to Dockerfile if prometheus is enabled.
        deploymentModel.setCmd(KubernetesConstants.PROMETHEUS_CMD + deploymentModel.getPrometheusPort());
    }
    dockerModel.setDockerConfig(deploymentModel.getDockerConfigPath());
    dockerModel.setCmd(deploymentModel.getCmd());
    dockerModel.setJarFileName(extractJarName(this.dataHolder.getUberJarPath()) + EXECUTABLE_JAR);
    dockerModel.setPorts(deploymentModel.getPorts());
    dockerModel.setUberJar(deploymentModel.isUberJar());
    dockerModel.setService(true);
    dockerModel.setDockerHost(deploymentModel.getDockerHost());
    dockerModel.setDockerCertPath(deploymentModel.getDockerCertPath());
    dockerModel.setBuildImage(deploymentModel.isBuildImage());
    dockerModel.addCommandArg(deploymentModel.getCommandArgs());
    dockerModel.setCopyFiles(deploymentModel.getCopyFiles());
    return dockerModel;
}
Also used : DockerModel(org.ballerinax.docker.generator.models.DockerModel) KubernetesDataHolder(org.ballerinax.kubernetes.models.KubernetesDataHolder)

Example 5 with DockerModel

use of org.ballerinax.docker.generator.models.DockerModel in project kubernetes by ballerinax.

the class DockerGeneratorTests method testDockerGenerate.

@Test
public void testDockerGenerate() throws KubernetesPluginException {
    DockerModel dockerModel = new DockerModel();
    Set<Integer> ports = new HashSet<>();
    ports.add(9090);
    ports.add(9091);
    ports.add(9092);
    dockerModel.setPorts(ports);
    dockerModel.setUberJar(true);
    dockerModel.setService(true);
    dockerModel.setJarFileName("hello.jar");
    dockerModel.setEnableDebug(true);
    dockerModel.setBaseImage("ballerina/ballerina-runtime" + ":latest");
    dockerModel.setDebugPort(5005);
    dockerModel.setBuildImage(false);
    dataHolder.setDockerModel(dockerModel);
    new DockerHandler().createArtifacts();
    File dockerfile = dataHolder.getDockerArtifactOutputPath().resolve("Dockerfile").toFile();
    Assert.assertTrue(dockerfile.exists());
    dockerfile.deleteOnExit();
}
Also used : DockerModel(org.ballerinax.docker.generator.models.DockerModel) File(java.io.File) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

DockerModel (org.ballerinax.docker.generator.models.DockerModel)5 KubernetesDataHolder (org.ballerinax.kubernetes.models.KubernetesDataHolder)3 File (java.io.File)2 HashSet (java.util.HashSet)2 Test (org.testng.annotations.Test)2 KubernetesContext (org.ballerinax.kubernetes.models.KubernetesContext)1