use of org.jreleaser.model.Docker in project jreleaser by jreleaser.
the class DockerValidator method validateDocker.
public static void validateDocker(JReleaserContext context, Distribution distribution, Docker packager, Errors errors) {
JReleaserModel model = context.getModel();
Project project = model.getProject();
Docker parentPackager = model.getPackagers().getDocker();
if (!packager.isActiveSet() && parentPackager.isActiveSet()) {
packager.setActive(parentPackager.getActive());
}
if (!packager.resolveEnabled(context.getModel().getProject(), distribution))
return;
String element = "distribution." + distribution.getName() + ".docker";
context.getLogger().debug(element);
List<Artifact> candidateArtifacts = packager.resolveCandidateArtifacts(context, distribution);
if (candidateArtifacts.size() == 0) {
packager.setActive(Active.NEVER);
packager.disable();
return;
}
// check specs for active status
for (DockerSpec spec : packager.getSpecs().values()) {
if (!spec.isActiveSet() && packager.isActiveSet()) {
spec.setActive(packager.getActive());
}
spec.resolveEnabled(context.getModel().getProject(), distribution);
}
validateTemplate(context, distribution, packager, parentPackager, errors);
validateCommitAuthor(packager, parentPackager);
Docker.DockerRepository repository = packager.getRepository();
repository.resolveEnabled(model.getProject());
if (!repository.isVersionedSubfoldersSet()) {
repository.setVersionedSubfolders(parentPackager.getRepository().isVersionedSubfolders());
}
if (isBlank(repository.getName())) {
repository.setName(project.getName() + "-docker");
}
validateTap(context, distribution, repository, parentPackager.getRepository(), "docker.repository");
mergeExtraProperties(packager, parentPackager);
validateContinueOnError(packager, parentPackager);
if (isBlank(packager.getDownloadUrl())) {
packager.setDownloadUrl(parentPackager.getDownloadUrl());
}
if (isBlank(packager.getBaseImage())) {
packager.setBaseImage(parentPackager.getBaseImage());
}
validateBaseImage(distribution, packager);
if (packager.getImageNames().isEmpty()) {
packager.setImageNames(parentPackager.getImageNames());
}
if (packager.getImageNames().isEmpty()) {
packager.addImageName("{{repoOwner}}/{{distributionName}}:{{tagName}}");
}
if (context.getModel().getProject().isSnapshot()) {
// find the 1st image that ends with :{{tagName}}
Optional<String> imageName = packager.getImageNames().stream().filter(n -> n.endsWith(":{{tagName}}") || n.endsWith(":{{ tagName }}")).findFirst();
packager.setImageNames(singleton(imageName.orElse("{{repoOwner}}/{{distributionName}}:{{tagName}}")));
}
validateCommands(packager, parentPackager);
Map<String, String> labels = new LinkedHashMap<>();
labels.putAll(parentPackager.getLabels());
labels.putAll(packager.getLabels());
packager.setLabels(labels);
if (!packager.getLabels().containsKey(LABEL_OCI_IMAGE_TITLE)) {
packager.getLabels().put(LABEL_OCI_IMAGE_TITLE, "{{distributionName}}");
}
validateLabels(packager);
validateArtifactPlatforms(context, distribution, packager, candidateArtifacts, errors);
validateRegistries(context, packager, parentPackager, errors, element);
if (!packager.isUseLocalArtifactSet() && parentPackager.isUseLocalArtifactSet()) {
packager.setUseLocalArtifact(parentPackager.isUseLocalArtifact());
}
if (distribution.getType() == Distribution.DistributionType.SINGLE_JAR) {
packager.setUseLocalArtifact(true);
}
for (Map.Entry<String, DockerSpec> e : packager.getSpecs().entrySet()) {
DockerSpec spec = e.getValue();
if (isBlank(spec.getName())) {
spec.setName(e.getKey());
}
validateDockerSpec(context, distribution, spec, packager, errors);
}
}
use of org.jreleaser.model.Docker in project jreleaser by jreleaser.
the class DockerValidator method isAlpineCompatible.
private static boolean isAlpineCompatible(Distribution distribution, DockerConfiguration docker) {
List<Artifact> artifacts = distribution.getArtifacts().stream().filter(artifact -> artifact.getPath().endsWith(".zip")).collect(Collectors.toList());
if (docker instanceof DockerSpec) {
DockerSpec spec = (DockerSpec) docker;
Optional<Artifact> artifact = artifacts.stream().filter(spec::matches).findFirst();
if (artifact.isPresent()) {
spec.setArtifact(artifact.get());
return PlatformUtils.isAlpineLinux(artifact.get().getPlatform());
}
return false;
}
return artifacts.stream().anyMatch(artifact -> PlatformUtils.isAlpineLinux(artifact.getPlatform()));
}
Aggregations