Search in sources :

Example 1 with DockerSpec

use of org.jreleaser.model.DockerSpec 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);
    }
}
Also used : Artifact(org.jreleaser.model.Artifact) DockerSpec(org.jreleaser.model.DockerSpec) DockerConfiguration(org.jreleaser.model.DockerConfiguration) LABEL_OCI_IMAGE_TITLE(org.jreleaser.model.Docker.LABEL_OCI_IMAGE_TITLE) StringUtils.isBlank(org.jreleaser.util.StringUtils.isBlank) JReleaserModel(org.jreleaser.model.JReleaserModel) LinkedHashMap(java.util.LinkedHashMap) Active(org.jreleaser.model.Active) Errors(org.jreleaser.util.Errors) Collections.singleton(java.util.Collections.singleton) LABEL_OCI_IMAGE_DESCRIPTION(org.jreleaser.model.Docker.LABEL_OCI_IMAGE_DESCRIPTION) Map(java.util.Map) JReleaserContext(org.jreleaser.model.JReleaserContext) Env(org.jreleaser.util.Env) DistributionsValidator.validateArtifactPlatforms(org.jreleaser.model.validation.DistributionsValidator.validateArtifactPlatforms) TemplateValidator.validateTemplate(org.jreleaser.model.validation.TemplateValidator.validateTemplate) Distribution(org.jreleaser.model.Distribution) LinkedHashSet(java.util.LinkedHashSet) LABEL_OCI_IMAGE_URL(org.jreleaser.model.Docker.LABEL_OCI_IMAGE_URL) LABEL_OCI_IMAGE_REVISION(org.jreleaser.model.Docker.LABEL_OCI_IMAGE_REVISION) LABEL_OCI_IMAGE_VERSION(org.jreleaser.model.Docker.LABEL_OCI_IMAGE_VERSION) Set(java.util.Set) PlatformUtils(org.jreleaser.util.PlatformUtils) Collectors(java.util.stream.Collectors) ExtraPropertiesValidator.mergeExtraProperties(org.jreleaser.model.validation.ExtraPropertiesValidator.mergeExtraProperties) Project(org.jreleaser.model.Project) List(java.util.List) Registry(org.jreleaser.model.Registry) LABEL_OCI_IMAGE_LICENSES(org.jreleaser.model.Docker.LABEL_OCI_IMAGE_LICENSES) Docker(org.jreleaser.model.Docker) Optional(java.util.Optional) GitService(org.jreleaser.model.GitService) RB(org.jreleaser.bundle.RB) Artifact(org.jreleaser.model.Artifact) LinkedHashMap(java.util.LinkedHashMap) Project(org.jreleaser.model.Project) Docker(org.jreleaser.model.Docker) JReleaserModel(org.jreleaser.model.JReleaserModel) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DockerSpec(org.jreleaser.model.DockerSpec)

Example 2 with DockerSpec

use of org.jreleaser.model.DockerSpec in project jreleaser by jreleaser.

the class DockerPackagerProcessor method doPrepareDistribution.

@Override
protected void doPrepareDistribution(Distribution distribution, Map<String, Object> props, String distributionName, Path prepareDirectory, String templateDirectory, String packagerName, boolean copyLicense) throws IOException, PackagerProcessingException {
    if (packager.getActiveSpecs().isEmpty()) {
        super.doPrepareDistribution(distribution, props, distributionName, prepareDirectory, templateDirectory, packagerName, true);
        if (!packager.isUseLocalArtifact()) {
            Files.move(prepareDirectory.resolve("Dockerfile-remote"), prepareDirectory.resolve("Dockerfile"), REPLACE_EXISTING);
        } else {
            Files.deleteIfExists(prepareDirectory.resolve("Dockerfile-remote"));
        }
        return;
    }
    // copy root files
    String rootTemplateDirectory = getPackager().getTemplateDirectory() + File.separator + ROOT;
    super.doPrepareDistribution(distribution, props, distributionName, prepareDirectory.resolve(ROOT), rootTemplateDirectory, packager.getType(), false);
    Files.deleteIfExists(prepareDirectory.resolve(ROOT).resolve("Dockerfile"));
    Files.deleteIfExists(prepareDirectory.resolve(ROOT).resolve("Dockerfile-remote"));
    for (DockerSpec spec : packager.getActiveSpecs()) {
        prepareSpec(distribution, props, distributionName, prepareDirectory, spec);
    }
}
Also used : DockerSpec(org.jreleaser.model.DockerSpec)

Example 3 with DockerSpec

use of org.jreleaser.model.DockerSpec in project jreleaser by jreleaser.

the class DockerPackagerProcessor method doPackageDistribution.

