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

Split cli into moby and linuxkit #1695

Merged
merged 1 commit into from Apr 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 22 additions & 15 deletions Makefile
@@ -1,5 +1,5 @@
.PHONY: default all
default: bin/moby
default: bin/moby bin/linuxkit
all: default

VERSION="0.0" # dummy for now
Expand All @@ -8,6 +8,7 @@ GIT_COMMIT=$(shell git rev-list -1 HEAD)
GO_COMPILE=linuxkit/go-compile:4513068d9a7e919e4ec42e2d7ee879ff5b95b7f5@sha256:bdfadbe3e4ec699ca45b67453662321ec270f2d1a1dbdbf09625776d3ebd68c5

MOBY?=bin/moby
LINUXKIT?=bin/linuxkit
GOOS=$(shell uname -s | tr '[:upper:]' '[:lower:]')
GOARCH=amd64
ifneq ($(GOOS),linux)
Expand All @@ -27,6 +28,13 @@ bin/moby: $(MOBY_DEPS) | bin
rm tmp_moby_bin.tar
touch $@

LINUXKIT_DEPS=$(wildcard src/cmd/linuxkit/*.go) Makefile vendor.conf
bin/linuxkit: $(LINUXKIT_DEPS) | bin
tar cf - vendor -C src/cmd/linuxkit . | docker run --rm --net=none --log-driver=none -i $(CROSS) $(GO_COMPILE) --package github.com/linuxkit/linuxkit --ldflags "-X main.GitCommit=$(GIT_COMMIT) -X main.Version=$(VERSION)" -o $@ > tmp_linuxkit_bin.tar
tar xf tmp_linuxkit_bin.tar > $@
rm tmp_linuxkit_bin.tar
touch $@

INFRAKIT_DEPS=$(wildcard src/cmd/infrakit-instance-hyperkit/*.go) Makefile vendor.conf
bin/infrakit-instance-hyperkit: $(INFRAKIT_DEPS) | bin
tar cf - vendor -C src/cmd/infrakit-instance-hyperkit . | docker run --rm --net=none --log-driver=none -i $(CROSS) $(GO_COMPILE) --package github.com/linuxkit/linuxkit -o $@ > tmp_infrakit_instance_hyperkit_bin.tar
Expand All @@ -35,14 +43,13 @@ bin/infrakit-instance-hyperkit: $(INFRAKIT_DEPS) | bin
touch $@

test-initrd.img: $(MOBY) test/test.yml
bin/moby build test/test.yml
$(MOBY) build test/test.yml

test-bzImage: test-initrd.img

# interactive versions need to use volume mounts
.PHONY: test-qemu-efi
test-qemu-efi: test-efi.iso
$(MOBY) run $^ | tee test-efi.log
test-qemu-efi: $(LINUXKIT) test-efi.iso
$(LINUXKIT) run $^ | tee test-efi.log
$(call check_test_log, test-efi.log)

bin:
Expand All @@ -56,29 +63,29 @@ define check_test_log
endef

.PHONY: test-hyperkit
test-hyperkit: $(MOBY) test-initrd.img test-bzImage test-cmdline
test-hyperkit: $(LINUXKIT) test-initrd.img test-bzImage test-cmdline
rm -f disk.img
$(MOBY) run test | tee test.log
$(LINUXKIT) run test | tee test.log
$(call check_test_log, test.log)

.PHONY: test-gcp
test-gcp: $(MOBY) test.img.tar.gz
$(MOBY) push gcp test.img.tar.gz
$(MOBY) run gcp test | tee test-gcp.log
test-gcp: $(LINUXKIT) test.img.tar.gz
$(LINUXKIT) push gcp test.img.tar.gz
$(LINUXKIT) run gcp test | tee test-gcp.log
$(call check_test_log, test-gcp.log)

.PHONY: test
test: test-initrd.img test-bzImage test-cmdline
$(MOBY) run test | tee test.log
test: $(LINUXKIT) test-initrd.img test-bzImage test-cmdline
$(LINUXKIT) run test | tee test.log
$(call check_test_log, test.log)

test-ltp.img.tar.gz: $(MOBY) test/ltp/test-ltp.yml
$(MOBY) build test/ltp/test-ltp.yml

.PHONY: test-ltp
test-ltp: $(MOBY) test-ltp.img.tar.gz
$(MOBY) push gcp test-ltp.img.tar.gz
$(MOBY) run gcp -skip-cleanup -machine n1-highcpu-4 test-ltp | tee test-ltp.log
test-ltp: $(LINUXKIT) test-ltp.img.tar.gz
$(LINUXKIT) push gcp test-ltp.img.tar.gz
$(LINUXKIT) run gcp -skip-cleanup -machine n1-highcpu-4 test-ltp | tee test-ltp.log
$(call check_test_log, test-ltp.log)

.PHONY: ci ci-tag ci-pr
Expand Down
24 changes: 12 additions & 12 deletions README.md
Expand Up @@ -15,17 +15,20 @@ LinuxKit, a toolkit for building custom minimal, immutable Linux distributions.

## Getting Started

### Build the `moby` tool
### Build the `moby` and `linuxkit` tools
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a brief explanation of the difference between the linuxkit and moby tools? I realize we'll continue to shuffle things around but might be helpful in the intermediate stage

Copy link
Collaborator

@deitch deitch Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still am trying to wrap my head around it. Is the short form: moby is a tool for building images, and linuxkit is a tool for pushing and running images? So moby == docker build and linuxkit == docker run / docker push?

And if so... why? What do we gain by having 2 distinct tools?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. And the moby tool will be moved and extended to build assemblies other than linux images. This was discussed at length at DockerCon and various meetings after. I'm not sure there is a good writeup yet


Simple build instructions: use `make` to build. This will build the customisation tool in `bin/`. Add this
to your `PATH` or copy it to somewhere in your `PATH` eg `sudo cp bin/moby /usr/local/bin/`. Or you can use `sudo make install`.
LinuxKit uses the `moby` tool for image builds, and the `linuxkit` tool for pushing and running VM images.

Simple build instructions: use `make` to build. This will build the tools in `bin/`. Add this
to your `PATH` or copy it to somewhere in your `PATH` eg `sudo cp bin/* /usr/local/bin/`. Or you can use `sudo make install`.

If you already have `go` installed you can use `go get -u github.com/linuxkit/linuxkit/src/cmd/moby` to install
the `moby` tool. You can use `go get -u github.com/linuxkit/linuxkit/src/cmd/infrakit-instance-hyperkit`
the `moby` build tool, and `go get -u github.com/linuxkit/linuxkit/src/cmd/linuxkit` to install the `linuxkit` tool.
You can use `go get -u github.com/linuxkit/linuxkit/src/cmd/infrakit-instance-hyperkit`
to get the hyperkit infrakit tool.

Once you have built the tool, use `moby build linuxkit.yml` to build the example configuration,
and `bin/moby run linuxkit` to run locally. Use `halt` to terminate on the console.
and `linuxkit run linuxkit` to run locally. Use `halt` to terminate on the console.

Build requirements:
- GNU `make`
Expand All @@ -34,24 +37,21 @@ Build requirements:

### Booting and Testing

You can use `moby run <name>` to execute the image you created with `moby build <name>.yml`.
You can use `linuxkit run <name>` to execute the image you created with `moby build <name>.yml`.
This will use a suitable backend for your platform or you can choose one, for example VMWare.
See `moby run --help`.

Some platforms do not yet have `moby run` support, so you can use `./scripts/qemu.sh moby-initrd.img moby-bzImage moby-cmdline`
or `./scripts/qemu.sh mobylinux-bios.iso` which runs qemu in a Docker container.
See `linuxkit run --help`.

`make test` or `make test-hyperkit` will run the test suite

There are also docs for booting on [Google Cloud](docs/gcp.md); `./bin/moby run --gcp <name>.yml` should
There are also docs for booting on [Google Cloud](docs/gcp.md); `linuxkit push gcp <name> && linuxkit run gcp <name>.yml` should
work if you specified a GCP image to be built in the config.

More detailed docs will be available shortly, for running both single hosts and clusters.

## Building your own customised image

To customise, copy or modify the [`linuxkit.yml`](linuxkit.yml) to your own `file.yml` or use one of the [examples](examples/) and then run `moby build file.yml` to
generate its specified output. You can run the output with `moby run file`.
generate its specified output. You can run the output with `linuxkit run file`.

The yaml file specifies a kernel and base init system, a set of containers that are built into the generated image and started at boot time. It also specifies what
formats to output, such as bootable ISOs and images for various platforms.
Expand Down
File renamed without changes.
95 changes: 95 additions & 0 deletions src/cmd/linuxkit/main.go
@@ -0,0 +1,95 @@
package main

import (
"flag"
"fmt"
"os"
"path/filepath"

log "github.com/Sirupsen/logrus"
)

var (
defaultLogFormatter = &log.TextFormatter{}

// Version is the human-readable version
Version = "unknown"

// GitCommit hash, set at compile time
GitCommit = "unknown"
)

// infoFormatter overrides the default format for Info() log events to
// provide an easier to read output
type infoFormatter struct {
}

func (f *infoFormatter) Format(entry *log.Entry) ([]byte, error) {
if entry.Level == log.InfoLevel {
return append([]byte(entry.Message), '\n'), nil
}
return defaultLogFormatter.Format(entry)
}

func version() {
fmt.Printf("%s version %s\n", filepath.Base(os.Args[0]), Version)
fmt.Printf("commit: %s\n", GitCommit)
os.Exit(0)
}

func main() {
flag.Usage = func() {
fmt.Printf("USAGE: %s [options] COMMAND\n\n", filepath.Base(os.Args[0]))
fmt.Printf("Commands:\n")
fmt.Printf(" push Push a VM image to a cloud or image store\n")
fmt.Printf(" run Run a VM image on a local hypervisor or remote cloud\n")
fmt.Printf(" version Print version information\n")
fmt.Printf(" help Print this message\n")
fmt.Printf("\n")
fmt.Printf("Run '%s COMMAND --help' for more information on the command\n", filepath.Base(os.Args[0]))
fmt.Printf("\n")
fmt.Printf("Options:\n")
flag.PrintDefaults()
}
flagQuiet := flag.Bool("q", false, "Quiet execution")
flagVerbose := flag.Bool("v", false, "Verbose execution")

// Set up logging
log.SetFormatter(new(infoFormatter))
log.SetLevel(log.InfoLevel)
flag.Parse()
if *flagQuiet && *flagVerbose {
fmt.Printf("Can't set quiet and verbose flag at the same time\n")
os.Exit(1)
}
if *flagQuiet {
log.SetLevel(log.ErrorLevel)
}
if *flagVerbose {
// Switch back to the standard formatter
log.SetFormatter(defaultLogFormatter)
log.SetLevel(log.DebugLevel)
}

args := flag.Args()
if len(args) < 1 {
fmt.Printf("Please specify a command.\n\n")
flag.Usage()
os.Exit(1)
}

switch args[0] {
case "push":
push(args[1:])
case "run":
run(args[1:])
case "version":
version()
case "help":
flag.Usage()
default:
fmt.Printf("%q is not valid command.\n\n", args[0])
flag.Usage()
os.Exit(1)
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 0 additions & 6 deletions src/cmd/moby/main.go
Expand Up @@ -42,8 +42,6 @@ func main() {
fmt.Printf("USAGE: %s [options] COMMAND\n\n", filepath.Base(os.Args[0]))
fmt.Printf("Commands:\n")
fmt.Printf(" build Build a Moby image from a YAML file\n")
fmt.Printf(" push Push a VM image to a cloud or image store\n")
fmt.Printf(" run Run a VM image on a local hypervisor or remote cloud\n")
fmt.Printf(" version Print version information\n")
fmt.Printf(" help Print this message\n")
fmt.Printf("\n")
Expand Down Expand Up @@ -82,10 +80,6 @@ func main() {
switch args[0] {
case "build":
build(args[1:])
case "push":
push(args[1:])
case "run":
run(args[1:])
case "version":
version()
case "help":
Expand Down