Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove packr and use go:embed #39

Merged
merged 1 commit into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
bin
.cnab
*-packr.go
.vscode/*
23 changes: 4 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,23 @@ endif
REGISTRY ?= $(USER)

.PHONY: build
build: build-client build-runtime clean-packr
build: build-client build-runtime

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

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

generate: packr2
$(GO) mod tidy
$(GO) generate ./...

HAS_PACKR2 := $(shell command -v packr2)
packr2:
ifndef HAS_PACKR2
$(GO) get -u github.com/gobuffalo/packr/v2/packr2
endif

xbuild-all:
$(foreach OS, $(SUPPORTED_PLATFORMS), \
$(foreach ARCH, $(SUPPORTED_ARCHES), \
$(MAKE) $(MAKE_OPTS) CLIENT_PLATFORM=$(OS) CLIENT_ARCH=$(ARCH) MIXIN=$(MIXIN) xbuild; \
))
# Buid for linux arm64
$(MAKE) $(MAKE_OPTS) CLIENT_PLATFORM=linux CLIENT_ARCH=arm64 MIXIN=$(MIXIN) xbuild;
# Clean
$(MAKE) clean-packr

xbuild: $(BINDIR)/$(VERSION)/$(MIXIN)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)$(FILE_EXT)
$(BINDIR)/$(VERSION)/$(MIXIN)-$(CLIENT_PLATFORM)-$(CLIENT_ARCH)$(FILE_EXT):
Expand Down Expand Up @@ -107,8 +95,5 @@ install:
install $(BINDIR)/$(MIXIN)$(FILE_EXT) $(PORTER_HOME)/mixins/$(MIXIN)/$(MIXIN)$(FILE_EXT)
install $(BINDIR)/$(MIXIN)-runtime$(FILE_EXT) $(PORTER_HOME)/mixins/$(MIXIN)/runtimes/$(MIXIN)-runtime$(FILE_EXT)
# @porter mixin list
clean: clean-packr
clean:
-rm -fr bin/

clean-packr: packr2
cd pkg/helm3 && packr2 clean
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/MChorfa/porter-helm3

go 1.13
go 1.16

require (
cloud.google.com/go v0.55.0 // indirect
Expand All @@ -13,7 +13,6 @@ require (
github.com/gobuffalo/envy v1.9.0 // indirect
github.com/gobuffalo/logger v1.0.3 // indirect
github.com/gobuffalo/packd v1.0.0 // indirect
github.com/gobuffalo/packr/v2 v2.7.1
github.com/google/gofuzz v1.1.0 // indirect
github.com/googleapis/gnostic v0.5.3 // indirect
github.com/gophercloud/gophercloud v0.8.0 // indirect
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
github.com/evanphx/json-patch v4.2.0+incompatible h1:fUDGZCv/7iAN7u0puUVhvKCcsR6vRfwrJatElLBEf0I=
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/getsentry/raven-go v0.0.0-20180121060056-563b81fc02b7/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
Expand Down
2 changes: 2 additions & 0 deletions pkg/helm3/execute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"io/ioutil"
"os"
"sort"
"testing"

"get.porter.sh/porter/pkg/exec/builder"
Expand Down Expand Up @@ -59,6 +60,7 @@ func TestMixin_UnmarshalExecuteLoginRegistryStep(t *testing.T) {
builder.Flag{Name: "u", Values: []string{"myuser"}},
}

sort.Sort(step.Flags)
assert.EqualValues(t, wantFlags, step.Flags)
}

Expand Down
9 changes: 1 addition & 8 deletions pkg/helm3/helm3.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// go:generate packr2
package helm3

import (
Expand All @@ -10,7 +9,6 @@ import (
"github.com/MChorfa/porter-helm3/pkg/kubernetes"

"github.com/ghodss/yaml" // We are not using go-yaml because of serialization problems with jsonschema, don't use this library elsewhere
"github.com/gobuffalo/packr/v2"
"github.com/pkg/errors"
"github.com/xeipuuv/gojsonschema"
k8s "k8s.io/client-go/kubernetes"
Expand All @@ -23,7 +21,6 @@ const defaultClientArchitecture string = "amd64"
// Helm is the logic behind the helm mixin
type Mixin struct {
*context.Context
schema *packr.Box
ClientFactory kubernetes.ClientFactory
HelmClientVersion string
HelmClientPlatfrom string
Expand All @@ -33,7 +30,6 @@ type Mixin struct {
// New helm mixin client, initialized with useful defaults.
func New() *Mixin {
return &Mixin{
schema: packr.New("schema", "./schema"),
Context: context.New(),
ClientFactory: kubernetes.New(),
HelmClientVersion: defaultClientVersion,
Expand Down Expand Up @@ -61,10 +57,7 @@ func (m *Mixin) ValidatePayload(b []byte) error {
manifestLoader := gojsonschema.NewGoLoader(s)

// Load the step schema
schema, err := m.GetSchema()
if err != nil {
return err
}
schema := m.GetSchema()
schemaLoader := gojsonschema.NewStringLoader(schema)

validator, err := gojsonschema.NewSchema(schemaLoader)
Expand Down
22 changes: 7 additions & 15 deletions pkg/helm3/schema.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
package helm3

import (
_ "embed"
"fmt"

packr "github.com/gobuffalo/packr/v2"
)

//go:embed schema/schema.json
var schemaDoc string

func (m *Mixin) PrintSchema() error {
schema, err := m.GetSchema()
if err != nil {
return err
}
schema := m.GetSchema()

fmt.Fprintf(m.Out, schema)

return nil
}

func (m *Mixin) GetSchema() (string, error) {
t := packr.New("schema", "./schema")

b, err := t.Find("schema.json")
if err != nil {
return "", err
}

return string(b), nil
func (m *Mixin) GetSchema() string {
return schemaDoc
}
15 changes: 1 addition & 14 deletions pkg/helm3/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@ import (
"github.com/xeipuuv/gojsonschema"
)

func TestMixin_GetSchema(t *testing.T) {
m := NewTestMixin(t)

gotSchema, err := m.GetSchema()
require.NoError(t, err)

wantSchema, err := ioutil.ReadFile("schema/schema.json")
require.NoError(t, err)

assert.Equal(t, string(wantSchema), gotSchema)
}

func TestMixin_PrintSchema(t *testing.T) {
m := NewTestMixin(t)

Expand All @@ -41,8 +29,7 @@ func TestMixin_ValidateSchema(t *testing.T) {
m := NewTestMixin(t)

// Load the mixin schema
schemaB, err := m.GetSchema()
require.NoError(t, err)
schemaB := m.GetSchema()
schemaLoader := gojsonschema.NewStringLoader(schemaB)

// This validates that your schema.json is filled in properly
Expand Down
Loading