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

Add docker stats support #70

Open
wants to merge 600 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
600 commits
Select commit Hold shift + click to select a range
c6507bd
support DOCKER_TLS_VERIFY to detect ssl
Jan 11, 2015
f026c1a
Merge branch 'master' of https://github.com/andre1987/docker-java int…
Jan 12, 2015
26cd47c
Polish exec create and start commands
Jan 12, 2015
9ef4f72
Merge branch 'andre1987-master'
Jan 12, 2015
2561436
Fix issue##122
Jan 12, 2015
c0c44ee
Update CHANGELOG.md
marcuslinke Jan 14, 2015
aa3867c
Merge pull request #123 from sclassen/support_tls_verify
marcuslinke Jan 14, 2015
327e5d1
Update CHANGELOG.md
marcuslinke Jan 14, 2015
421a873
Fixed NPE on ExecStartCmdImpl.
Jan 15, 2015
d1ea20f
Merge pull request #126 from andre1987/fixing-NPE-exec-start
marcuslinke Jan 15, 2015
04eaf1f
apply a rebased and squashed unixsocket-branch with a working ssl con…
gesellix Jan 16, 2015
bce65f0
add Dockerfile with minimal build environment
gesellix Jan 17, 2015
0319b14
fix client config test to handle different develeoper environments
gesellix Jan 18, 2015
f4ddcb3
explicitly declare the Exception as ignored
gesellix Jan 18, 2015
4f969dc
Allow unauthorized pullImageCmd
rtimush Jan 19, 2015
cdb75d8
Fix misleading variable name in Exec-start
vjuranek Jan 20, 2015
60fb248
Support wildcards in Dockerfile. Fix issue#129
Jan 20, 2015
3455bf4
Merge pull request #130 from vjuranek/start_exec_cleanup
marcuslinke Jan 20, 2015
4c69b51
some cleanup
Jan 21, 2015
fd05239
Merge branch 'gesellix-docker-unixsocket-rebast push origin mastered'
Jan 21, 2015
55e42ad
Update CHANGELOG.md
marcuslinke Jan 21, 2015
f71c2d9
[maven-release-plugin] prepare release docker-java-0.10.5
Jan 21, 2015
c256ccf
Merge branch 'master' of https://github.com/docker-java/docker-java
Jan 21, 2015
e2e30cd
[maven-release-plugin] prepare for next development iteration
Jan 21, 2015
e022c44
Update README.md
marcuslinke Jan 21, 2015
de1611e
Update README.md
marcuslinke Jan 21, 2015
2f9b736
Update CHANGELOG.md
marcuslinke Jan 21, 2015
7e50459
Merge pull request #128 from rtimush/unauthorized-pull
marcuslinke Jan 21, 2015
06c3ffe
Update CHANGELOG.md
marcuslinke Jan 21, 2015
0a3a28e
Fix compile error
Jan 21, 2015
ad7881a
Remove Google Guava as dependency
aslakknutsen Jan 27, 2015
6c4ab6a
Update to latest unix-socket-factory
aslakknutsen Jan 27, 2015
d451336
Merge pull request #134 from aslakknutsen/remove_guava
marcuslinke Jan 27, 2015
6fd8123
Merge pull request #135 from aslakknutsen/unix_socket_factory_update
marcuslinke Jan 27, 2015
a19dc6b
Update CHANGELOG.md
marcuslinke Jan 27, 2015
5a7e79c
Fix some CFX interoperability issues
Jan 27, 2015
db4cf1d
Patched LoggingFilter to work with CXF.
nfsantos Jan 28, 2015
3efaa6a
Merge pull request #136 from nfsantos/cfx-interop
marcuslinke Jan 28, 2015
48ba911
Multiple volumesFrom option when creating a container
Jan 28, 2015
ca611c1
Merge pull request #137 from docker-java/volumesfrom
marcuslinke Jan 28, 2015
afdafe9
Update CHANGELOG.md
marcuslinke Jan 28, 2015
cc5331d
Simplify volumesFrom handling
Jan 29, 2015
9b95d08
Merge pull request #138 from docker-java/cfx-interop
marcuslinke Jan 29, 2015
91b8107
Update CHANGELOG.md
marcuslinke Jan 29, 2015
11ae37f
Removed own Preconditons implementation
Jan 31, 2015
93348ec
Fix Issue #139
Feb 2, 2015
64abb6f
Merge pull request #142 from docker-java/issue-139
marcuslinke Feb 2, 2015
602008c
There are two different event streamed JSON objects that come back
magnayn Jan 2, 2015
8140c47
Make BuildImage and PushImage return an object that can be iterated
magnayn Jan 2, 2015
f186971
Repoint to shaded, imported jersey.repackaged guava (!)
magnayn Feb 3, 2015
b4d30f6
Update test to show typed API.
magnayn Feb 3, 2015
6fa4cc0
Only override AuthConfig iff username/password/email/server address a…
tedoc2000 Feb 5, 2015
f897dd0
Merge pull request #144 from signalfx/master
marcuslinke Feb 5, 2015
62a608d
Merge pull request #131 from magnayn/pr3
marcuslinke Feb 5, 2015
ea72e14
Added testcase for conflicting ports binding
Feb 5, 2015
ad32772
Fix events tests
Feb 5, 2015
62cd7e9
Fix events tests
Feb 5, 2015
dae60a4
Merge branch 'master' of https://github.com/docker-java/docker-java
Feb 5, 2015
e820c21
Introduce the notion of a Dockerfile, which can read specifications
magnayn Feb 6, 2015
509bd2e
Make BuildImage use DockerFile impl.
magnayn Feb 6, 2015
06fea21
Fix Issue #110
Feb 6, 2015
abee7f6
Move utilities classes to core package
Feb 6, 2015
cbcfba4
switch to 1.0.0-SNAPSHOT
Feb 6, 2015
1d098f8
Fix Issue #147
Feb 7, 2015
8af3d6f
feat(save): add save image to docker client
Feb 8, 2015
833d6fd
Merge pull request #145 from magnayn/pr4
marcuslinke Feb 8, 2015
9109be9
Merge pull request #148 from arthurtsang/feature/saveImage
marcuslinke Feb 8, 2015
0c6f2b4
Update CHANGELOG.md
marcuslinke Feb 8, 2015
19ec0db
Add redirection for 301 - Issue #147
Feb 11, 2015
adb85a8
fix unit tests
Feb 11, 2015
f28972b
Fix Issue #150
Feb 16, 2015
4dea651
Merge branch 'master' of https://github.com/docker-java/docker-java
Feb 16, 2015
8e2a1af
Merge branch 'redirects' of https://github.com/gabeki/docker-java into
Feb 16, 2015
c17bd5b
Merge branch 'gabeki-redirects't push origin master
Feb 16, 2015
8f9c275
Restore guava as a dependency
flandr Feb 16, 2015
4fc8a66
Merge branch 'flandr-guava't push origin master
Feb 18, 2015
09a71fe
Update CHANGELOG.md
marcuslinke Feb 18, 2015
4bdfd6f
Update CHANGELOG.md
marcuslinke Feb 18, 2015
126fae1
Add support for configuring ExtraHosts
Feb 19, 2015
30e2688
Support for withExtraHosts on StartContainerCmd
Feb 19, 2015
86edd56
add certificates for integration test on CI
Jan 20, 2015
22d4b2a
add configuration for circle CI
Feb 21, 2015
dc52e60
exclude tests which are failing in circle CI
Feb 21, 2015
abd73f5
do not validate isMemoryLimit() since it is host dependent
Feb 21, 2015
977a98f
add missing toString()
Feb 21, 2015
cc3e6dc
add circle.md
Feb 21, 2015
a4a19fe
[maven-release-plugin] prepare release docker-java-1.0.0
Feb 22, 2015
f73c493
[maven-release-plugin] prepare for next development iteration
Feb 22, 2015
b61918d
Update CHANGELOG.md
marcuslinke Feb 22, 2015
63fe62f
Update README.md
marcuslinke Feb 22, 2015
238c4dd
Adding volumes that was commented for some reason
Feb 23, 2015
077de66
Merge pull request #156 from kalmanb/withExtraHosts
marcuslinke Feb 23, 2015
3a7240e
Update CHANGELOG.md
marcuslinke Feb 23, 2015
a4e02ea
Update CHANGELOG.md
marcuslinke Feb 23, 2015
decbe71
Update CHANGELOG.md
docker-java-maintain Feb 23, 2015
7120519
Merge pull request #157 from sclassen/ciForIntegrationTests
docker-java-maintain Feb 23, 2015
9be273f
Update circle.md
docker-java-maintain Feb 23, 2015
1098c29
Fixing imports
Feb 23, 2015
8462173
Disable test cleanup exceptions stacktraces
Feb 23, 2015
f0c4acb
Update README.md
docker-java-maintain Feb 24, 2015
ec8f1f9
Added InspectExec command
netvl Feb 24, 2015
bcfcb47
Added missing ExitCode field
netvl Feb 24, 2015
553b394
Fix issue #158
Feb 24, 2015
5bed982
Fix race condition
Feb 24, 2015
bef2275
Merge pull request #159 from docker-java/issue158
marcuslinke Feb 24, 2015
0f01863
Update CHANGELOG.md
marcuslinke Feb 24, 2015
1e2c99a
Added a test for InspectExec command
netvl Mar 2, 2015
c88167b
PushImageCmd assumes that you have an auth config setup for the
magnayn Mar 4, 2015
2b4ca23
Add some utility classes for splitting up "tag parameters" passed
magnayn Feb 6, 2015
81b30b2
Convenience function for pushing by full tag.
magnayn Feb 23, 2015
c2b14dc
Close in finally.
alesj Mar 6, 2015
037c2f3
Ignore test in circle CI
Mar 6, 2015
d1107f5
Merge branch 'netvl-inspect-exec't push origin master
Mar 6, 2015
9fdbfc9
Merge branch 'master' of https://github.com/docker-java/docker-java
Mar 6, 2015
cb3ee13
Update CHANGELOG.md
marcuslinke Mar 6, 2015
6124b29
Merge branch 'iter_close' of https://github.com/alesj/docker-java int…
Mar 6, 2015
a6c8490
Merge branch 'alesj-iter_close't push origin master
Mar 6, 2015
f2cd973
Merge pull request #165 from magnayn/pr6
marcuslinke Mar 6, 2015
78226cc
Update CHANGELOG.md
marcuslinke Mar 6, 2015
b803438
Implemented AuthConfigurations for the Build command.
Mar 4, 2015
a3a8b98
Merge branch 'pr5' of https://github.com/magnayn/docker-java
Mar 6, 2015
0fd5a8d
Update CHANGELOG.md
marcuslinke Mar 6, 2015
c42720a
Update README.md
marcuslinke Mar 6, 2015
920c900
Update README.md
marcuslinke Mar 6, 2015
f38e935
Update README.md
marcuslinke Mar 6, 2015
73602ad
Since docker 1.5.0, it has been allowable to specify files other
magnayn Mar 9, 2015
8935d11
Merge pull request #170 from magnayn/pr7
marcuslinke Mar 16, 2015
9cb4273
Update CHANGELOG.md
marcuslinke Mar 16, 2015
6a89072
SaveImageCmd assumes that you have an auth config setup
xfournet Mar 19, 2015
fc3f7b7
SaveImageCmd API doesn't support X-Registry-Auth header
xfournet Mar 19, 2015
749a9af
Fix pull image test to work with 1.17
Mar 20, 2015
d57bed7
Fix issue # 171 with nested ENV variables in Dockerfile
Mar 20, 2015
408a320
Fix issue #176
Mar 20, 2015
8523236
Fix httpclient dep
KostyaSha Mar 22, 2015
a2b0f47
Merge pull request #178 from KostyaSha/patch-2
marcuslinke Mar 22, 2015
7f68a26
Cleanup POM.xml
Mar 23, 2015
59ca504
Add support for cpuset in CreateContainerCmd
maafy6 Mar 25, 2015
bc9fa11
Merge pull request #179 from maafy6/cpuset
marcuslinke Mar 25, 2015
8ae16af
Update CHANGELOG.md
marcuslinke Mar 25, 2015
a9c478b
Dockerfiles not called 'dockerfile'
magnayn Mar 25, 2015
0366cdf
Fix logger for SaveImageCmd and SaveImageCmdImplTest classes
xfournet Mar 28, 2015
63ea2fa
Merge pull request #175 from xfournet/pr1
marcuslinke Mar 29, 2015
6ac2753
We are now on a modern version of guava, so remove code that is
magnayn Mar 31, 2015
56356b3
Merge pull request #180 from magnayn/pr9
marcuslinke Apr 1, 2015
6987a1f
Update CHANGELOG.md
marcuslinke Apr 1, 2015
44570fe
Merge pull request #183 from magnayn/pr10
marcuslinke Apr 1, 2015
fd0bf88
exclude tests from circleCI
Apr 1, 2015
155f24c
Merge branch 'master' of https://github.com/docker-java/docker-java
Apr 1, 2015
376e7ed
Introduce WrappedResponseInputStream to close underlying Response
Apr 1, 2015
3dff2ea
Merge pull request #185 from docker-java/issue-181
marcuslinke Apr 1, 2015
e08695b
Update CHANGELOG.md
marcuslinke Apr 1, 2015
3214f5f
Added withPull method to BuilImageCmd
Apr 1, 2015
47cefcd
Merge pull request #186 from docker-java/issue-184
marcuslinke Apr 1, 2015
2bc3439
Update CHANGELOG.md
marcuslinke Apr 1, 2015
ca54f9c
Deprecate StartContainerCmd methods in favor of using CreateContainerCmd
Apr 1, 2015
bef79df
Added a Links constructor accepting a List object
MartinAhrer Apr 4, 2015
ccd56e9
Switch to 1.1.0-SNAPSHOT according to semantic versioning
Apr 5, 2015
ed1fba4
[maven-release-plugin] prepare release docker-java-1.1.0
Apr 5, 2015
a3bbeae
[maven-release-plugin] prepare for next development iteration
Apr 5, 2015
52cb771
Update CHANGELOG.md
marcuslinke Apr 5, 2015
d28460f
Merge pull request #192 from MartinAhrer/master
marcuslinke Apr 5, 2015
bdedec0
Update CHANGELOG.md
marcuslinke Apr 5, 2015
3b4c346
Update CHANGELOG.md
marcuslinke Apr 5, 2015
b42a3e1
Fix issue #164
Apr 7, 2015
c26c87c
Merge pull request #193 from docker-java/refactor-1
marcuslinke Apr 7, 2015
d26024c
Update CHANGELOG.md
marcuslinke Apr 7, 2015
2549f57
* Fixed remove intermediate containers bug on build goal - it was al…
eemmiirr Apr 7, 2015
e37814e
Merge pull request #194 from eemmiirr/bugfix
marcuslinke Apr 8, 2015
0f847c9
Update CHANGELOG.md
marcuslinke Apr 8, 2015
6ab93b4
Allow for null bindings
chenchun Apr 13, 2015
80093ca
Set to version 1.2.0-SNAPSHOT
Apr 14, 2015
8e2f6b3
[maven-release-plugin] prepare release docker-java-1.2.0
Apr 14, 2015
33b0ff5
[maven-release-plugin] prepare for next development iteration
Apr 14, 2015
065cd78
Update CHANGELOG.md
marcuslinke Apr 14, 2015
bcdfd46
Created FrameReader to assist reading frames from attach commands.
alexec Apr 25, 2015
2b4d5ff
Created FrameReader to assist reading frames from attach commands.
alexec Apr 25, 2015
83943eb
Make FrameReader Closable.
alexec Apr 25, 2015
538d465
Made exception more specifi
alexec Apr 25, 2015
4251444
Trim toString.
alexec Apr 25, 2015
559e6c1
Fixed bug in header.
alexec Apr 25, 2015
1e1e7e8
Updated FrameReaderTest.
alexec Apr 25, 2015
15b388e
Added 'MacAddress' option to create command
Apr 27, 2015
e3e6ce8
Added 'MacAddress' to inspect container response.
Apr 27, 2015
8c948b1
Merge branch 'master' of https://github.com/docker-java/docker-java
Apr 27, 2015
8534b78
* Added support to use Auth for mutiple repos during build
eemmiirr Apr 28, 2015
2bc290d
Fix createContainerWithEnv test
Apr 28, 2015
3dc651e
Merge pull request #197 from chenchun/binding
marcuslinke Apr 28, 2015
0d9e8a4
Update CHANGELOG.md
marcuslinke Apr 28, 2015
68df58a
Merge pull request #200 from docker-java/logging-with-frame
marcuslinke Apr 28, 2015
db7040f
Fix issue #202
Apr 28, 2015
f148c20
Merge branch 'master' of https://github.com/docker-java/docker-java
Apr 28, 2015
fdb9e77
Fix issue #205
May 1, 2015
6cd5f46
Update CHANGELOG.md
marcuslinke May 1, 2015
7f22b87
Merge pull request #204 from eemmiirr/use-authorization-on-build-fix
marcuslinke May 1, 2015
cfc3a9a
Update CHANGELOG.md
marcuslinke May 1, 2015
7675400
Update README.md
marcuslinke May 1, 2015
42c1892
Updated to jersey 2.17.
alexec May 3, 2015
92b2002
Flipped expressions for minor perf issue.
alexec May 3, 2015
9dc9b3c
Reverted jersey 2.11 -> 2.17
alexec May 3, 2015
ebaba35
Created integration test for FrameReader.
alexec May 3, 2015
6a7f1d2
Created integration test for FrameReader.
alexec May 3, 2015
5e8cfc6
Mad Dockerfile more robust.
alexec May 3, 2015
e29e7da
Ignore container removal error.
alexec May 3, 2015
0922068
Fixed connection leak.
alexec May 3, 2015
92aa1bb
Updated test.
alexec May 3, 2015
6942c4f
Ignore error when removing image (e.g. due to brtfs on CircleCI).
alexec May 3, 2015
33d66da
Ignore error when removing image (e.g. due to brtfs on CircleCI).
alexec May 3, 2015
fec6b92
Merge pull request #207 from docker-java/issue-196
alexec May 3, 2015
f05294d
Added PullEventStreamItem and EventStreamReader to stream the reading…
alexec May 3, 2015
8a35bd6
Corrected bug in test.
alexec May 3, 2015
86c9f0a
Added PullEventStreamItem and EventStreamReader to stream the reading…
alexec May 3, 2015
c577bf9
Add public constructor and Javadoc to api.model.Event
oleg-nenashev May 5, 2015
c3224cb
Merge pull request #208 from docker-java/event-stream-reader
marcuslinke May 6, 2015
8042fc9
Update CHANGELOG.md
marcuslinke May 6, 2015
f3e11c7
Merge pull request #210 from oleg-nenashev/api-model-improvement
marcuslinke May 6, 2015
5697c60
Quietly catch IndexOutOfBoundsException.
May 6, 2015
f4d5a4d
Revert "Quietly catch IndexOutOfBoundsException."
May 6, 2015
6fa074b
Add ulimit support
vangie May 7, 2015
bdbdd75
Added framework classes for JSON serialization-deserialization tests
oleg-nenashev May 7, 2015
a221a94
Direct unit tests for https://github.com/docker-java/docker-java/issu…
oleg-nenashev May 7, 2015
c31c4ac
Add missing serializers to resolve https://github.com/docker-java/doc…
oleg-nenashev May 7, 2015
d6e8be3
Add roundtrip spotcheck to InspectExecCmdImplTest
oleg-nenashev May 7, 2015
0dd4944
Merge pull request #212 from oleg-nenashev/issue_211
marcuslinke May 7, 2015
f539a10
Merge branch 'vangie/support_ulimit' of https://github.com/vangie/doc…
May 7, 2015
390b2f9
Use a common path relativize method to fix testDockerIgnore and testN…
xfournet May 8, 2015
3bdb899
Fix testDockerBuilderAddFilesViaWildcard on Windows
xfournet May 8, 2015
0e52d21
Fix canCloseFrameReaderAndReadExpectedLines test on Windows
xfournet May 8, 2015
d61b7c4
Fix regression when building an image from a TAR input stream
xfournet May 9, 2015
5ee09ba
Fix issue #201
May 10, 2015
72a61dd
Fix test expectation
May 10, 2015
2b70b45
Merge branch 'vangie-vangie/support_ulimit't push origin master
May 10, 2015
355e649
Call onCompletetion callback before close because of
May 10, 2015
1d52a47
Fix issue #214
May 10, 2015
8652329
Update CHANGELOG.md
marcuslinke May 10, 2015
5e268e5
Update README.md
marcuslinke May 10, 2015
306f635
Merge pull request #217 from xfournet/pr2
marcuslinke May 10, 2015
9954713
Exclude from CircleCI integration tests
May 10, 2015
ebcb85c
Set new semver version
May 10, 2015
3a0e734
[maven-release-plugin] prepare release docker-java-1.3.0
May 10, 2015
f4f8b56
[maven-release-plugin] prepare for next development iteration
May 10, 2015
9daa373
Update CHANGELOG.md
marcuslinke May 10, 2015
c5ba01b
Update README.md
marcuslinke May 10, 2015
e34638a
Do not wait for another event before exiting.
jtnord May 13, 2015
4c850b8
Merge pull request #220 from jtnord/patch-2
marcuslinke May 13, 2015
a9b92e3
Fix roundtrip test
May 14, 2015
a072d62
Workaround for issue #196
May 14, 2015
1ed6fbf
Warning comment on 'followStream'
May 15, 2015
2df09cd
Make FrameReaderITest work again
May 15, 2015
bff4291
Added test for starting container with auto assigned port binding
May 22, 2015
60ee0ce
Add docker stats support
May 24, 2015
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.github.dockerjava.core.GoLangFileMatch;
import com.github.dockerjava.core.GoLangFileMatchException;
import com.github.dockerjava.core.GoLangMatchFileFilter;
import com.github.dockerjava.core.dockerfile.Dockerfile;

