Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-28675] - Create fingerprints when creating new images
This is a draft implementation of the on-demand creation of Docker fingerprints from docker-build-publich plugin. The current version has a limited usability due to the lack of the info in fingerprints. We assume that something like Docker Traceability Plugin will add more info later.
- Loading branch information
1 parent
899be05
commit defbeab
Showing
6 changed files
with
283 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/main/java/com/cloudbees/dockerpublish/DockerCLIHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2015 CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package com.cloudbees.dockerpublish; | ||
|
||
import java.io.IOException; | ||
import javax.annotation.CheckForNull; | ||
import net.sf.json.JSONArray; | ||
import net.sf.json.JSONObject; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
/** | ||
* Retrieves the data for {@link DockerBuilder} from docker-java datatypes | ||
* @author Oleg Nenashev | ||
* @since TODO | ||
*/ | ||
@Restricted(NoExternalUse.class) | ||
public class DockerCLIHelper { | ||
|
||
/** | ||
* Retrieves an info about image from command-line outputs. | ||
* @param stdout Data output to be parsed | ||
* @return ImageId or null | ||
* @throws IOException Cannot parse the response | ||
* @since TODO | ||
*/ | ||
@CheckForNull | ||
public static InspectImageResponse parseInspectImageResponse(String stdout) throws IOException { | ||
JSONArray array = JSONArray.fromObject(stdout); | ||
if (array != null && array.size() > 0) { | ||
return new InspectImageResponse(array.getJSONObject(0)); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
@Restricted(NoExternalUse.class) | ||
public static class InspectImageResponse { | ||
|
||
private final String parent; | ||
private final String id; | ||
|
||
public InspectImageResponse(JSONObject inspectImageResponse) throws IOException { | ||
this.parent = inspectImageResponse.getString("Parent"); | ||
this.id = inspectImageResponse.getString("Id"); | ||
} | ||
|
||
public InspectImageResponse(String parent, String id) { | ||
this.parent = parent; | ||
this.id = id; | ||
} | ||
|
||
public String getParent() { | ||
return parent; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/resources/com/cloudbees/dockerpublish/DockerBuilder/help-createFingerprint.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div> | ||
If enabled, the plugin will create fingerprints after the build of each image. | ||
These fingerprints are being managed by | ||
<a href="https://wiki.jenkins-ci.org/display/JENKINS/Docker+Commons+Plugin"> | ||
Docker Commons Plugin</a>. | ||
</div> |
47 changes: 47 additions & 0 deletions
47
src/test/java/com/cloudbees/dockerpublish/DockerCLIHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2015 Cloudbees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package com.cloudbees.dockerpublish; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import com.google.common.base.Charsets; | ||
import java.net.URL; | ||
import org.junit.Test; | ||
import com.google.common.io.Resources; | ||
|
||
/** | ||
* Tests for {@link DockerCLIHelper}. | ||
* @author Oleg Nenashev | ||
*/ | ||
public class DockerCLIHelperTest { | ||
|
||
@Test | ||
public void parseDockerInspectImageOutput() throws Exception { | ||
URL url = Resources.getResource("dockerInspectImage_response.json"); | ||
DockerCLIHelper.InspectImageResponse rsp = DockerCLIHelper.parseInspectImageResponse(Resources.toString(url, Charsets.UTF_8)); | ||
assertNotNull(rsp); | ||
assertEquals("5366517d611967756a43c63a3223dbf645c5e9be66d594d86802dee143aad93a", rsp.getId()); | ||
assertEquals("4300417211ebb75b48b06ed5640d641778f312072d24b37978682345cbb362b1", rsp.getParent()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
[ | ||
{ | ||
"Architecture": "amd64", | ||
"Author": "Jesse Glick", | ||
"Comment": "Workflow Plugin Pipeline Demo", | ||
"Config": { | ||
"AttachStderr": false, | ||
"AttachStdin": false, | ||
"AttachStdout": false, | ||
"Cmd": [ | ||
"/bin/sh", | ||
"-c", | ||
"/var/lib/jenkins/run.sh" | ||
], | ||
"CpuShares": 0, | ||
"Cpuset": "", | ||
"Domainname": "", | ||
"Entrypoint": null, | ||
"Env": [ | ||
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", | ||
"MAVEN_VERSION=3.3.1", | ||
"JETTY_VERSION=9.2.9.v20150224", | ||
"REV=107ea141f5c7581056c6eb53d2ccd222cdf0d58c" | ||
], | ||
"ExposedPorts": { | ||
"22/tcp": {}, | ||
"8080/tcp": {}, | ||
"8081/tcp": {} | ||
}, | ||
"Hostname": "1d42a20b09ac", | ||
"Image": "5366517d611967756a43c63a3223dbf645c5e9be66d594d86802dee143aad93a", | ||
"Labels": null, | ||
"MacAddress": "", | ||
"Memory": 0, | ||
"MemorySwap": 0, | ||
"NetworkDisabled": false, | ||
"OnBuild": [], | ||
"OpenStdin": false, | ||
"PortSpecs": null, | ||
"StdinOnce": false, | ||
"Tty": false, | ||
"User": "", | ||
"Volumes": null, | ||
"WorkingDir": "/var/lib/jenkins/workflow-plugin-pipeline-demo" | ||
}, | ||
"Container": "3e5af3835a00a99092dc0e877e37f82bfee5a7d73ad63c93ecdba94d6e594665", | ||
"ContainerConfig": { | ||
"AttachStderr": false, | ||
"AttachStdin": false, | ||
"AttachStdout": false, | ||
"Cmd": [ | ||
"/bin/sh", | ||
"-c", | ||
"#(nop) EXPOSE 22/tcp 8080/tcp 8081/tcp" | ||
], | ||
"CpuShares": 0, | ||
"Cpuset": "", | ||
"Domainname": "", | ||
"Entrypoint": null, | ||
"Env": [ | ||
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", | ||
"MAVEN_VERSION=3.3.1", | ||
"JETTY_VERSION=9.2.9.v20150224", | ||
"REV=107ea141f5c7581056c6eb53d2ccd222cdf0d58c" | ||
], | ||
"ExposedPorts": { | ||
"22/tcp": {}, | ||
"8080/tcp": {}, | ||
"8081/tcp": {} | ||
}, | ||
"Hostname": "1d42a20b09ac", | ||
"Image": "5366517d611967756a43c63a3223dbf645c5e9be66d594d86802dee143aad93a", | ||
"Labels": null, | ||
"MacAddress": "", | ||
"Memory": 0, | ||
"MemorySwap": 0, | ||
"NetworkDisabled": false, | ||
"OnBuild": [], | ||
"OpenStdin": false, | ||
"PortSpecs": null, | ||
"StdinOnce": false, | ||
"Tty": false, | ||
"User": "", | ||
"Volumes": null, | ||
"WorkingDir": "/var/lib/jenkins/workflow-plugin-pipeline-demo" | ||
}, | ||
"Created": "2015-04-01T14:15:30.700262841Z", | ||
"DockerVersion": "1.5.0", | ||
"Id": "5366517d611967756a43c63a3223dbf645c5e9be66d594d86802dee143aad93a", | ||
"Os": "linux", | ||
"Parent": "4300417211ebb75b48b06ed5640d641778f312072d24b37978682345cbb362b1", | ||
"Size": 0, | ||
"VirtualSize": 827600055 | ||
} | ||
] |