Skip to content

Commit 084efa9

Browse files
committed
Use go:embed instead of packr
This is general cleanup that we are doing to all code once they upgrade to Go 1.16 Signed-off-by: Carolyn Van Slyck <[email protected]>
1 parent f1eb07c commit 084efa9

File tree

6 files changed

+13
-66
lines changed

6 files changed

+13
-66
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
bin
22
.cnab
3-
*-packr.go
43
/build/git_askpass.sh

CONTRIBUTING.md

-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,3 @@ Here are the most common Makefile tasks
2929
* `build` builds both the runtime and client.
3030
* `install` installs the mixin into **~/.porter/mixins**.
3131
* `test-unit` runs the unit tests.
32-
* `clean-packr` removes extra packr files that were a side-effect of the build.
33-
Normally this is run automatically but if you run into issues with packr,
34-
run this command.
35-

Makefile

+5-19
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,21 @@ endif
3232
REGISTRY ?= $(USER)
3333

3434
.PHONY: build
35-
build: build-client build-runtime clean-packr
35+
build: build-client build-runtime
3636

37-
build-runtime: generate
37+
build-runtime:
3838
mkdir -p $(BINDIR)
3939
GOARCH=$(RUNTIME_ARCH) GOOS=$(RUNTIME_PLATFORM) $(GO) build -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(MIXIN)-runtime$(FILE_EXT) ./cmd/$(MIXIN)
4040

41-
build-client: generate
41+
build-client:
4242
mkdir -p $(BINDIR)
4343
$(GO) build -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(MIXIN)$(FILE_EXT) ./cmd/$(MIXIN)
4444

45-
generate: packr2
46-
$(GO) mod tidy
47-
$(GO) generate ./...
48-
49-
HAS_PACKR2 := $(shell command -v packr2)
50-
packr2:
51-
ifndef HAS_PACKR2
52-
$(GO) get -u github.com/gobuffalo/packr/v2/packr2
53-
endif
54-
55-
xbuild-all: generate
45+
xbuild-all:
5646
$(foreach OS, $(SUPPORTED_PLATFORMS), \
5747
$(foreach ARCH, $(SUPPORTED_ARCHES), \
5848
$(MAKE) $(MAKE_OPTS) CLIENT_PLATFORM=$(OS) CLIENT_ARCH=$(ARCH) MIXIN=$(MIXIN) xbuild; \
5949
))
60-
$(MAKE) clean-packr
6150

6251
xbuild: $(BINDIR)/$(VERSION)/$(MIXIN)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)$(FILE_EXT)
6352
$(BINDIR)/$(VERSION)/$(MIXIN)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)$(FILE_EXT):
@@ -87,8 +76,5 @@ install:
8776
install $(BINDIR)/$(MIXIN)$(FILE_EXT) $(PORTER_HOME)/mixins/$(MIXIN)/$(MIXIN)$(FILE_EXT)
8877
install $(BINDIR)/$(MIXIN)-runtime$(FILE_EXT) $(PORTER_HOME)/mixins/$(MIXIN)/runtimes/$(MIXIN)-runtime$(FILE_EXT)
8978

90-
clean: clean-packr
79+
clean:
9180
-rm -fr bin/
92-
93-
clean-packr: packr2
94-
cd pkg/kubernetes && packr2 clean

pkg/kubernetes/kubernetes.go

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:generate packr2
2-
31
package kubernetes
42

53
import (
@@ -11,7 +9,6 @@ import (
119

1210
"get.porter.sh/porter/pkg/context"
1311
"github.com/ghodss/yaml"
14-
"github.com/gobuffalo/packr/v2"
1512
"github.com/pkg/errors"
1613
"github.com/xeipuuv/gojsonschema"
1714
)
@@ -22,22 +19,16 @@ const (
2219

2320
type Mixin struct {
2421
*context.Context
25-
schemas *packr.Box
2622
KubernetesClientVersion string
2723
}
2824

2925
func New() *Mixin {
3026
return &Mixin{
3127
Context: context.New(),
32-
schemas: NewSchemaBox(),
3328
KubernetesClientVersion: defaultKubernetesClientVersion,
3429
}
3530
}
3631

37-
func NewSchemaBox() *packr.Box {
38-
return packr.New("get.porter.sh/porter/pkg/kubernetes/schema", "./schema")
39-
}
40-
4132
func (m *Mixin) getCommandFile(commandFile string, w io.Writer) ([]byte, error) {
4233
if commandFile == "" {
4334
reader := bufio.NewReader(m.In)
@@ -65,10 +56,7 @@ func (m *Mixin) ValidatePayload(b []byte) error {
6556
manifestLoader := gojsonschema.NewGoLoader(s)
6657

6758
// Load the step schema
68-
schema, err := m.GetSchema()
69-
if err != nil {
70-
return err
71-
}
59+
schema := m.GetSchema()
7260
schemaLoader := gojsonschema.NewStringLoader(schema)
7361

7462
validator, err := gojsonschema.NewSchema(schemaLoader)

pkg/kubernetes/schema.go

+7-17
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
package kubernetes
22

33
import (
4+
_ "embed"
45
"fmt"
5-
6-
packr "github.com/gobuffalo/packr/v2"
76
)
87

9-
func (m *Mixin) PrintSchema() error {
10-
schema, err := m.GetSchema()
11-
if err != nil {
12-
return err
13-
}
8+
//go:embed schema/schema.json
9+
var schema string
1410

11+
func (m *Mixin) PrintSchema() error {
12+
schema := m.GetSchema()
1513
fmt.Fprintf(m.Out, schema)
16-
1714
return nil
1815
}
1916

20-
func (m *Mixin) GetSchema() (string, error) {
21-
t := packr.New("schema", "./schema")
22-
23-
b, err := t.Find("schema.json")
24-
if err != nil {
25-
return "", err
26-
}
27-
28-
return string(b), nil
17+
func (m *Mixin) GetSchema() string {
18+
return schema
2919
}

pkg/kubernetes/schema_test.go

-12
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@ import (
99
"github.com/stretchr/testify/require"
1010
)
1111

12-
func TestMixin_GetSchema(t *testing.T) {
13-
m := NewTestMixin(t)
14-
15-
gotSchema, err := m.GetSchema()
16-
require.NoError(t, err)
17-
18-
wantSchema, err := ioutil.ReadFile("./schema/schema.json")
19-
require.NoError(t, err)
20-
21-
assert.Equal(t, string(wantSchema), gotSchema)
22-
}
23-
2412
func TestMixin_PrintSchema(t *testing.T) {
2513
m := NewTestMixin(t)
2614

0 commit comments

Comments
 (0)