import static jersey.repackaged.com.google.common.base.Preconditions.*;

Expand All @@ -34,14 +35,8 @@
*/
public class BuildImageCmdImpl extends AbstrDockerCmd<BuildImageCmd, BuildImageCmd.Response> implements BuildImageCmd {

private static final Pattern ADD_OR_COPY_PATTERN = Pattern
.compile("^(ADD|COPY)\\s+(.*)\\s+(.*)$");

private static final Pattern ENV_PATTERN = Pattern
.compile("^ENV\\s+(.*)\\s+(.*)$");

private InputStream tarInputStream = null;
private File tarFile = null;
private String tag;
private boolean noCache;
private boolean remove = true;
Expand All @@ -50,9 +45,12 @@ public class BuildImageCmdImpl extends AbstrDockerCmd<BuildImageCmd, BuildImageC
public BuildImageCmdImpl(BuildImageCmd.Exec exec, File dockerFolder) {
super(exec);
checkNotNull(dockerFolder, "dockerFolder is null");
tarFile = buildDockerFolderTar(dockerFolder);

try {
withTarInputStream(FileUtils.openInputStream(tarFile));
withTarInputStream(
new Dockerfile(new File(dockerFolder, "Dockerfile"))
.parse()
.buildDockerFolderTar() );
} catch (IOException e) {
// we just created the file this should never happen.
throw new RuntimeException(e);
Expand Down Expand Up @@ -140,9 +138,6 @@ public BuildImageCmdImpl withQuiet(boolean quiet) {
@Override
public void close() throws IOException {
super.close();
if (tarFile != null) {
FileUtils.deleteQuietly(tarFile);
}

tarInputStream.close();
}
Expand All @@ -156,201 +151,5 @@ public String toString() {
.append(!remove ? "--rm=false " : "").toString();
}

protected File buildDockerFolderTar(File dockerFolder) {
checkArgument(dockerFolder.exists(),
"Path %s doesn't exist", dockerFolder);
checkArgument(dockerFolder.isDirectory(),
"Folder %s doesn't exist", dockerFolder);
checkState(new File(dockerFolder, "Dockerfile").exists(),
"Dockerfile doesn't exist in " + dockerFolder);

// ARCHIVE TAR
String archiveNameWithOutExtension = UUID.randomUUID().toString();

File dockerFolderTar = null;

try {
File dockerFile = new File(dockerFolder, "Dockerfile");
List<String> dockerFileContent = FileUtils.readLines(dockerFile);

if (dockerFileContent.size() <= 0) {
throw new DockerClientException(String.format(
"Dockerfile %s is empty", dockerFile));
}

List<String> ignores = new ArrayList<String>();
File dockerIgnoreFile = new File(dockerFolder, ".dockerignore");
if (dockerIgnoreFile.exists()) {
int lineNumber = 0;
List<String> dockerIgnoreFileContent = FileUtils
.readLines(dockerIgnoreFile);
for (String pattern : dockerIgnoreFileContent) {
lineNumber++;
pattern = pattern.trim();
if (pattern.isEmpty()) {
continue; // skip empty lines
}
pattern = FilenameUtils.normalize(pattern);
try {
// validate pattern and make sure we aren't excluding
// Dockerfile
if (GoLangFileMatch.match(pattern, "Dockerfile")) {
throw new DockerClientException(
String.format(
"Dockerfile is excluded by pattern '%s' on line %s in .dockerignore file",
pattern, lineNumber));
}
ignores.add(pattern);
} catch (GoLangFileMatchException e) {
throw new DockerClientException(
String.format(
"Invalid pattern '%s' on line %s in .dockerignore file",
pattern, lineNumber));
}
}
}
List<File> filesToAdd = new ArrayList<File>();
filesToAdd.add(dockerFile);

Map<String, String> environmentMap = new HashMap<String, String>();

int lineNumber = 0;

for (String cmd : dockerFileContent) {

lineNumber++;

if (cmd.trim().isEmpty() || cmd.startsWith("#"))
continue; // skip emtpy and commend lines

final Matcher envMatcher = ENV_PATTERN.matcher(cmd.trim());

if (envMatcher.find()) {
if (envMatcher.groupCount() != 2)
throw new DockerClientException(String.format(
"Wrong ENV format on line [%d]", lineNumber));

String variable = envMatcher.group(1).trim();

String value = envMatcher.group(2).trim();

environmentMap.put(variable, value);
}

final Matcher matcher = ADD_OR_COPY_PATTERN.matcher(cmd.trim());
if (matcher.find()) {
if (matcher.groupCount() != 3) {
throw new DockerClientException(String.format(
"Wrong ADD or COPY format on line [%d]",
lineNumber));
}

String extractedResource = matcher.group(2);

String resource = filterForEnvironmentVars(
extractedResource, environmentMap).trim();

if (isFileResource(resource)) {
File src = new File(resource);
if (!src.isAbsolute()) {
src = new File(dockerFolder, resource)
.getCanonicalFile();
} else {
throw new DockerClientException(String.format(
"Source file %s must be relative to %s",
src, dockerFolder));
}

// if (!src.exists()) {
// throw new DockerClientException(String.format(
// "Source file %s doesn't exist", src));
// }
if (src.isDirectory()) {
Collection<File> files = FileUtils.listFiles(src,
new GoLangMatchFileFilter(src, ignores),
TrueFileFilter.INSTANCE);
filesToAdd.addAll(files);
} else if (!src.exists()) {
filesToAdd.addAll(resolveWildcards(src, ignores));
} else if (!GoLangFileMatch.match(ignores,
CompressArchiveUtil.relativize(dockerFolder,
src))) {
filesToAdd.add(src);
} else {
throw new DockerClientException(
String.format(
"Source file %s is excluded by .dockerignore file",
src));
}
}
}
}

return CompressArchiveUtil.archiveTARFiles(dockerFolder,
filesToAdd, archiveNameWithOutExtension);
} catch (IOException ex) {
FileUtils.deleteQuietly(dockerFolderTar);
throw new DockerClientException(
"Error occurred while preparing Docker context folder.", ex);
}
}

private Collection<File> resolveWildcards(File file, List<String> ignores) {
List<File> filesToAdd = new ArrayList<File>();

File parent = file.getParentFile();
if (parent != null) {
if (parent.isDirectory()) {
Collection<File> files = FileUtils.listFiles(parent,
new GoLangMatchFileFilter(parent, ignores),
TrueFileFilter.INSTANCE);
filesToAdd.addAll(files);
} else {
filesToAdd.addAll(resolveWildcards(parent, ignores));
}
} else {
throw new DockerClientException(String.format(
"Source file %s doesn't exist", file));
}

return filesToAdd;
}

private String filterForEnvironmentVars(String extractedResource,
Map<String, String> environmentMap) {

if (environmentMap.size() > 0) {

String currentResourceContent = extractedResource;

for (Map.Entry<String, String> entry : environmentMap.entrySet()) {

String variable = entry.getKey();

String replacementValue = entry.getValue();

// handle: $VARIABLE case
currentResourceContent = currentResourceContent.replaceAll(
"\\$" + variable, replacementValue);

// handle ${VARIABLE} case
currentResourceContent = currentResourceContent.replaceAll(
"\\$\\{" + variable + "\\}", replacementValue);

}

return currentResourceContent;
} else
return extractedResource;
}

private static boolean isFileResource(String resource) {
URI uri;
try {
uri = new URI(resource);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
return uri.getScheme() == null || "file".equals(uri.getScheme());
}
}
Loading