Search in sources :

Example 6 with KubernetesDataHolder

use of org.ballerinax.kubernetes.models.KubernetesDataHolder 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 7 with KubernetesDataHolder

use of org.ballerinax.kubernetes.models.KubernetesDataHolder in project kubernetes by ballerinax.

the class KubernetesUtils method writeToFile.

/**
 * Write content to a File. Create the required directories if they don't not exists.
 *
 * @param outputDir  Artifact output path.
 * @param context    Context of the file
 * @param fileSuffix Suffix for artifact.
 * @throws IOException If an error occurs when writing to a file
 */
public static void writeToFile(Path outputDir, String context, String fileSuffix) throws IOException {
    KubernetesDataHolder dataHolder = KubernetesContext.getInstance().getDataHolder();
    Path artifactFileName = outputDir.resolve(extractJarName(dataHolder.getUberJarPath()) + fileSuffix);
    DeploymentModel deploymentModel = dataHolder.getDeploymentModel();
    JobModel jobModel = dataHolder.getJobModel();
    // Priority given for job, then deployment.
    if (jobModel != null && jobModel.isSingleYAML()) {
        artifactFileName = outputDir.resolve(extractJarName(dataHolder.getUberJarPath()) + YAML);
    } else if (jobModel == null && deploymentModel != null && deploymentModel.isSingleYAML()) {
        artifactFileName = outputDir.resolve(extractJarName(dataHolder.getUberJarPath()) + YAML);
    }
    File newFile = artifactFileName.toFile();
    // append if file exists
    if (newFile.exists()) {
        Files.write(artifactFileName, context.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
        return;
    }
    // create required directories
    if (newFile.getParentFile().mkdirs()) {
        Files.write(artifactFileName, context.getBytes(StandardCharsets.UTF_8));
        return;
    }
    Files.write(artifactFileName, context.getBytes(StandardCharsets.UTF_8));
}
Also used : Path(java.nio.file.Path) DeploymentModel(org.ballerinax.kubernetes.models.DeploymentModel) KubernetesDataHolder(org.ballerinax.kubernetes.models.KubernetesDataHolder) JobModel(org.ballerinax.kubernetes.models.JobModel) File(java.io.File)

Aggregations

KubernetesDataHolder (org.ballerinax.kubernetes.models.KubernetesDataHolder)7 DockerModel (org.ballerinax.docker.generator.models.DockerModel)3 File (java.io.File)2 Path (java.nio.file.Path)2 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)2 KubernetesContext (org.ballerinax.kubernetes.models.KubernetesContext)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 JarResolver (org.ballerinalang.compiler.JarResolver)1 PackageID (org.ballerinalang.model.elements.PackageID)1 DeploymentModel (org.ballerinax.kubernetes.models.DeploymentModel)1 JobModel (org.ballerinax.kubernetes.models.JobModel)1 DependencyValidator (org.ballerinax.kubernetes.utils.DependencyValidator)1 Test (org.testng.annotations.Test)1