Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
Merge branch 'development' into partial_with_for_loop
Browse files Browse the repository at this point in the history
  • Loading branch information
mclark4386 authored Oct 30, 2018
2 parents 3ef5d53 + ce2e6a9 commit 617e05a
Show file tree
Hide file tree
Showing 86 changed files with 8,088 additions and 830 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pkg
*.pid
coverage
coverage.data
build/*
*.pbxuser
*.mode1v3
.svn
Expand All @@ -27,3 +26,4 @@ generated/
bin/*
gin-bin
.idea/
.vscode/settings.json
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ RUN buffalo new --skip-webpack coke --db-type=sqlite3
WORKDIR $GOPATH/src/github.com/markbates/coke
RUN buffalo db create -a -d
RUN buffalo g resource widget name
RUN buffalo b -d
RUN buffalo b
# works fine:
RUN ./bin/coke migrate
RUN rm -rfv $GOPATH/src/github.com/markbates/coke
Expand Down
110 changes: 83 additions & 27 deletions buffalo/cmd/build.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
package cmd

import (
"bytes"
"context"
"os"
"os/exec"
"strings"
"time"

"github.com/gobuffalo/buffalo/buffalo/cmd/build"
"github.com/gobuffalo/buffalo/genny/build"
"github.com/gobuffalo/genny"
"github.com/gobuffalo/logger"
"github.com/gobuffalo/meta"
"github.com/markbates/sigtx"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var buildOptions = struct {
build.Options
SkipAssets bool
Tags string
*build.Options
SkipAssets bool
Debug bool
Tags string
SkipTemplateValidation bool
DryRun bool
Verbose bool
}{
Options: build.Options{},
Options: &build.Options{
BuildTime: time.Now(),
},
}

var xbuildCmd = &cobra.Command{
Expand All @@ -30,31 +40,29 @@ var xbuildCmd = &cobra.Command{

buildOptions.Options.WithAssets = !buildOptions.SkipAssets

if buildOptions.Debug {
logrus.SetLevel(logrus.DebugLevel)
run := genny.WetRunner(ctx)
if buildOptions.DryRun {
run = genny.DryRunner(ctx)
}

b := build.New(ctx, buildOptions.Options)
if buildOptions.Tags != "" {
b.Tags = append(b.Tags, buildOptions.Tags)
if buildOptions.Verbose || buildOptions.Debug {
run.Logger = logger.New(logger.DebugLevel)
buildOptions.BuildFlags = append(buildOptions.BuildFlags, "-v")
}

go func() {
<-ctx.Done()
err := b.Cleanup()
if err != nil {
logrus.Fatal(err)
}
}()

err := b.Run()
if err != nil {
return errors.WithStack(err)
opts := buildOptions.Options
opts.BuildVersion = buildVersion(opts.BuildTime.Format(time.RFC3339))

if buildOptions.Tags != "" {
opts.Tags = append(opts.Tags, buildOptions.Tags)
}

logrus.Infof("\nThe application was successfully built at %s\n", b.AbsoluteBinaryPath())
if !buildOptions.SkipTemplateValidation {
opts.TemplateValidators = append(opts.TemplateValidators, build.PlushValidator, build.GoTemplateValidator)
}

return nil
run.WithNew(build.New(opts))
return run.Run()
},
}

Expand All @@ -71,8 +79,56 @@ func init() {
xbuildCmd.Flags().BoolVarP(&buildOptions.SkipAssets, "skip-assets", "k", false, "skip running webpack and building assets")
xbuildCmd.Flags().BoolVarP(&buildOptions.Static, "static", "s", false, "build a static binary using --ldflags '-linkmode external -extldflags \"-static\"'")
xbuildCmd.Flags().StringVar(&buildOptions.LDFlags, "ldflags", "", "set any ldflags to be passed to the go build")
xbuildCmd.Flags().BoolVarP(&buildOptions.Debug, "debug", "d", false, "print debugging information")
xbuildCmd.Flags().BoolVarP(&buildOptions.Compress, "compress", "c", true, "compress static files in the binary")
xbuildCmd.Flags().BoolVarP(&buildOptions.Verbose, "verbose", "v", false, "print debugging information")
xbuildCmd.Flags().BoolVarP(&buildOptions.Debug, "deprecated-verbose", "d", false, "[deprecated] use -v instead")
xbuildCmd.Flags().BoolVar(&buildOptions.DryRun, "dry-run", false, "runs the build 'dry'")
xbuildCmd.Flags().BoolVar(&buildOptions.SkipTemplateValidation, "skip-template-validation", false, "skip validating plush templates")
xbuildCmd.Flags().StringVarP(&buildOptions.Environment, "environment", "", "development", "set the environment for the binary")
}

func buildVersion(version string) string {
vcs := buildOptions.VCS

if len(vcs) == 0 {
return version
}

ctx := context.Background()
run := genny.WetRunner(ctx)
if buildOptions.DryRun {
run = genny.DryRunner(ctx)
}

_, err := exec.LookPath(vcs)
if err != nil {
run.Logger.Warnf("could not find %s; defaulting to version %s", vcs, version)
return vcs
}
var cmd *exec.Cmd
switch vcs {
case "git":
cmd = exec.Command("git", "rev-parse", "--short", "HEAD")
case "bzr":
cmd = exec.Command("bzr", "revno")
default:
run.Logger.Warnf("could not find %s; defaulting to version %s", vcs, version)
return vcs
}

out := &bytes.Buffer{}
cmd.Stdout = out
run.WithRun(func(r *genny.Runner) error {
return r.Exec(cmd)
})

if err := run.Run(); err != nil {
run.Logger.Error(err)
return version
}

if out.String() != "" {
return strings.TrimSpace(out.String())
}

return version
}
12 changes: 0 additions & 12 deletions buffalo/cmd/build/a_build-packr.go

This file was deleted.

110 changes: 0 additions & 110 deletions buffalo/cmd/build/apkg.go

This file was deleted.

Loading

0 comments on commit 617e05a

Please sign in to comment.