Skip to content

Commit

Permalink
Merge pull request #3 from robinmonjo/v2-registry-support
Browse files Browse the repository at this point in the history
V2 registry support
  • Loading branch information
robinmonjo committed Feb 15, 2015
2 parents 43dcc3d + 798851b commit b1dd546
Show file tree
Hide file tree
Showing 21 changed files with 706 additions and 292 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ rootfs
.vagrant
vendor
release
cargo
krgo
15 changes: 7 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
GOPATH:=`pwd`/vendor:$(GOPATH) #inject vendored package
GOPATH:=`pwd`/vendor/src/github.com/docker/docker/vendor:$(GOPATH) #inject docker vendored package

VERSION:=1.4.1
VERSION:=1.5.0
HARDWARE=$(shell uname -m)

build: vendor
GOPATH=$(GOPATH) go build

test: vendor
GOPATH=$(GOPATH) go install
GOPATH=$(GOPATH) go test
test: vendor build
GOPATH=$(GOPATH) PATH=$(PATH):`pwd` go test

release:
mkdir -p release
GOPATH=$(GOPATH) GOOS=linux go build -o release/cargo
cd release && tar -zcf cargo-v$(VERSION)_$(HARDWARE).tgz cargo
rm release/cargo
GOPATH=$(GOPATH) GOOS=linux go build -o release/krgo
cd release && tar -zcf krgo-v$(VERSION)_$(HARDWARE).tgz krgo
rm release/krgo

clean:
rm -rf ./cargo ./rootfs ./release
rm -rf ./krgo ./release ./vendor/pkg/*

vendor:
sh vendor.sh
80 changes: 49 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#cargo
> krgo was formerly [dlrootfs](https://github.com/robinmonjo/dlrootfs) and cargo but has been renamed because of this [issue]()
> cargo was formerly [dlrootfs](https://github.com/robinmonjo/dlrootfs)
#krgo

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

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

##Why cargo ?
##Why krgo ?

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

##Installation

````bash
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 -
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 -
````

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

##Usage

````
NAME:
cargo - docker hub without docker
krgo - docker hub without docker
USAGE:
cargo [global options] command [command options] [arguments...]
krgo [global options] command [command options] [arguments...]
VERSION:
1.4.0
krgo 1.5.0 (docker 1.5.0)
COMMANDS:
pull pull an image
push push an image
commit commit changes to an image pulled with -g
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version
````

###cargo pull
###krgo pull

`cargo pull image [-r rootfs] [-u user] [-g]`
`krgo pull image [-r rootfs] [-u user] [-g] [-v2]`

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

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

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

The `-g` flag brings the power of git to container images (versionning, inspecting diffs ...). But more importantly, it will allow to
push image modifications to the docker hub (see `cargo push`)
push image modifications to the docker hub (see `krgo push`)

- `-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

**Examples**:
- `cargo pull debian` #library/debian:latest
- `cargo pull progrium/busybox -r busybox -g`
- `cargo pull robinmonjo/debian:latest -r debian -u $DHUB_CREDS`
- `krgo pull debian -v2 #library/debian:latest using v2 registry`
- `krgo pull progrium/busybox -r busybox -g`
- `krgo pull robinmonjo/debian:latest -r debian -u $DHUB_CREDS`

###cargo push
###krgo push

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

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

`cargo commit [-r rootfs] -m "commit message"`
`krgo commit [-r rootfs] -m "commit message"`

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

````bash
$> cargo commit -m "adding new user"
$> krgo commit -m "adding new user"
Changes commited in layer_4_804c37249306321b90bbfa07d7cfe02d5f3d056971eb069d7bc37647de484a35
Image ID: 804c37249306321b90bbfa07d7cfe02d5f3d056971eb069d7bc37647de484a35
Parent: 4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125
Checksum: tarsum.dev+sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Layer size: 1536
Done
````

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

`cargo push image [-r rootfs] -u username:password`
`krgo push image [-r rootfs] -u username:password`

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

**Examples:**
- `cargo push username/debian:cargo -u $DHUB_CREDS`
- `cargo push username/busybox -r busybox -u $DHUB_CREDS`
- `krgo push username/debian:krgo -u $DHUB_CREDS`
- `krgo push username/busybox -r busybox -u $DHUB_CREDS`

##Dependencies

If you plan to use `krgo` to push images, you will need git >= 1.8

##Notes on docker v2 registry

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:
- images are now addressed by content (IDs are tarsum calculation)
- images are described in a manifest
- images metadata are no more stored in a json file at the root of the file system

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.


##Hacking on cargo
##Hacking on krgo

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

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

##Resources

Expand Down
3 changes: 2 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "trusty64"
config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"

config.vm.synced_folder ".", "/vagrant/cargo"
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.synced_folder ".", "/vagrant/krgo"

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

Expand Down
16 changes: 5 additions & 11 deletions commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
"io/ioutil"
"os"
"path"
"strconv"
"time"

"github.com/docker/docker/image"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/tarsum"
"github.com/docker/docker/utils"
)

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

layerTarSum, err := tarsum.NewTarSum(layerData, true, tarsum.VersionDev)
if err != nil {
return err
}

//fill new infos
image.Checksum = layerTarSum.Sum(nil)
image.Parent = image.ID
image.ID = utils.GenerateRandomID()
image.Created = time.Now()
Expand Down Expand Up @@ -67,8 +61,8 @@ func commitChanges(rootfs, message string) error {
}

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

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

return nil
}
Loading

0 comments on commit b1dd546

Please sign in to comment.