Merge branch 'master' into add-disable-emoji-flag

This commit is contained in:
Sendil Kumar 2018-10-03 12:42:00 +02:00
Родитель 09669f558e 67f2463725
Коммит 148ed39e5b
4 изменённых файлов: 53 добавлений и 24 удалений

Просмотреть файл

@ -4,6 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -48,6 +49,7 @@ var (
dockerCertPath = os.Getenv("DOCKER_CERT_PATH") dockerCertPath = os.Getenv("DOCKER_CERT_PATH")
autoConnect bool autoConnect bool
skipImagePush bool skipImagePush bool
quiet bool
) )
type upCmd struct { type upCmd struct {
@ -115,13 +117,14 @@ func newUpCmd(out io.Writer) *cobra.Command {
f = cmd.Flags() f = cmd.Flags()
f.StringVarP(&runningEnvironment, environmentFlagName, environmentFlagShorthand, defaultDraftEnvironment(), environmentFlagUsage) f.StringVarP(&runningEnvironment, environmentFlagName, environmentFlagShorthand, defaultDraftEnvironment(), environmentFlagUsage)
f.BoolVar(&up.dockerClientOptions.Common.Debug, "docker-debug", false, "Enable debug mode") f.BoolVar(&up.dockerClientOptions.Common.Debug, "docker-debug", false, "enable debug mode")
f.StringVar(&up.dockerClientOptions.Common.LogLevel, "docker-log-level", "info", `Set the logging level ("debug"|"info"|"warn"|"error"|"fatal")`) f.StringVar(&up.dockerClientOptions.Common.LogLevel, "docker-log-level", "info", `set the logging level ("debug"|"info"|"warn"|"error"|"fatal")`)
f.BoolVar(&up.dockerClientOptions.Common.TLS, "docker-tls", defaultDockerTLS(), "Use TLS; implied by --tlsverify") f.BoolVar(&up.dockerClientOptions.Common.TLS, "docker-tls", defaultDockerTLS(), "use TLS; implied by --tlsverify")
f.BoolVar(&up.dockerClientOptions.Common.TLSVerify, fmt.Sprintf("docker-%s", dockerflags.FlagTLSVerify), defaultDockerTLSVerify(), "Use TLS and verify the remote") f.BoolVar(&up.dockerClientOptions.Common.TLSVerify, fmt.Sprintf("docker-%s", dockerflags.FlagTLSVerify), defaultDockerTLSVerify(), "use TLS and verify the remote")
f.StringVar(&up.dockerClientOptions.ConfigDir, "docker-config", cliconfig.Dir(), "Location of client config files") f.StringVar(&up.dockerClientOptions.ConfigDir, "docker-config", cliconfig.Dir(), "location of client config files")
f.BoolVarP(&autoConnect, "auto-connect", "", false, "specifies if draft up should automatically connect to the application") f.BoolVarP(&autoConnect, "auto-connect", "", false, "specifies if draft up should automatically connect to the application")
f.BoolVar(&skipImagePush, "skip-image-push", false, "skip pushing image to registry") f.BoolVar(&skipImagePush, "skip-image-push", false, "skip pushing image to registry")
f.BoolVarP(&quiet, "quiet", "q", false, "only output errors")
up.dockerClientOptions.Common.TLSOptions = &tlsconfig.Options{ up.dockerClientOptions.Common.TLSOptions = &tlsconfig.Options{
CAFile: filepath.Join(dockerCertPath, dockerflags.DefaultCaFile), CAFile: filepath.Join(dockerCertPath, dockerflags.DefaultCaFile),
@ -241,7 +244,17 @@ func (u *upCmd) run(environment string) (err error) {
// setup the storage engine // setup the storage engine
bldr.Storage = configmap.NewConfigMaps(bldr.Kube.CoreV1().ConfigMaps(tillerNamespace)) bldr.Storage = configmap.NewConfigMaps(bldr.Kube.CoreV1().ConfigMaps(tillerNamespace))
progressC := bldr.Up(ctx, buildctx) progressC := bldr.Up(ctx, buildctx)
cmdline.Display(ctx, buildctx.Env.Name, progressC, cmdline.WithBuildID(bldr.ID), cmdline.WithDisableEmoji(disableEmoji)) opts := []cmdline.Option{cmdline.WithBuildID(bldr.ID)}
if quiet {
opts = append(opts, cmdline.WithStdout(ioutil.Discard))
}
if disableEmoji {
opts = append(opts, cmdline.WithDisableEmoji(disableEmoji))
}
cmdline.Display(ctx, buildctx.Env.Name, progressC, opts...)
if buildctx.Env.AutoConnect || autoConnect { if buildctx.Env.AutoConnect || autoConnect {
c := newConnectCmd(u.out) c := newConnectCmd(u.out)

Просмотреть файл

@ -10,7 +10,7 @@ To compile and test Draft binaries and to build Docker images, you will need:
- a [Kubernetes][] cluster. We recommend [minikube][]. - a [Kubernetes][] cluster. We recommend [minikube][].
- [docker][] - [docker][]
- [git][] - [git][]
- [helm][], using the same version as recommended in the [installation guide][install]. - [helm][], see the [quickstart guide][quickstart] for installing helm
- [Go][] 1.8 or later, with support for compiling to `linux/amd64` - [Go][] 1.8 or later, with support for compiling to `linux/amd64`
In most cases, install the prerequisite according to its instructions. See the next section In most cases, install the prerequisite according to its instructions. See the next section
@ -85,10 +85,10 @@ $ make clean
[docker]: https://www.docker.com/ [docker]: https://www.docker.com/
[install]: ../install.md [quickstart]: ../quickstart.md#install-and-configure-helm
[git]: https://git-scm.com/ [git]: https://git-scm.com/
[go]: https://golang.org/ [go]: https://golang.org/
[helm]: https://github.com/kubernetes/helm [helm]: https://github.com/helm/helm
[Homebrew]: https://brew.sh/ [Homebrew]: https://brew.sh/
[Kubernetes]: https://github.com/kubernetes/kubernetes [Kubernetes]: https://github.com/kubernetes/kubernetes
[minikube]: https://github.com/kubernetes/minikube [minikube]: https://github.com/kubernetes/minikube

Просмотреть файл

@ -40,6 +40,8 @@ const (
PullSecretName = "draft-pullsecret" PullSecretName = "draft-pullsecret"
// DefaultServiceAccountName is the name of the default service account draft will modify with the imagepullsecret // DefaultServiceAccountName is the name of the default service account draft will modify with the imagepullsecret
DefaultServiceAccountName = "default" DefaultServiceAccountName = "default"
// DefaultDockerfile represents the default name of the Dockerfile if not specified in draft.toml
DefaultDockerfile = "Dockerfile"
) )
// Builder contains information about the build environment // Builder contains information about the build environment
@ -264,6 +266,9 @@ func loadValues(ctx *Context) error {
} }
func archiveSrc(ctx *Context) error { func archiveSrc(ctx *Context) error {
if ctx.Env.Dockerfile == "" {
ctx.Env.Dockerfile = DefaultDockerfile
}
dockerfilePath := filepath.Join(ctx.AppDir, ctx.Env.Dockerfile) dockerfilePath := filepath.Join(ctx.AppDir, ctx.Env.Dockerfile)
contextDir, relDockerfile, err := build.GetContextFromLocalDir(ctx.AppDir, dockerfilePath) contextDir, relDockerfile, err := build.GetContextFromLocalDir(ctx.AppDir, dockerfilePath)

Просмотреть файл

@ -86,8 +86,9 @@ func Display(ctx context.Context, app string, summaries <-chan *builder.Summary,
) )
ongoing := make(map[string]chan builder.SummaryStatusCode) ongoing := make(map[string]chan builder.SummaryStatusCode)
var ( var (
wg sync.WaitGroup wg sync.WaitGroup
id string id string
failed bool
) )
defer func() { defer func() {
for _, c := range ongoing { for _, c := range ongoing {
@ -95,7 +96,14 @@ func Display(ctx context.Context, app string, summaries <-chan *builder.Summary,
} }
cli.Stop() cli.Stop()
wg.Wait() wg.Wait()
fmt.Fprintf(cli.opts.stdout, "%s `%s`\n", blue("Inspect the logs with"), yellow("draft logs ", id))
logText := fmt.Sprintf("%s `%s`\n", blue("Inspect the logs with"), yellow("draft logs ", id))
if failed {
fmt.Fprintf(cli.opts.stderr, logText)
} else {
fmt.Fprintf(cli.opts.stdout, logText)
}
}() }()
for { for {
select { select {
@ -106,6 +114,9 @@ func Display(ctx context.Context, app string, summaries <-chan *builder.Summary,
if id == "" { if id == "" {
id = summary.BuildID id = summary.BuildID
} }
if summary.StatusCode == builder.SummaryFailure {
failed = true
}
if ch, ok := ongoing[summary.StageDesc]; !ok { if ch, ok := ongoing[summary.StageDesc]; !ok {
ch = make(chan builder.SummaryStatusCode, 1) ch = make(chan builder.SummaryStatusCode, 1)
ongoing[summary.StageDesc] = ch ongoing[summary.StageDesc] = ch
@ -126,10 +137,21 @@ func Display(ctx context.Context, app string, summaries <-chan *builder.Summary,
func progress(cli *cmdline, app, desc string, codes <-chan builder.SummaryStatusCode) { func progress(cli *cmdline, app, desc string, codes <-chan builder.SummaryStatusCode) {
start := time.Now() start := time.Now()
done := make(chan string, 1) done := make(chan builder.SummaryStatusCode, 1)
go func() { go func() {
defer close(done) defer close(done)
for code := range codes { for code := range codes {
if code == builder.SummarySuccess || code == builder.SummaryFailure {
done <- code
}
}
}()
m := fmt.Sprintf("%s: %s", cyan(app), yellow(desc))
s := `-\|/-`
i := 0
for {
select {
case code := <-done:
switch code { switch code {
case builder.SummarySuccess: case builder.SummarySuccess:
done <- fmt.Sprintf("%s: %s (%.4fs)\n", cyan(app), passStr(desc, cli.opts.disableEmoji), time.Since(start).Seconds()) done <- fmt.Sprintf("%s: %s (%.4fs)\n", cyan(app), passStr(desc, cli.opts.disableEmoji), time.Since(start).Seconds())
@ -138,17 +160,6 @@ func progress(cli *cmdline, app, desc string, codes <-chan builder.SummaryStatus
done <- fmt.Sprintf("%s: %s (%.4fs)\n", cyan(app), failStr(desc, cli.opts.disableEmoji), time.Since(start).Seconds()) done <- fmt.Sprintf("%s: %s (%.4fs)\n", cyan(app), failStr(desc, cli.opts.disableEmoji), time.Since(start).Seconds())
return return
} }
}
done <- "\n"
}()
m := fmt.Sprintf("%s: %s", cyan(app), yellow(desc))
s := `-\|/-`
i := 0
for {
select {
case msg := <-done:
fmt.Fprintf(cli.opts.stdout, "\r%s", msg)
return
default: default:
fmt.Fprintf(cli.opts.stdout, "\r%s %c", m, s[i%len(s)]) fmt.Fprintf(cli.opts.stdout, "\r%s %c", m, s[i%len(s)])
time.Sleep(50 * time.Millisecond) time.Sleep(50 * time.Millisecond)