本文整理汇总了Java中org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints类的典型用法代码示例。如果您正苦于以下问题:Java DockerFingerprints类的具体用法?Java DockerFingerprints怎么用?Java DockerFingerprints使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DockerFingerprints类属于org.jenkinsci.plugins.docker.commons.fingerprint包,在下文中一共展示了DockerFingerprints类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: withRunCommand
import org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints; //导入依赖的package包/类
@Test public void withRunCommand() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
assumeDocker();
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "prj");
p.setDefinition(new CpsFlowDefinition(
" docker.image('maven:3.3.9-jdk-8').withRun(\"--entrypoint mvn\", \"-version\") {c ->\n" +
" sh \"docker logs ${c.id}\"" +
"}", true));
story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
DockerClient client = new DockerClient(new Launcher.LocalLauncher(StreamTaskListener.NULL), null, null);
String mavenIID = client.inspect(new EnvVars(), "maven:3.3.9-jdk-8", ".Id");
Fingerprint f = DockerFingerprints.of(mavenIID);
assertNotNull(f);
DockerRunFingerprintFacet facet = f.getFacet(DockerRunFingerprintFacet.class);
assertNotNull(facet);
}
});
}
示例2: assertBuild
import org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints; //导入依赖的package包/类
private void assertBuild(final String projectName, final String piplineCode) throws Exception {
story.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
assumeDocker();
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, projectName);
p.setDefinition(new CpsFlowDefinition(piplineCode, true));
WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
DockerClient client = new DockerClient(new LocalLauncher(StreamTaskListener.NULL), null, null);
String ancestorImageId = client.inspect(new EnvVars(), "hello-world", ".Id");
story.j.assertLogContains("built from-with-arg", b);
story.j.assertLogContains(ancestorImageId.replaceFirst("^sha256:", "").substring(0, 12), b);
Fingerprint f = DockerFingerprints.of(ancestorImageId);
assertNotNull(f);
DockerDescendantFingerprintFacet descendantFacet = f.getFacet(DockerDescendantFingerprintFacet.class);
assertNotNull(descendantFacet);
}
});
}
示例3: attachFacet
import org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints; //导入依赖的package包/类
public static void attachFacet(Run<?, ?> run, TaskListener listener) {
final Executor executor = run.getExecutor();
if (executor == null) {
return;
}
final Computer owner = executor.getOwner();
DockerComputer dockerComputer;
if (owner instanceof DockerComputer) {
dockerComputer = (DockerComputer) owner;
try {
DockerFingerprints.addRunFacet(
createRecordFor(dockerComputer),
run
);
} catch (IOException | ParseException e) {
listener.error("Can't add Docker fingerprint to run.");
LOG.error("Can't add fingerprint to run {}", run, e);
}
}
}
示例4: getLastInspectImageResponse
import org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints; //导入依赖的package包/类
/**
* Retrieves the last {@link InspectImageResponse} for the specified image.
* @param imageId Image Id
* @return Last available report. Null if there is no data available
* (or if an internal exception happens)
*/
public static @CheckForNull InspectImageResponse getLastInspectImageResponse(@Nonnull String imageId) {
try {
final Fingerprint fp = DockerFingerprints.of(imageId);
if (fp != null) {
final DockerInspectImageFacet facet = FingerprintsHelper.getFacet(fp, DockerInspectImageFacet.class);
if (facet != null) {
return facet.getData();
}
}
return null;
} catch (IOException ex) {
LOGGER.log(Level.WARNING, "Cannot retrieve deployment reports for imageId="+imageId, ex);
return null;
}
}
示例5: doTestSubmitBuildRef
import org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints; //导入依赖的package包/类
/**
* A stub method, which emulates the submission of the image reference
* from the web interface
* @param req Incoming request
* @param rsp Response
* @param imageId image id
* @param jobName job name, to which the facet should be attached
* @throws IOException Request processing error
* @throws ServletException Servlet error
*/
public static void doTestSubmitBuildRef(StaplerRequest req, StaplerResponse rsp,
@QueryParameter(required = true) String imageId,
@QueryParameter(required = true) String jobName) throws IOException, ServletException {
final Jenkins j = Jenkins.getInstance();
if (j == null) {
throw new IOException("Jenkins instance is not active");
}
j.checkPermission(Jenkins.ADMINISTER);
final AbstractProject item = j.getItem(jobName, j, AbstractProject.class);
final Run latest = item != null ? item.getLastBuild() : null;
if (latest == null) {
throw new IOException("Cannot find a project or run to modify");
}
DockerFingerprints.addFromFacet(null,imageId, latest);
rsp.sendRedirect2(j.getRootUrl());
}
示例6: submitReportWithoutImageReference
import org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints; //导入依赖的package包/类
/**
* Checks the resolution of imageId from previously saved data.
* @throws Exception test failure
*/
@Bug(28752)
public void submitReportWithoutImageReference() throws Exception {
DockerTraceabilityPluginTest.configure(new DockerTraceabilityPluginConfiguration(true, true));
final String imageId = FingerprintTestUtil.generateDockerId("1");
final Event event1 = new DockerEvent("run", imageId, "host", 12345).toDockerEvent();
final Event event2 = new DockerEvent("die", imageId, "host", 12346).toDockerEvent();
final InspectContainerResponse containerInfo = JSONSamples.inspectContainerData_emptyImage.
readObject(InspectContainerResponse.class);
DockerTraceabilityReport r1 = new DockerTraceabilityReport(event1, null, containerInfo, imageId, null, null,
new LinkedList<String>(), null);
DockerTraceabilityReport r2 = new DockerTraceabilityReport(event2, null, containerInfo, null, null, null,
new LinkedList<String>(), null);
// Spawn two reports
DockerTraceabilityReportListener.fire(r1);
DockerTraceabilityReportListener.fire(r2);
// Retrieve
final DockerDeploymentFacet facet =
DockerFingerprints.getFacet(containerInfo.getId(), DockerDeploymentFacet.class);
assertNotNull(facet);
assertEquals(imageId, facet.getImageId());
assertEquals("Expected both reports to be saved in the fingerprint", 2, facet.getDeploymentRecords().size());
}
开发者ID:jenkinsci,项目名称:docker-traceability-plugin,代码行数:30,代码来源:DockerTraceabilityReportListenerImplTest.java
示例7: assertNotNull
import org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints; //导入依赖的package包/类
/**
* Checks that the existence {@link DockerDeploymentRefFacet}.
* @param containerId Container ID
* @param imageId image ID
* @return Facet (if validation passes)
* @throws IOException test failure
* @throws AssertionError Validation failure
*/
public DockerDeploymentRefFacet assertExistsDeploymentRefFacet
(@Nonnull String containerId, @Nonnull String imageId) throws IOException {
final Fingerprint imageFP = DockerFingerprints.of(imageId);
assertNotNull(imageFP);
final DockerDeploymentRefFacet containerRefFacet =
FingerprintsHelper.getFacet(imageFP, DockerDeploymentRefFacet.class);
assertNotNull(containerRefFacet);
assertEquals(1, containerRefFacet.getContainerIds().size());
for (String containerRefId : containerRefFacet.getContainerIds()) {
assertNotNull(containerRefFacet.getLastStatus(containerRefId));
}
assertEquals(containerId, containerRefFacet.getContainerIds().toArray()[0]);
return containerRefFacet;
}
示例8: run
import org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints; //导入依赖的package包/类
@SuppressWarnings("SynchronizeOnNonFinalField") // run is quasi-final
@Override protected Void run() throws Exception {
DockerClient client = new DockerClient(launcher, node, step.toolName);
DockerFingerprints.addRunFacet(client.getContainerRecord(env, step.containerId), run);
String image = client.inspect(env, step.containerId, ".Config.Image");
if (image != null) {
ImageAction.add(image, run);
}
return null;
}
示例9: getOrCreate
import org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints; //导入依赖的package包/类
public static @Nonnull DockerDeploymentFacet getOrCreate(@Nonnull Fingerprint fingerprint)
throws IOException {
DockerDeploymentFacet res = DockerFingerprints.getFacet(fingerprint, DockerDeploymentFacet.class);
if (res != null) {
return res;
}
// Create new one
DockerDeploymentFacet facet = new DockerDeploymentFacet(fingerprint);
fingerprint.getFacets().add(facet);
fingerprint.save();
return facet;
}
示例10: createFingerPrintsOnDemand
import org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints; //导入依赖的package包/类
@Test
@Bug(28656)
public void createFingerPrintsOnDemand() throws Exception {
// Read data from resources
String inspectData = JSONSamples.inspectContainerData.readString();
InspectContainerResponse inspectResponse = JSONSamples.inspectContainerData.
readObject(InspectContainerResponse[].class)[0];
final String containerId = inspectResponse.getId();
final String imageId = inspectResponse.getImageId();
// Retrieve instances
final DockerTraceabilityRootAction action = DockerTraceabilityRootAction.getInstance();
assertNotNull(action);
// Enable automatic fingerprints creation
DockerTraceabilityPluginConfiguration config = new DockerTraceabilityPluginConfiguration(true, false);
DockerTraceabilityPluginTest.configure(config);
DockerTraceabilityPlugin plugin = DockerTraceabilityPlugin.getInstance();
assertTrue(plugin.getConfiguration().isCreateImageFingerprints());
// Submit JSON
HttpResponse res = action.doSubmitContainerStatus(inspectData, null, null, null, 0, null, null);
// Ensure that both container and images have been created with proper facets
Fingerprint imageFP = DockerFingerprints.of(imageId);
Fingerprint containerFP = DockerFingerprints.of(containerId);
assertNotNull(imageFP);
assertNotNull(DockerFingerprints.getFacet(imageFP, DockerDeploymentRefFacet.class));
assertNotNull(containerFP);
assertNotNull(DockerFingerprints.getFacet(containerFP, DockerDeploymentFacet.class));
// TODO: JENKINS-28655 (Fingerprints cleanup)
// Check original references - Docker Traceability Manager should create runs
// assertNotNull(imageFP.getOriginal().getJob());
// assertNotNull(containerFP.getOriginal().getJob());
}
示例11: run
import org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints; //导入依赖的package包/类
@Override protected Void run() throws Exception {
String fromImage = null;
FilePath dockerfile = workspace.child(step.dockerfile);
InputStream is = dockerfile.read();
try {
BufferedReader r = new BufferedReader(new InputStreamReader(is, "ISO-8859-1")); // encoding probably irrelevant since image/tag names must be ASCII
try {
String line;
while ((line = r.readLine()) != null) {
line = line.trim();
if (line.startsWith("#")) {
continue;
}
if (line.startsWith("FROM ")) {
fromImage = line.substring(5);
continue;
}
}
} finally {
r.close();
}
} finally {
is.close();
}
if (fromImage == null) {
throw new AbortException("could not find FROM instruction in " + dockerfile);
}
if (step.getBuildArgs() != null) {
// Fortunately, Docker uses the same EnvVar syntax as Jenkins :)
fromImage = Util.replaceMacro(fromImage, step.getBuildArgs());
}
DockerClient client = new DockerClient(launcher, node, step.toolName);
String descendantImageId = client.inspectRequiredField(env, step.image, ".Id");
if (fromImage.equals("scratch")) { // we just made a base image
DockerFingerprints.addFromFacet(null, descendantImageId, run);
} else {
DockerFingerprints.addFromFacet(client.inspectRequiredField(env, fromImage, ".Id"), descendantImageId, run);
ImageAction.add(fromImage, run);
}
return null;
}
示例12: start
import org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints; //导入依赖的package包/类
@Override public boolean start() throws Exception {
EnvVars envReduced = new EnvVars(env);
EnvVars envHost = computer.getEnvironment();
envReduced.entrySet().removeAll(envHost.entrySet());
// Remove PATH during cat.
envReduced.remove("PATH");
envReduced.remove("");
LOGGER.log(Level.FINE, "reduced environment: {0}", envReduced);
workspace.mkdirs(); // otherwise it may be owned by root when created for -v
String ws = workspace.getRemote();
toolName = step.toolName;
DockerClient dockerClient = new DockerClient(launcher, node, toolName);
VersionNumber dockerVersion = dockerClient.version();
if (dockerVersion != null) {
if (dockerVersion.isOlderThan(new VersionNumber("1.7"))) {
throw new AbortException("The docker version is less than v1.7. Pipeline functions requiring 'docker exec' (e.g. 'docker.inside') or SELinux labeling will not work.");
} else if (dockerVersion.isOlderThan(new VersionNumber("1.8"))) {
listener.error("The docker version is less than v1.8. Running a 'docker.inside' from inside a container will not work.");
}
} else {
listener.error("Failed to parse docker version. Please note there is a minimum docker version requirement of v1.7.");
}
FilePath tempDir = tempDir(workspace);
tempDir.mkdirs();
String tmp = tempDir.getRemote();
Map<String, String> volumes = new LinkedHashMap<String, String>();
Collection<String> volumesFromContainers = new LinkedHashSet<String>();
Optional<String> containerId = dockerClient.getContainerIdIfContainerized();
if (containerId.isPresent()) {
listener.getLogger().println(node.getDisplayName() + " seems to be running inside container " + containerId.get());
final Collection<String> mountedVolumes = dockerClient.getVolumes(env, containerId.get());
final String[] dirs = {ws, tmp};
for (String dir : dirs) {
// check if there is any volume which contains the directory
boolean found = false;
for (String vol : mountedVolumes) {
if (dir.startsWith(vol)) {
volumesFromContainers.add(containerId.get());
found = true;
break;
}
}
if (!found) {
listener.getLogger().println("but " + dir + " could not be found among " + mountedVolumes);
volumes.put(dir, dir);
}
}
} else {
listener.getLogger().println(node.getDisplayName() + " does not seem to be running inside a container");
volumes.put(ws, ws);
volumes.put(tmp, tmp);
}
container = dockerClient.run(env, step.image, step.args, ws, volumes, volumesFromContainers, envReduced, dockerClient.whoAmI(), /* expected to hang until killed */ "cat");
DockerFingerprints.addRunFacet(dockerClient.getContainerRecord(env, container), run);
ImageAction.add(step.image, run);
getContext().newBodyInvoker().
withContext(BodyInvoker.mergeLauncherDecorators(getContext().get(LauncherDecorator.class), new Decorator(container, envHost, ws, toolName, dockerVersion))).
withCallback(new Callback(container, toolName)).
start();
return false;
}
示例13: build
import org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints; //导入依赖的package包/类
@Test public void build() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
assumeDocker();
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "prj");
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" writeFile file: 'stuff1', text: 'hello'\n" +
" writeFile file: 'stuff2', text: 'world'\n" +
" writeFile file: 'stuff3', text: env.BUILD_NUMBER\n" +
" writeFile file: 'Dockerfile', text: '# This is a test.\\n\\nFROM hello-world\\nCOPY stuff1 /\\nCOPY stuff2 /\\nCOPY stuff3 /\\n'\n" +
" def built = docker.build 'hello-world-stuff'\n" +
" echo \"built ${built.id}\"\n" +
"}", true));
WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
DockerClient client = new DockerClient(new Launcher.LocalLauncher(StreamTaskListener.NULL), null, null);
String ancestorImageId = client.inspect(new EnvVars(), "hello-world", ".Id");
String descendantImageId1 = client.inspect(new EnvVars(), "hello-world-stuff", ".Id");
story.j.assertLogContains("built hello-world-stuff", b);
story.j.assertLogContains(descendantImageId1.replaceFirst("^sha256:", "").substring(0, 12), b);
Fingerprint f = DockerFingerprints.of(ancestorImageId);
assertNotNull(f);
DockerDescendantFingerprintFacet descendantFacet = f.getFacet(DockerDescendantFingerprintFacet.class);
assertNotNull(descendantFacet);
assertEquals(Fingerprint.RangeSet.fromString("1", false), descendantFacet.getRangeSet(p));
assertEquals(ancestorImageId, descendantFacet.getImageId());
assertEquals(Collections.singleton(descendantImageId1), descendantFacet.getDescendantImageIds());
f = DockerFingerprints.of(descendantImageId1);
assertNotNull(f);
DockerAncestorFingerprintFacet ancestorFacet = f.getFacet(DockerAncestorFingerprintFacet.class);
assertNotNull(ancestorFacet);
assertEquals(Fingerprint.RangeSet.fromString("1", false), ancestorFacet.getRangeSet(p));
assertEquals(Collections.singleton(ancestorImageId), ancestorFacet.getAncestorImageIds());
assertEquals(descendantImageId1, ancestorFacet.getImageId());
b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
String descendantImageId2 = client.inspect(new EnvVars(), "hello-world-stuff", ".Id");
story.j.assertLogContains("built hello-world-stuff", b);
story.j.assertLogContains(descendantImageId2.replaceFirst("^sha256:", "").substring(0, 12), b);
f = DockerFingerprints.of(ancestorImageId);
assertNotNull(f);
descendantFacet = f.getFacet(DockerDescendantFingerprintFacet.class);
assertNotNull(descendantFacet);
assertEquals(Fingerprint.RangeSet.fromString("1-2", false), descendantFacet.getRangeSet(p));
assertEquals(ancestorImageId, descendantFacet.getImageId());
assertEquals(new HashSet<String>(Arrays.asList(descendantImageId1, descendantImageId2)), descendantFacet.getDescendantImageIds());
f = DockerFingerprints.of(descendantImageId1);
assertNotNull(f);
ancestorFacet = f.getFacet(DockerAncestorFingerprintFacet.class);
assertNotNull(ancestorFacet);
assertEquals(Fingerprint.RangeSet.fromString("1", false), ancestorFacet.getRangeSet(p));
assertEquals(Collections.singleton(ancestorImageId), ancestorFacet.getAncestorImageIds());
assertEquals(descendantImageId1, ancestorFacet.getImageId());
f = DockerFingerprints.of(descendantImageId2);
assertNotNull(f);
ancestorFacet = f.getFacet(DockerAncestorFingerprintFacet.class);
assertNotNull(ancestorFacet);
assertEquals(Fingerprint.RangeSet.fromString("2", false), ancestorFacet.getRangeSet(p));
assertEquals(Collections.singleton(ancestorImageId), ancestorFacet.getAncestorImageIds());
assertEquals(descendantImageId2, ancestorFacet.getImageId());
assertEquals(Collections.singleton("hello-world"), DockerImageExtractor.getDockerImagesUsedByJobFromAll(p));
}
});
}
示例14: forContainer
import org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints; //导入依赖的package包/类
/**
* Creates a report for a container.
* @param containerId Container id
* @return Generated report. Null if the data cannot be retrieved.
*/
public static @CheckForNull DockerAPIReport forContainer(@Nonnull String containerId) {
Fingerprint containerFP = DockerTraceabilityHelper.of(containerId);
if (containerFP == null) {
return null;
}
DockerDeploymentFacet facet = FingerprintsHelper.getFacet(containerFP,
DockerDeploymentFacet.class);
if (facet == null) {
return null;
}
final String lastStatus = facet.getLastStatus();
final DockerContainerRecord lastRecord = facet.getLatest();
if (lastRecord == null) {
return null;
}
final DockerTraceabilityReport report = lastRecord.getReport();
final String imageId = report.getImageId();
@CheckForNull Fingerprint imageFP = null;
if (imageId != null) {
try {
imageFP = DockerFingerprints.of(imageId);
} catch (IOException ex) {
// Do nothing
}
}
final InspectImageResponse inspectImageResponse = report.getImage();
final InspectContainerResponse inspectContainerResponse = report.getContainer();
if (inspectContainerResponse == null) {
return null;
}
final Image image = new Image(imageId, report.getImageName(),
(inspectImageResponse != null) ? inspectImageResponse.getCreated() : "N/A", imageFP);
final State state = new State(lastStatus, inspectContainerResponse.getState());
final Container container = new Container(inspectContainerResponse.getId(), inspectContainerResponse.getName(),
inspectContainerResponse.getCreated(), containerFP, state);
final Host host = new Host(report.getHostInfo().getID(), report.getHostInfo().getName());
final String environment = report.getEnvironment();
final String lastUpdate = DockerTraceabilityHelper.formatTime(report.getEvent().getTime());
return new DockerAPIReport(lastUpdate, container, image, environment, host, report.getParents());
}
示例15: injectFromFacet
import org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints; //导入依赖的package包/类
/**
* Injects a {@link Fingerprint} and reference facets to the specified run.
* @param run Run to be modified
* @param imageId Image id
* @throws IOException Error
*/
public static void injectFromFacet (Run run, String imageId) throws IOException {
DockerFingerprints.addFromFacet(null, imageId, run);
}