Skip to content

Commit b1dd546

Browse files
committed
Merge pull request #3 from robinmonjo/v2-registry-support
V2 registry support
2 parents 43dcc3d + 798851b commit b1dd546

21 files changed

+706
-292
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ rootfs
22
.vagrant
33
vendor
44
release
5-
cargo
5+
krgo

Makefile

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
GOPATH:=`pwd`/vendor:$(GOPATH) #inject vendored package
22
GOPATH:=`pwd`/vendor/src/github.com/docker/docker/vendor:$(GOPATH) #inject docker vendored package
33

4-
VERSION:=1.4.1
4+
VERSION:=1.5.0
55
HARDWARE=$(shell uname -m)
66

77
build: vendor
88
GOPATH=$(GOPATH) go build
99

10-
test: vendor
11-
GOPATH=$(GOPATH) go install
12-
GOPATH=$(GOPATH) go test
10+
test: vendor build
11+
GOPATH=$(GOPATH) PATH=$(PATH):`pwd` go test
1312

1413
release:
1514
mkdir -p release
16-
GOPATH=$(GOPATH) GOOS=linux go build -o release/cargo
17-
cd release && tar -zcf cargo-v$(VERSION)_$(HARDWARE).tgz cargo
18-
rm release/cargo
15+
GOPATH=$(GOPATH) GOOS=linux go build -o release/krgo
16+
cd release && tar -zcf krgo-v$(VERSION)_$(HARDWARE).tgz krgo
17+
rm release/krgo
1918

