mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 09:16:29 +00:00
Split cli into moby and linuxkit
moby just does the simple `build` cases, while `linuxkit` does `push` and `run`. Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
parent
fe29a90c3d
commit
6f80f664ce
37
Makefile
37
Makefile
@ -1,5 +1,5 @@
|
||||
.PHONY: default all
|
||||
default: bin/moby
|
||||
default: bin/moby bin/linuxkit
|
||||
all: default
|
||||
|
||||
VERSION="0.0" # dummy for now
|
||||
@ -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)
|
||||
@ -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
|
||||
@ -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:
|
||||
@ -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
|
||||
|
24
README.md
24
README.md
@ -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
|
||||
|
||||
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`
|
||||
@ -34,16 +37,13 @@ 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.
|
||||
@ -51,7 +51,7 @@ More detailed docs will be available shortly, for running both single hosts and
|
||||
## 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.
|
||||
|
95
src/cmd/linuxkit/main.go
Normal file
95
src/cmd/linuxkit/main.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
@ -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")
|
||||
@ -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":
|
||||
|
Loading…
Reference in New Issue
Block a user