|
|
package org.implab.gradle.containers;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
|
import java.util.Optional;
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
|
import org.gradle.api.Project;
|
|
|
import org.gradle.api.file.DirectoryProperty;
|
|
|
import org.gradle.api.file.ProjectLayout;
|
|
|
import org.gradle.api.provider.Property;
|
|
|
import org.gradle.api.provider.Provider;
|
|
|
import org.implab.gradle.containers.cli.ImageName;
|
|
|
import org.implab.gradle.containers.cli.ImageRef;
|
|
|
import org.implab.gradle.containers.cli.Utils;
|
|
|
|
|
|
public abstract class ContainerExtension implements PropertiesMixin {
|
|
|
|
|
|
public abstract Property<String> getCliCmd();
|
|
|
|
|
|
public abstract DirectoryProperty getContextDirectory();
|
|
|
|
|
|
/**
|
|
|
* Specifies the name of the registry where the image is located
|
|
|
* {@code registry.my-company.org}
|
|
|
*/
|
|
|
public abstract Property<String> getImageAuthority();
|
|
|
|
|
|
/**
|
|
|
* Specified the path of the image like {@code my-company}
|
|
|
*/
|
|
|
public abstract Property<String> getImageGroup();
|
|
|
|
|
|
public Provider<ImageName> getImageName() {
|
|
|
return provider(this::createImageName);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Specifies local image part like {@code httpd}
|
|
|
*/
|
|
|
public abstract Property<String> getImageLocalName();
|
|
|
|
|
|
/**
|
|
|
* This property is deprecated use imageLocalName
|
|
|
*/
|
|
|
@Deprecated
|
|
|
public Property<String> getImageShortName() {
|
|
|
return getImageLocalName();
|
|
|
}
|
|
|
|
|
|
public abstract Property<String> getImageTag();
|
|
|
|
|
|
@Inject
|
|
|
public ContainerExtension(ProjectLayout layout, Project project) {
|
|
|
getContextDirectory().convention(layout.getBuildDirectory().dir("context"));
|
|
|
|
|
|
getImageLocalName().convention(project.getName());
|
|
|
|
|
|
getImageTag().set(provider(() -> Optional.ofNullable(project.getVersion())
|
|
|
.map(Object::toString)
|
|
|
.orElse("latest")));
|
|
|
|
|
|
getImageAuthority()
|
|
|
.convention(project.provider(() -> (String) project.getProperties().get("imagesAuthority")));
|
|
|
|
|
|
getImageGroup()
|
|
|
.convention(project.provider(() -> (String) project.getProperties().get("imagesGroup")));
|
|
|
|
|
|
getCliCmd().convention(project
|
|
|
.provider(() -> (String) project.getProperties().get("containerCli"))
|
|
|
.orElse("docker"));
|
|
|
}
|
|
|
|
|
|
ImageName createImageName() {
|
|
|
return new ImageName(
|
|
|
getImageAuthority().getOrNull(),
|
|
|
getImageGroup().getOrNull(),
|
|
|
getImageLocalName().get(),
|
|
|
getImageTag().getOrNull());
|
|
|
}
|
|
|
|
|
|
public ImageRef readImageRef(File file) throws FileNotFoundException, IOException {
|
|
|
return Utils.readImageRef(file);
|
|
|
}
|
|
|
|
|
|
}
|