Skip to content

Instantly share code, notes, and snippets.

@tianon
Last active August 29, 2015 13:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tianon/9129512 to your computer and use it in GitHub Desktop.
Save tianon/9129512 to your computer and use it in GitHub Desktop.
Testing "docker build" Remote API Endpoint Using Curl
{ echo 'FROM debian'; echo 'RUN apt-get update'; } | perl -w -MArchive::Tar -e 'my $tar = Archive::Tar->new; { local $/; $tar->add_data("Dockerfile", <>); } print $tar->write' | curl --data-binary @- --header 'Content-Type: application/x-tar' --dump-header - --no-buffer 'http://localhost:4243/build?rm=1&nocache=1'
{
echo 'FROM debian'
echo 'RUN apt-get update'
} | perl -w -MArchive::Tar -e '
my $tar = Archive::Tar->new;
{
local $/;
$tar->add_data("Dockerfile", <>);
}
print $tar->write;
' | curl \
--data-binary @- \
--header 'Content-Type: application/x-tar' \
--dump-header - \
--no-buffer \
'http://localhost:4243/build?rm=1&nocache=1'
$ python -c 'import tarfile, StringIO, sys; df = "FROM debian\nRUN apt-get update\n"; ti = tarfile.TarInfo("Dockerfile"); ti.size = len(df); tar = tarfile.open(fileobj=sys.stdout, mode="w|"); tar.addfile(ti, StringIO.StringIO(df)); tar.close()' | curl --data-binary @- --header 'Content-Type: application/x-tar' --dump-header - --no-buffer 'http://localhost:4243/build?rm=1&nocache=1'
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Content-Type: application/json
Date: Fri, 21 Feb 2014 06:45:46 GMT
Transfer-Encoding: chunked
{"stream":"Step 0 : FROM debian\n"}
{"stream":" ---\u003e b5fe16f2ccba\n"}
{"stream":"Step 1 : RUN apt-get update\n"}
{"stream":" ---\u003e Running in 11e487462df0\n"}
{"stream":"Get:1 http://security.debian.org wheezy/updates Release.gpg [836 B]\n"}
{"stream":"Get:2 http://security.debian.org wheezy/updates Release [102 kB]\n"}
{"stream":"Get:3 http://http.debian.net wheezy Release.gpg [1672 B]\n"}
{"stream":"Get:4 http://http.debian.net wheezy-updates Release.gpg [836 B]\n"}
{"stream":"Get:5 http://http.debian.net wheezy Release [168 kB]\n"}
{"stream":"Get:6 http://security.debian.org wheezy/updates/main amd64 Packages [161 kB]\n"}
{"stream":"Get:7 http://http.debian.net wheezy-updates Release [124 kB]\n"}
{"stream":"Get:8 http://http.debian.net wheezy/main amd64 Packages [5845 kB]\n"}
{"stream":"Get:9 http://http.debian.net wheezy-updates/main amd64 Packages/DiffIndex [643 B]\n"}
{"stream":"Get:10 http://http.debian.net wheezy-updates/main amd64 2014-02-15-1443.31.pdiff [547 B]\n"}
{"stream":"Get:11 http://http.debian.net wheezy-updates/main amd64 2014-02-15-1443.31.pdiff [547 B]\n"}
{"stream":"Fetched 6405 kB in 6s (1032 kB/s)\nReading package lists..."}
{"stream":"\n"}
{"stream":" ---\u003e bd2f5bcb0182\n"}
{"stream":"Successfully built bd2f5bcb0182\n"}
{"stream":"Removing intermediate container 11e487462df0\n"}
python -c 'import tarfile, StringIO, sys; df = "FROM debian\n"; ti = tarfile.TarInfo("Dockerfile"); ti.size = len(df); tar = tarfile.open(fileobj=sys.stdout, mode="w|"); tar.addfile(ti, StringIO.StringIO(df)); tar.close()' | curl --data-binary @- --header 'Content-Type: application/x-tar' --dump-header - --no-buffer http://localhost:4243/build
python -c '
if True: # added for the sake of indentation (so that this exploded version is actually readable)
import tarfile, StringIO, sys
df = "FROM debian\n"
ti = tarfile.TarInfo("Dockerfile")
ti.size = len(df)
tar = tarfile.open(fileobj=sys.stdout, mode="w|")
tar.addfile(ti, StringIO.StringIO(df))
tar.close()
' | curl \
--data-binary @- \
--header 'Content-Type: application/x-tar' \
--dump-header - \
--no-buffer \
http://localhost:4243/build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment