mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-20 01:29:07 +00:00
Merge pull request #1695 from justincormack/split-cli
Split cli into moby and linuxkit
This commit is contained in:
commit
b78b5a7449
37
Makefile
37
Makefile
@ -1,5 +1,5 @@
|
|||||||
.PHONY: default all
|
.PHONY: default all
|
||||||
default: bin/moby
|
default: bin/moby bin/linuxkit
|
||||||
all: default
|
all: default
|
||||||
|
|
||||||
VERSION="0.0" # dummy for now
|
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
|
GO_COMPILE=linuxkit/go-compile:4513068d9a7e919e4ec42e2d7ee879ff5b95b7f5@sha256:bdfadbe3e4ec699ca45b67453662321ec270f2d1a1dbdbf09625776d3ebd68c5
|
||||||
|
|
||||||
MOBY?=bin/moby
|
MOBY?=bin/moby
|
||||||
|
LINUXKIT?=bin/linuxkit
|
||||||
GOOS=$(shell uname -s | tr '[:upper:]' '[:lower:]')
|
GOOS=$(shell uname -s | tr '[:upper:]' '[:lower:]')
|
||||||
GOARCH=amd64
|
GOARCH=amd64
|
||||||
ifneq ($(GOOS),linux)
|
ifneq ($(GOOS),linux)
|
||||||
@ -27,6 +28,13 @@ bin/moby: $(MOBY_DEPS) | bin
|
|||||||
rm tmp_moby_bin.tar
|
rm tmp_moby_bin.tar
|
||||||
touch $@
|
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
|
INFRAKIT_DEPS=$(wildcard src/cmd/infrakit-instance-hyperkit/*.go) Makefile vendor.conf
|
||||||
bin/infrakit-instance-hyperkit: $(INFRAKIT_DEPS) | bin
|
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
|
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 $@
|
touch $@
|
||||||
|
|
||||||
test-initrd.img: $(MOBY) test/test.yml
|
test-initrd.img: $(MOBY) test/test.yml
|
||||||
bin/moby build test/test.yml
|
$(MOBY) build test/test.yml
|
||||||
|
|
||||||
test-bzImage: test-initrd.img
|
test-bzImage: test-initrd.img
|
||||||
|
|
||||||
# interactive versions need to use volume mounts
|
|
||||||
.PHONY: test-qemu-efi
|
.PHONY: test-qemu-efi
|
||||||
test-qemu-efi: test-efi.iso
|
test-qemu-efi: $(LINUXKIT) test-efi.iso
|
||||||
$(MOBY) run $^ | tee test-efi.log
|
$(LINUXKIT) run $^ | tee test-efi.log
|
||||||
$(call check_test_log, test-efi.log)
|
$(call check_test_log, test-efi.log)
|
||||||
|
|
||||||
bin:
|
bin:
|
||||||
@ -56,29 +63,29 @@ define check_test_log
|
|||||||
endef
|
endef
|
||||||
|
|
||||||
.PHONY: test-hyperkit
|
.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
|
rm -f disk.img
|
||||||
$(MOBY) run test | tee test.log
|
$(LINUXKIT) run test | tee test.log
|
||||||
$(call check_test_log, test.log)
|
$(call check_test_log, test.log)
|
||||||
|
|
||||||
.PHONY: test-gcp
|
.PHONY: test-gcp
|
||||||
test-gcp: $(MOBY) test.img.tar.gz
|
test-gcp: $(LINUXKIT) test.img.tar.gz
|
||||||
$(MOBY) push gcp test.img.tar.gz
|
$(LINUXKIT) push gcp test.img.tar.gz
|
||||||
$(MOBY) run gcp test | tee test-gcp.log
|
$(LINUXKIT) run gcp test | tee test-gcp.log
|
||||||
$(call check_test_log, test-gcp.log)
|
$(call check_test_log, test-gcp.log)
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: test-initrd.img test-bzImage test-cmdline
|
test: $(LINUXKIT) test-initrd.img test-bzImage test-cmdline
|
||||||
$(MOBY) run test | tee test.log
|
$(LINUXKIT) run test | tee test.log
|
||||||
$(call check_test_log, test.log)
|
$(call check_test_log, test.log)
|
||||||
|
|
||||||
test-ltp.img.tar.gz: $(MOBY) test/ltp/test-ltp.yml
|
test-ltp.img.tar.gz: $(MOBY) test/ltp/test-ltp.yml
|
||||||
$(MOBY) build test/ltp/test-ltp.yml
|
$(MOBY) build test/ltp/test-ltp.yml
|
||||||
|
|
||||||
.PHONY: test-ltp
|
.PHONY: test-ltp
|
||||||
test-ltp: $(MOBY) test-ltp.img.tar.gz
|
test-ltp: $(LINUXKIT) test-ltp.img.tar.gz
|
||||||
$(MOBY) push gcp test-ltp.img.tar.gz
|
$(LINUXKIT) push gcp test-ltp.img.tar.gz
|
||||||
$(MOBY) run gcp -skip-cleanup -machine n1-highcpu-4 test-ltp | tee test-ltp.log
|
$(LINUXKIT) run gcp -skip-cleanup -machine n1-highcpu-4 test-ltp | tee test-ltp.log
|
||||||
$(call check_test_log, test-ltp.log)
|
$(call check_test_log, test-ltp.log)
|
||||||
|
|
||||||
.PHONY: ci ci-tag ci-pr
|
.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
|
## 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
|
LinuxKit uses the `moby` tool for image builds, and the `linuxkit` tool for pushing and running VM images.
|
||||||
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`.
|
|
||||||
|
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
|
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.
|
to get the hyperkit infrakit tool.
|
||||||
|
|
||||||
Once you have built the tool, use `moby build linuxkit.yml` to build the example configuration,
|
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:
|
Build requirements:
|
||||||
- GNU `make`
|
- GNU `make`
|
||||||
@ -34,16 +37,13 @@ Build requirements:
|
|||||||
|
|
||||||
### Booting and Testing
|
### 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.
|
This will use a suitable backend for your platform or you can choose one, for example VMWare.
|
||||||
See `moby run --help`.
|
See `linuxkit 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.
|
|
||||||
|
|
||||||
`make test` or `make test-hyperkit` will run the test suite
|
`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.
|
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.
|
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
|
## 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
|
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
|
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.
|
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("USAGE: %s [options] COMMAND\n\n", filepath.Base(os.Args[0]))
|
||||||
fmt.Printf("Commands:\n")
|
fmt.Printf("Commands:\n")
|
||||||
fmt.Printf(" build Build a Moby image from a YAML file\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(" version Print version information\n")
|
||||||
fmt.Printf(" help Print this message\n")
|
fmt.Printf(" help Print this message\n")
|
||||||
fmt.Printf("\n")
|
fmt.Printf("\n")
|
||||||
@ -82,10 +80,6 @@ func main() {
|
|||||||
switch args[0] {
|
switch args[0] {
|
||||||
case "build":
|
case "build":
|
||||||
build(args[1:])
|
build(args[1:])
|
||||||
case "push":
|
|
||||||
push(args[1:])
|
|
||||||
case "run":
|
|
||||||
run(args[1:])
|
|
||||||
case "version":
|
case "version":
|
||||||
version()
|
version()
|
||||||
case "help":
|
case "help":
|
||||||
|
Loading…
Reference in New Issue
Block a user