mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-20 01:29:07 +00:00
verbosity for pkg build and error catching
Signed-off-by: Avi Deitcher <avi@deitcher.net>
This commit is contained in:
parent
56a05f628f
commit
bc5084df99
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -126,7 +126,7 @@ jobs:
|
|||||||
- name: Build Packages
|
- name: Build Packages
|
||||||
# Skip s390x as emulation is unreliable
|
# Skip s390x as emulation is unreliable
|
||||||
run: |
|
run: |
|
||||||
make OPTIONS="--skip-platforms linux/s390x" -C pkg build
|
make OPTIONS="-v --skip-platforms linux/s390x" -C pkg build
|
||||||
|
|
||||||
test_packages:
|
test_packages:
|
||||||
name: Packages Tests
|
name: Packages Tests
|
||||||
|
5
src/cmd/linuxkit/cache/write.go
vendored
5
src/cmd/linuxkit/cache/write.go
vendored
@ -13,7 +13,7 @@ import (
|
|||||||
"github.com/containerd/containerd/reference"
|
"github.com/containerd/containerd/reference"
|
||||||
"github.com/google/go-containerregistry/pkg/authn"
|
"github.com/google/go-containerregistry/pkg/authn"
|
||||||
"github.com/google/go-containerregistry/pkg/name"
|
"github.com/google/go-containerregistry/pkg/name"
|
||||||
"github.com/google/go-containerregistry/pkg/v1"
|
v1 "github.com/google/go-containerregistry/pkg/v1"
|
||||||
"github.com/google/go-containerregistry/pkg/v1/layout"
|
"github.com/google/go-containerregistry/pkg/v1/layout"
|
||||||
"github.com/google/go-containerregistry/pkg/v1/match"
|
"github.com/google/go-containerregistry/pkg/v1/match"
|
||||||
"github.com/google/go-containerregistry/pkg/v1/partial"
|
"github.com/google/go-containerregistry/pkg/v1/partial"
|
||||||
@ -200,6 +200,9 @@ func (p *Provider) ImageLoad(ref *reference.Spec, architecture string, r io.Read
|
|||||||
func (p *Provider) IndexWrite(ref *reference.Spec, descriptors ...v1.Descriptor) (lktspec.ImageSource, error) {
|
func (p *Provider) IndexWrite(ref *reference.Spec, descriptors ...v1.Descriptor) (lktspec.ImageSource, error) {
|
||||||
image := ref.String()
|
image := ref.String()
|
||||||
log.Debugf("writing an index for %s", image)
|
log.Debugf("writing an index for %s", image)
|
||||||
|
if len(descriptors) < 1 {
|
||||||
|
return ImageSource{}, errors.New("cannot create index without any manifests")
|
||||||
|
}
|
||||||
|
|
||||||
ii, err := p.cache.ImageIndex()
|
ii, err := p.cache.ImageIndex()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -4,11 +4,10 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
stdlog "log"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
ggcrlog "github.com/google/go-containerregistry/pkg/logs"
|
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/util"
|
||||||
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/version"
|
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/version"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -86,31 +85,13 @@ func main() {
|
|||||||
fmt.Printf("Options:\n")
|
fmt.Printf("Options:\n")
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
}
|
}
|
||||||
flagQuiet := flag.Bool("q", false, "Quiet execution")
|
|
||||||
flagVerbose := flag.Bool("v", false, "Verbose execution")
|
|
||||||
|
|
||||||
readConfig()
|
readConfig()
|
||||||
|
|
||||||
// Set up logging
|
// Set up logging
|
||||||
log.SetFormatter(new(infoFormatter))
|
util.AddLoggingFlags(nil)
|
||||||
log.SetLevel(log.InfoLevel)
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if *flagQuiet && *flagVerbose {
|
util.SetupLogging()
|
||||||
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)
|
|
||||||
// set go-containerregistry logging as well
|
|
||||||
ggcrlog.Warn = stdlog.New(log.StandardLogger().WriterLevel(log.WarnLevel), "", 0)
|
|
||||||
ggcrlog.Debug = stdlog.New(log.StandardLogger().WriterLevel(log.DebugLevel), "", 0)
|
|
||||||
}
|
|
||||||
ggcrlog.Progress = stdlog.New(log.StandardLogger().WriterLevel(log.InfoLevel), "", 0)
|
|
||||||
|
|
||||||
args := flag.Args()
|
args := flag.Args()
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
|
@ -102,8 +102,12 @@ func NewFromCLI(fs *flag.FlagSet, args ...string) ([]Pkg, error) {
|
|||||||
fs.BoolVar(&dirty, "force-dirty", false, "Force the pkg(s) to be considered dirty")
|
fs.BoolVar(&dirty, "force-dirty", false, "Force the pkg(s) to be considered dirty")
|
||||||
fs.BoolVar(&devMode, "dev", false, "Force org and hash to $USER and \"dev\" respectively")
|
fs.BoolVar(&devMode, "dev", false, "Force org and hash to $USER and \"dev\" respectively")
|
||||||
|
|
||||||
|
util.AddLoggingFlags(fs)
|
||||||
|
|
||||||
_ = fs.Parse(args)
|
_ = fs.Parse(args)
|
||||||
|
|
||||||
|
util.SetupLogging()
|
||||||
|
|
||||||
if fs.NArg() < 1 {
|
if fs.NArg() < 1 {
|
||||||
return nil, fmt.Errorf("At least one pkg directory is required")
|
return nil, fmt.Errorf("At least one pkg directory is required")
|
||||||
}
|
}
|
||||||
|
68
src/cmd/linuxkit/util/flags.go
Normal file
68
src/cmd/linuxkit/util/flags.go
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
stdlog "log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
ggcrlog "github.com/google/go-containerregistry/pkg/logs"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
defaultLogFormatter = &log.TextFormatter{}
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
flagQuiet, flagVerbose *bool
|
||||||
|
)
|
||||||
|
|
||||||
|
// AddLoggingFlags add the logging flags to a flagset, or, if none given,
|
||||||
|
// the default flag package
|
||||||
|
func AddLoggingFlags(fs *flag.FlagSet) {
|
||||||
|
// if we have no flagset, add it to the default flag package
|
||||||
|
if fs == nil {
|
||||||
|
flagQuiet = flag.Bool("q", false, "Quiet execution")
|
||||||
|
flagVerbose = flag.Bool("v", false, "Verbose execution")
|
||||||
|
} else {
|
||||||
|
flagQuiet = fs.Bool("q", false, "Quiet execution")
|
||||||
|
flagVerbose = fs.Bool("v", false, "Verbose execution")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetupLogging once the flags have been parsed, setup the logging
|
||||||
|
func SetupLogging() {
|
||||||
|
// 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)
|
||||||
|
// set go-containerregistry logging as well
|
||||||
|
ggcrlog.Warn = stdlog.New(log.StandardLogger().WriterLevel(log.WarnLevel), "", 0)
|
||||||
|
ggcrlog.Debug = stdlog.New(log.StandardLogger().WriterLevel(log.DebugLevel), "", 0)
|
||||||
|
}
|
||||||
|
ggcrlog.Progress = stdlog.New(log.StandardLogger().WriterLevel(log.InfoLevel), "", 0)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user