This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pulls in the buffalo-docker plugin (#1709)
* pulls in the buffalo-docker plugin * remove syncx
- Loading branch information
Showing
18 changed files
with
399 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package docker | ||
|
||
import ( | ||
"text/template" | ||
|
||
"github.com/gobuffalo/genny" | ||
"github.com/gobuffalo/gogen" | ||
"github.com/gobuffalo/packr/v2" | ||
) | ||
|
||
func New(opts *Options) (*genny.Generator, error) { | ||
g := genny.New() | ||
|
||
if err := opts.Validate(); err != nil { | ||
return g, err | ||
} | ||
|
||
data := map[string]interface{}{ | ||
"opts": opts, | ||
} | ||
|
||
g.Box(packr.New("github.com/gobuffalo/buffalo/common", "../docker/templates/common")) | ||
|
||
switch opts.Style { | ||
case "multi": | ||
g.Box(packr.New("github.com/gobuffalo/buffalo/multi", "../docker/templates/multi")) | ||
case "standard": | ||
g.Box(packr.New("github.com/gobuffalo/buffalo/standard", "../docker/templates/standard")) | ||
} | ||
|
||
helpers := template.FuncMap{} | ||
t := gogen.TemplateTransformer(data, helpers) | ||
g.Transformer(t) | ||
g.Transformer(genny.Dot()) | ||
|
||
return g, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package docker | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gobuffalo/genny/gentest" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_New(t *testing.T) { | ||
r := require.New(t) | ||
|
||
g, err := New(&Options{}) | ||
r.NoError(err) | ||
|
||
run := gentest.NewRunner() | ||
run.With(g) | ||
|
||
r.NoError(run.Run()) | ||
|
||
res := run.Results() | ||
|
||
r.Len(res.Commands, 0) | ||
|
||
r.Len(res.Files, 2) | ||
|
||
f := res.Files[0] | ||
r.Equal(".dockerignore", f.Name()) | ||
|
||
f = res.Files[1] | ||
r.Equal("Dockerfile", f.Name()) | ||
r.Contains(f.String(), "multi-stage") | ||
} | ||
|
||
func Test_New_Standard(t *testing.T) { | ||
r := require.New(t) | ||
|
||
g, err := New(&Options{ | ||
Style: "standard", | ||
}) | ||
r.NoError(err) | ||
|
||
run := gentest.NewRunner() | ||
run.With(g) | ||
|
||
r.NoError(run.Run()) | ||
|
||
res := run.Results() | ||
|
||
r.Len(res.Commands, 0) | ||
|
||
r.Len(res.Files, 2) | ||
|
||
f := res.Files[0] | ||
r.Equal(".dockerignore", f.Name()) | ||
|
||
f = res.Files[1] | ||
r.Equal("Dockerfile", f.Name()) | ||
r.NotContains(f.String(), "multi-stage") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package docker | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gobuffalo/buffalo/runtime" | ||
"github.com/gobuffalo/meta" | ||
) | ||
|
||
type Options struct { | ||
App meta.App `json:"app"` | ||
Version string `json:"version"` | ||
Style string `json:"style"` | ||
} | ||
|
||
// Validate that options are usuable | ||
func (opts *Options) Validate() error { | ||
if opts.App.IsZero() { | ||
opts.App = meta.New(".") | ||
} | ||
if len(opts.Version) == 0 { | ||
opts.Version = runtime.Version | ||
} | ||
if len(opts.Style) == 0 { | ||
opts.Style = "multi" | ||
} | ||
|
||
switch opts.Style { | ||
case "multi", "standard": | ||
default: | ||
return fmt.Errorf("unknown style option %s", opts.Style) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package docker | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_Options_Validate(t *testing.T) { | ||
r := require.New(t) | ||
|
||
opts := &Options{ | ||
Style: "foo", | ||
} | ||
err := opts.Validate() | ||
r.Error(err) | ||
|
||
opts.Style = "multi" | ||
err = opts.Validate() | ||
r.NoError(err) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
*.log | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# This is a multi-stage Dockerfile and requires >= Docker 17.05 | ||
# https://docs.docker.com/engine/userguide/eng-image/multistage-build/ | ||
FROM gobuffalo/buffalo:{{.opts.Version}} as builder | ||
|
||
RUN mkdir -p $GOPATH/src/{{.opts.App.PackagePkg}} | ||
WORKDIR $GOPATH/src/{{.opts.App.PackagePkg}} | ||
|
||
{{if .opts.App.WithWebpack -}} | ||
# this will cache the npm install step, unless package.json changes | ||
ADD package.json . | ||
{{if .opts.App.WithYarn -}} | ||
ADD yarn.lock . | ||
RUN yarn install --no-progress | ||
{{else -}} | ||
RUN npm install --no-progress | ||
{{end -}} | ||
{{end -}} | ||
|
||
ADD . . | ||
{{if .opts.App.WithDep -}} | ||
RUN dep ensure | ||
{{else -}} | ||
{{if .opts.App.WithModules -}} | ||
ENV GO111MODULES=on | ||
{{end -}} | ||
RUN go get ./... | ||
{{end -}} | ||
RUN buffalo build --static -o /bin/app | ||
|
||
FROM alpine | ||
RUN apk add --no-cache bash | ||
RUN apk add --no-cache ca-certificates | ||
|
||
WORKDIR /bin/ | ||
|
||
COPY --from=builder /bin/app . | ||
|
||
# Uncomment to run the binary in "production" mode: | ||
# ENV GO_ENV=production | ||
|
||
# Bind the app to 0.0.0.0 so it can be seen from outside the container | ||
ENV ADDR=0.0.0.0 | ||
|
||
EXPOSE 3000 | ||
|
||
# Uncomment to run the migrations before running the binary: | ||
# CMD /bin/app migrate; /bin/app | ||
CMD exec /bin/app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
FROM gobuffalo/buffalo:{{.opts.Version}} | ||
|
||
RUN mkdir -p $GOPATH/src/{{.opts.App.PackagePkg}} | ||
WORKDIR $GOPATH/src/{{.opts.App.PackagePkg}} | ||
|
||
{{if .opts.App.AsWeb -}} | ||
{{if .opts.App.WithWebpack -}} | ||
# this will cache the npm install step, unless package.json changes | ||
ADD package.json . | ||
{{if .opts.App.WithYarn -}} | ||
ADD yarn.lock . | ||
RUN yarn install --no-progress | ||
{{else -}} | ||
RUN npm install --no-progress | ||
{{end -}} | ||
{{end -}} | ||
{{end -}} | ||
|
||
ADD . . | ||
{{if .opts.App.WithDep -}} | ||
RUN dep ensure | ||
{{else -}} | ||
RUN go get $(go list ./... | grep -v /vendor/) | ||
{{end -}} | ||
RUN buffalo build --static -o /bin/app | ||
|
||
# Uncomment to run the binary in "production" mode: | ||
# ENV GO_ENV=production | ||
|
||
# Bind the app to 0.0.0.0 so it can be seen from outside the container | ||
ENV ADDR=0.0.0.0 | ||
|
||
EXPOSE 3000 | ||
|
||
# Uncomment to run the migrations before running the binary: | ||
# CMD /bin/app migrate; /bin/app | ||
CMD exec /bin/app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package render | ||
|
||
import ( | ||
"sort" | ||
"sync" | ||
) | ||
|
||
// stringMap wraps sync.Map and uses the following types: | ||
// key: string | ||
// value: string | ||
type stringMap struct { | ||
data sync.Map | ||
} | ||
|
||
// Delete the key from the map | ||
func (m *stringMap) Delete(key string) { | ||
m.data.Delete(key) | ||
} | ||
|
||
// Load the key from the map. | ||
// Returns string or bool. | ||
// A false return indicates either the key was not found | ||
// or the value is not of type string | ||
func (m *stringMap) Load(key string) (string, bool) { | ||
i, ok := m.data.Load(key) | ||
if !ok { | ||
return ``, false | ||
} | ||
s, ok := i.(string) | ||
return s, ok | ||
} | ||
|
||
// LoadOrStore will return an existing key or | ||
// store the value if not already in the map | ||
func (m *stringMap) LoadOrStore(key string, value string) (string, bool) { | ||
i, _ := m.data.LoadOrStore(key, value) | ||
s, ok := i.(string) | ||
return s, ok | ||
} | ||
|
||
// Range over the string values in the map | ||
func (m *stringMap) Range(f func(key string, value string) bool) { | ||
m.data.Range(func(k, v interface{}) bool { | ||
key, ok := k.(string) | ||
if !ok { | ||
return false | ||
} | ||
value, ok := v.(string) | ||
if !ok { | ||
return false | ||
} | ||
return f(key, value) | ||
}) | ||
} | ||
|
||
// Store a string in the map | ||
func (m *stringMap) Store(key string, value string) { | ||
m.data.Store(key, value) | ||
} | ||
|
||
// Keys returns a list of keys in the map | ||
func (m *stringMap) Keys() []string { | ||
var keys []string | ||
m.Range(func(key string, value string) bool { | ||
keys = append(keys, key) | ||
return true | ||
}) | ||
sort.Strings(keys) | ||
return keys | ||
} |
Oops, something went wrong.