|
|
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.file.RegularFileProperty;
|
|
|
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 {
|
|
|
|
|
|
public abstract Property<String> getCliCmd();
|
|
|
|
|
|
public abstract DirectoryProperty getContextDirectory();
|
|
|
|
|
|
public abstract RegularFileProperty getImageIdFile();
|
|
|
|
|
|
/**
|
|
|
* 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 abstract Property<ImageName> getImageName();
|
|
|
|
|
|
/**
|
|
|
* 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"));
|
|
|
|
|
|
getImageIdFile().convention(layout.getBuildDirectory().file("iid.json"));
|
|
|
|
|
|
getCliCmd().set("docker");
|
|
|
|
|
|
getImageLocalName().convention(project.getName());
|
|
|
|
|
|
getImageTag().set(project
|
|
|
.provider(() -> Optional.ofNullable(project.getVersion()).map(v -> v.toString()).orElse("latest")));
|
|
|
|
|
|
Provider<String> imageRepository = getImageGroup().map(g -> g + "/" + getImageLocalName().get())
|
|
|
.orElse(getImageLocalName());
|
|
|
|
|
|
getImageName().convention(project.provider(
|
|
|
() -> new ImageName().authority(getImageAuthority().get()).name(imageRepository.get())
|
|
|
.tag(getImageTag().get())));
|
|
|
}
|
|
|
|
|
|
public ImageName createImageName() {
|
|
|
return new ImageName();
|
|
|
}
|
|
|
|
|
|
public ImageRef readImageRef(File file) throws FileNotFoundException, IOException {
|
|
|
return Utils.readImageRef(file);
|
|
|
}
|
|
|
|
|
|
}
|