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;
}
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));
}
Aggregations