@Override
protected void doPackageDistribution(Distribution distribution, Map<String, Object> props, Path packageDirectory) throws PackagerProcessingException {
    if (packager.getActiveSpecs().isEmpty()) {
        List<Artifact> artifacts = packager.resolveCandidateArtifacts(context, distribution);
        packageDocker(distribution, props, packageDirectory, getPackager(), artifacts);
        return;
    }
    Path rootPrepareDirectory = getPrepareDirectory(props).resolve(ROOT);
    Path rootPackageDirectory = getPackageDirectory(props).resolve(ROOT);
    copyFiles(rootPrepareDirectory, rootPackageDirectory);
    for (DockerSpec spec : packager.getActiveSpecs()) {
        context.getLogger().debug(RB.$("distributions.action.packaging") + " {} spec", spec.getName());
        Map<String, Object> newProps = fillSpecProps(distribution, props, spec);
        packageDocker(distribution, newProps, packageDirectory.resolve(spec.getName()), spec, Collections.singletonList(spec.getArtifact()));
    }
}
Also used : Path(java.nio.file.Path) Artifact(org.jreleaser.model.Artifact) DockerSpec(org.jreleaser.model.DockerSpec)

Example 4 with DockerSpec

use of org.jreleaser.model.DockerSpec in project jreleaser by jreleaser.

the class DockerPackagerProcessor method publishDistribution.

@Override
public void publishDistribution(Distribution distribution, Map<String, Object> props) throws PackagerProcessingException {
    if (packager.getActiveSpecs().isEmpty()) {
        if (packager.getRegistries().isEmpty()) {
            context.getLogger().info(RB.$("docker.no.registries"));
            publishToRepository(distribution, props);
            return;
        }
        super.publishDistribution(distribution, props);
        publishToRepository(distribution, props);
        return;
    }
    for (DockerSpec spec : packager.getActiveSpecs()) {
        context.getLogger().debug(RB.$("distributions.action.publishing") + " {} spec", spec.getName());
        Map<String, Object> newProps = fillSpecProps(distribution, props, spec);
        publishDocker(distribution, newProps, spec);
    }
    publishToRepository(distribution, props);
}
Also used : DockerSpec(org.jreleaser.model.DockerSpec)

Example 5 with DockerSpec

use of org.jreleaser.model.DockerSpec in project jreleaser by jreleaser.

the class DockerPackagerProcessor method prepareWorkingCopy.

@Override
protected void prepareWorkingCopy(Map<String, Object> props, Path directory, Distribution distribution) throws PackagerProcessingException, IOException {
    Path packageDirectory = (Path) props.get(KEY_DISTRIBUTION_PACKAGE_DIRECTORY);
    List<DockerSpec> activeSpecs = packager.getActiveSpecs();
    if (activeSpecs.isEmpty()) {
        for (String imageName : packager.getImageNames()) {
            copyDockerfiles(packageDirectory, resolveTemplate(imageName, props), directory, packager, false);
        }
    } else {
        // copy files that do not belong to specs
        prepareWorkingCopy(packageDirectory.resolve(ROOT), directory);
        for (DockerSpec spec : activeSpecs) {
            Map<String, Object> newProps = fillSpecProps(distribution, props, spec);
            for (String imageName : spec.getImageNames()) {
                copyDockerfiles(packageDirectory.resolve(spec.getName()), resolveTemplate(imageName, newProps), directory, spec, true);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) DockerSpec(org.jreleaser.model.DockerSpec)

Aggregations

DockerSpec (org.jreleaser.model.DockerSpec)6 Artifact (org.jreleaser.model.Artifact)3 Path (java.nio.file.Path)2 Collections.singleton (java.util.Collections.singleton)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 RB (org.jreleaser.bundle.RB)2 Active (org.jreleaser.model.Active)2 Distribution (org.jreleaser.model.Distribution)2 Docker (org.jreleaser.model.Docker)2 LABEL_OCI_IMAGE_DESCRIPTION (org.jreleaser.model.Docker.LABEL_OCI_IMAGE_DESCRIPTION)2 LABEL_OCI_IMAGE_LICENSES (org.jreleaser.model.Docker.LABEL_OCI_IMAGE_LICENSES)2 LABEL_OCI_IMAGE_REVISION (org.jreleaser.model.Docker.LABEL_OCI_IMAGE_REVISION)2 LABEL_OCI_IMAGE_TITLE (org.jreleaser.model.Docker.LABEL_OCI_IMAGE_TITLE)2 LABEL_OCI_IMAGE_URL (org.jreleaser.model.Docker.LABEL_OCI_IMAGE_URL)2