2019
clean:
21-
rm -rf ./cargo ./rootfs ./release
20+
rm -rf ./krgo ./release ./vendor/pkg/*
2221

2322
vendor:
2423
sh vendor.sh

README.md

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#cargo
1+
> krgo was formerly [dlrootfs](https://github.com/robinmonjo/dlrootfs) and cargo but has been renamed because of this [issue]()
22
3-
> cargo was formerly [dlrootfs](https://github.com/robinmonjo/dlrootfs)
3+
#krgo
44

5-
docker hub without docker. `cargo` is a command line tool to pull and push docker images from/to the docker hub.
6-
`cargo` brings the docker hub content and delivery capabilities to any container engine.
5+
docker hub without docker. `krgo` is a command line tool to pull and push docker images from/to the docker hub.
6+
`krgo` brings the docker hub content and delivery capabilities to any container engine.
77

88
[Read the launch article and how to](https://gist.github.com/robinmonjo/f6ca0f85a204c8103e10)
99

10-
##Why cargo ?
10+
##Why krgo ?
1111

1212
docker is really popular and a lot of people and organisations are building docker images. These images are stored
1313
and shared on the docker hub. However they are only available to docker users. Metadata apart, a docker
@@ -17,100 +17,118 @@ image is a linux root file system that can be used with any container engine
1717
[systemd-nspawn](http://www.freedesktop.org/software/systemd/man/systemd-nspawn.html),
1818
[rocket](https://github.com/coreos/rocket)
1919
...).
20-
Using `cargo`, non docker users would be able to pull and share linux images using the [docker hub](https://hub.docker.com/).
20+
Using `krgo`, non docker users would be able to pull and share linux images using the [docker hub](https://hub.docker.com/).
2121

2222
##Installation
2323

2424
````bash
25-
curl -sL https://github.com/robinmonjo/cargo/releases/download/v1.4.1/cargo-v1.4.1_x86_64.tgz | tar -C /usr/local/bin -zxf -
25+
curl -sL https://github.com/robinmonjo/krgo/releases/download/v1.5.0/krgo-v1.4.1_x86_64.tgz | tar -C /usr/local/bin -zxf -
2626
````
2727

28-
Provided binary is linux only but `cargo` may be used on OSX and (probably) Windows too.
28+
Provided binary is linux only but `krgo` may be used on OSX and (probably) Windows too.
2929

3030
##Usage
3131

3232
````
3333
NAME:
34-
cargo - docker hub without docker
34+
krgo - docker hub without docker
3535
3636
USAGE:
37-
cargo [global options] command [command options] [arguments...]
37+
krgo [global options] command [command options] [arguments...]
3838
3939
VERSION:
40-
1.4.0
40+
krgo 1.5.0 (docker 1.5.0)
4141
4242
COMMANDS:
4343
pull pull an image
4444
push push an image
4545
commit commit changes to an image pulled with -g
4646
help, h Shows a list of commands or help for one command
47+
48+
GLOBAL OPTIONS:
49+
--help, -h show help
50+
--version, -v print the version
4751
````
4852

49-
###cargo pull
53+
###krgo pull
5054

51-
`cargo pull image [-r rootfs] [-u user] [-g]`
55+
`krgo pull image [-r rootfs] [-u user] [-g] [-v2]`
5256

5357
Pull `image` into `rootfs` directory:
5458
- `-u` flag allows you to specify your docker hub credentials: `username:password`
5559
- `-g` flag download the image into a git repository. Each branch contains a layer
56-
of the image. This is the resulting rootfs of `cargo pull busybox -g`:
60+
of the image. This is the resulting rootfs of `krgo pull busybox -g`:
5761

58-
![Alt text](https://dl.dropboxusercontent.com/u/6543817/cargo-readme/cargo_br.png)
62+
![Alt text](https://dl.dropboxusercontent.com/u/6543817/krgo-readme/krgo_br.png)
5963

6064
Branches are named `layer_<layer_index>_<layer_id>`. layer_n is a `checkout -b` from layer_n-1, so
6165
the layer_3 branch contains the full image. You can then use it as is.
6266

6367
The `-g` flag brings the power of git to container images (versionning, inspecting diffs ...). But more importantly, it will allow to
64-
push image modifications to the docker hub (see `cargo push`)
68+
push image modifications to the docker hub (see `krgo push`)
69+
70+
- `-v2` flag makes `krgo` download the image using docker [v2 registry](https://github.com/docker/docker-registry/issues/612). Because everything is not yet production ready, images pulled with the `-v2` flag won't be pushable to the docker hub
6571

6672
**Examples**:
67-
- `cargo pull debian` #library/debian:latest
68-
- `cargo pull progrium/busybox -r busybox -g`
69-
- `cargo pull robinmonjo/debian:latest -r debian -u $DHUB_CREDS`
73+
- `krgo pull debian -v2 #library/debian:latest using v2 registry`
74+
- `krgo pull progrium/busybox -r busybox -g`
75+
- `krgo pull robinmonjo/debian:latest -r debian -u $DHUB_CREDS`
7076

71-
###cargo push
77+
###krgo push
7278

7379
Push an image downloaded with the `-g` option to the docker hub
7480
(a [docker hub account](https://hub.docker.com/account/signup/) is needed).
7581

7682
In order to push your modification you **must commit** them beforehand:
7783

78-
`cargo commit [-r rootfs] -m "commit message"`
84+
`krgo commit [-r rootfs] -m "commit message"`
7985

8086
This will take every changes on the current branch, and commit them onto a new branch.
8187
The new branch will be properly named and some additional metadata will be written, so
8288
this new layer can be pushed:
8389

8490
````bash
85-
$> cargo commit -m "adding new user"
91+
$> krgo commit -m "adding new user"
8692
Changes commited in layer_4_804c37249306321b90bbfa07d7cfe02d5f3d056971eb069d7bc37647de484a35
8793
Image ID: 804c37249306321b90bbfa07d7cfe02d5f3d056971eb069d7bc37647de484a35
8894
Parent: 4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125
89-
Checksum: tarsum.dev+sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
9095
Layer size: 1536
9196
Done
9297
````
9398

94-
If you plan to use `cargo push`, branches should not be created manually and commit must be done via `cargo`.
99+
If you plan to use `krgo push`, branches should not be created manually and commit must be done via `krgo`.
95100
Also, branches other than the last one should never be modified.
96101

97-
`cargo push image [-r rootfs] -u username:password`
102+
`krgo push image [-r rootfs] -u username:password`
98103

99104
Push the image in the `rootfs` directory onto the docker hub.
100105

101106
**Examples:**
102-
- `cargo push username/debian:cargo -u $DHUB_CREDS`
103-
- `cargo push username/busybox -r busybox -u $DHUB_CREDS`
107+
- `krgo push username/debian:krgo -u $DHUB_CREDS`
108+
- `krgo push username/busybox -r busybox -u $DHUB_CREDS`
109+
110+
##Dependencies
111+
112+
If you plan to use `krgo` to push images, you will need git >= 1.8
113+
114+
##Notes on docker v2 registry
115+
116+
docker 1.5.0 pulls official images (library/*) from the v2 registry. Push are still made using the v1 registry. v2 registry brings a lot of [changes](https://github.com/docker/docker-registry/issues/612), the most noticeable ones for `krgo` are:
117+
- images are now addressed by content (IDs are tarsum calculation)
118+
- images are described in a manifest
119+
- images metadata are no more stored in a json file at the root of the file system
120+
121+
A lot of layers in v1 where created only because the json metadata file changed. Since this file is no more distributed, some (all ?) images have "dulpicated empty layers". `krgo` clean the manifest to download only what's needed.
104122

105123

106-
##Hacking on cargo
124+
##Hacking on krgo
107125

108-
`cargo` directly uses some of docker source code. Docker is moving fast, and `cargo` must keep up.
126+
`krgo` directly uses some of docker source code. Docker is moving fast, and `krgo` must keep up.
109127
I will maintain it but if you want to contribute every pull requests / bug reports are welcome.
110128

111-
You don't need linux, `cargo` can run on OSX (Windows ?). Fork the repository and clone it into your
129+
You don't need linux, `krgo` can run on OSX (Windows ?). Fork the repository and clone it into your
112130
go workspace. Then `make vendor`, `make build` and you are ready to go. Tests can be run
113-
with `make test`. Note that most `cargo` command must be run as sudo.
131+
with `make test`. Note that most `krgo` command must be run as sudo.
114132

115133
##Resources
116134

Vagrantfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
88
config.vm.box = "trusty64"
99
config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
1010

11-
config.vm.synced_folder ".", "/vagrant/cargo"
11+
config.vm.synced_folder ".", "/vagrant", disabled: true
12+
config.vm.synced_folder ".", "/vagrant/krgo"
1213

1314
config.vm.provision "shell", path: "setup.sh"
1415

commit.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import (
66
"io/ioutil"
77
"os"
88
"path"
9-
"strconv"
109
"time"
1110

1211
"github.com/docker/docker/image"
1312
"github.com/docker/docker/pkg/archive"
14-
"github.com/docker/docker/pkg/tarsum"
1513
"github.com/docker/docker/utils"
1614
)
1715

16+
//krgo commit -r rootfs
17+
//commit current changes in a new properly formated branch ready for pushing
1818
func commitChanges(rootfs, message string) error {
1919
if !isGitRepo(rootfs) {
2020
return fmt.Errorf("%v not a git repository", rootfs)
@@ -33,13 +33,7 @@ func commitChanges(rootfs, message string) error {
3333
return err
3434
}
3535

36-
layerTarSum, err := tarsum.NewTarSum(layerData, true, tarsum.VersionDev)
37-
if err != nil {
38-
return err
39-
}
40-
4136
//fill new infos
42-
image.Checksum = layerTarSum.Sum(nil)
4337
image.Parent = image.ID
4438
image.ID = utils.GenerateRandomID()
4539
image.Created = time.Now()
@@ -67,8 +61,8 @@ func commitChanges(rootfs, message string) error {
6761
}
6862

6963
//commit the changes in a new branch
70-
brNumber, _ := gitRepo.countBranch()
71-
br := "layer_" + strconv.Itoa(brNumber) + "_" + image.ID
64+
n, _ := gitRepo.countBranch()
65+
br := newBranch(n, image.ID)
7266
if _, err = gitRepo.checkoutB(br); err != nil {
7367
return err
7468
}
@@ -77,7 +71,7 @@ func commitChanges(rootfs, message string) error {
7771
}
7872

7973
fmt.Printf("Changes commited in %v\n", br)
80-
fmt.Printf("Image ID: %v\nParent: %v\nChecksum: %v\nLayer size: %v\n", image.ID, image.Parent, image.Checksum, image.Size)
74+
fmt.Printf("Image ID: %v\nParent: %v\nChecksum: %v\nLayer size: %v\n", image.ID, image.Parent, image.Size)
8175

8276
return nil
8377
}

0 commit comments

Comments
 (0)