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

Fix image pulling #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$script = <<SCRIPT
(
rpm -i https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
yum install -y -q autoconf automake btrfs-progs docker gettext-devel git libcgroup-tools libtool python-pip
yum install -y -q autoconf automake btrfs-progs docker gettext-devel git libcgroup-tools libtool python-pip jq

fallocate -l 10G ~/btrfs.img
mkdir /var/bocker
Expand All @@ -22,6 +22,9 @@ make
mv unshare /usr/bin/unshare
cd ..

curl -sL https://raw.githubusercontent.com/moby/moby/master/contrib/download-frozen-image-v2.sh -o /usr/bin/download-frozen-image-v2
chmod +x /usr/bin/download-frozen-image-v2

ln -s /vagrant/bocker /usr/bin/bocker

echo 1 > /proc/sys/net/ipv4/ip_forward
Expand Down
17 changes: 8 additions & 9 deletions bocker
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ function bocker_init() { #HELP Create an image from a directory:\nBOCKER init <d
}

function bocker_pull() { #HELP Pull an image from Docker Hub:\nBOCKER pull <name> <tag>
token="$(curl -sL -o /dev/null -D- -H 'X-Docker-Token: true' "https://index.docker.io/v1/repositories/$1/images" | tr -d '\r' | awk -F ': *' '$1 == "X-Docker-Token" { print $2 }')"
registry='https://registry-1.docker.io/v1'
id="$(curl -sL -H "Authorization: Token $token" "$registry/repositories/$1/tags/$2" | sed 's/"//g')"
[[ "${#id}" -ne 64 ]] && echo "No image named '$1:$2' exists" && exit 1
ancestry="$(curl -sL -H "Authorization: Token $token" "$registry/images/$id/ancestry")"
IFS=',' && ancestry=(${ancestry//[\[\] \"]/}) && IFS=' \n\t'; tmp_uuid="$(uuidgen)" && mkdir /tmp/"$tmp_uuid"
for id in "${ancestry[@]}"; do
curl -#L -H "Authorization: Token $token" "$registry/images/$id/layer" -o /tmp/"$tmp_uuid"/layer.tar
tar xf /tmp/"$tmp_uuid"/layer.tar -C /tmp/"$tmp_uuid" && rm /tmp/"$tmp_uuid"/layer.tar
tmp_uuid="$(uuidgen)" && mkdir /tmp/"$tmp_uuid"
download-frozen-image-v2 /tmp/"$tmp_uuid" "$1:$2" > /dev/null
rm -rf /tmp/"$tmp_uuid"/repositories
for tar in "$(jq '.[].Layers[]' --raw-output < /tmp/$tmp_uuid/manifest.json)"; do
tar xf /tmp/"$tmp_uuid"/$tar -C /tmp/"$tmp_uuid" && rm -rf /tmp/"$tmp_uuid"/$tar
done
for config in "$(jq '.[].Config' --raw-output < /tmp/$tmp_uuid/manifest.json)"; do
rm -f /tmp/"$tmp_uuid"/$config
done
echo "$1:$2" > /tmp/"$tmp_uuid"/img.source
bocker_init /tmp/"$tmp_uuid" && rm -rf /tmp/"$tmp_uuid"
Expand Down