Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Gradle declared external docker image dependencies #12

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/java/org/terracotta/build/plugins/docker/DockerBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import java.nio.file.Files;
import java.nio.file.Path;

import static java.nio.file.StandardOpenOption.CREATE;
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
import static java.util.stream.Stream.of;

public abstract class DockerBuild extends DockerTask {
Expand Down Expand Up @@ -90,4 +93,14 @@ protected static String readImageId(FileSystemLocation file) {
throw new UncheckedIOException(e);
}
}

protected static void writeImageId(FileSystemLocation file, String imageId) {
Path path = file.getAsFile().toPath();
try {
Files.createDirectories(path.getParent());
Files.write(path, singletonList(imageId), CREATE, TRUNCATE_EXISTING);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package org.terracotta.build.plugins.docker;

import groovy.lang.Closure;
import org.gradle.api.NamedDomainObjectProvider;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.attributes.Category;
import org.gradle.api.file.RegularFile;
import org.gradle.api.provider.Provider;

import java.util.Map;
Expand Down Expand Up @@ -34,6 +38,16 @@ public void apply(Project project) {
});

project.getExtensions().create("docker", DockerExtension.class, dockerImageIds);

DependencyHandler dependencies = project.getDependencies();
dependencies.getExtensions().add("external", new Closure<Dependency>(dependencies, dependencies) {

Dependency doCall(String name, String imageId) {
Provider<RegularFile> imageIdFile = project.getLayout().getBuildDirectory().file(name + ".iid");
DockerBuild.writeImageId(imageIdFile.get(), imageId);
return ((DependencyHandler) getOwner()).create(project.files(imageIdFile));
}
});
}

public static class DockerExtension {
Expand Down