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

[jjo] use statik for embedded manifests #12

Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kubeapps
generated
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@ BINARY = kubeapps
GO_PACKAGES = ./cmd/...
GO_FILES := $(shell find $(shell $(GO) list -f '{{.Dir}}' $(GO_PACKAGES)) -name \*.go)
GO_FLAGS = -ldflags="-w -X github.com/kubeapps/installer/cmd.VERSION=${VERSION}"

.PHONY: binary
EMBEDDED_STATIC = generated/statik/statik.go

default: binary

binary:
binary: $(EMBEDDED_STATIC)
$(GO) build -o $(BINARY) $(GO_FLAGS) .

test:
test: $(EMBEDDED_STATIC)
$(GO) test $(GO_FLAGS) $(GO_PACKAGES)

$(EMBEDDED_STATIC): $(wilcard static/*)
$(GO) build -o statik ./vendor/github.com/rakyll/statik/statik.go
$(GO) generate

fmt:
$(GOFMT) -s -w $(GO_FILES)

vet:
$(GO) vet $(GO_FLAGS) $(GO_PACKAGES)
$(GO) vet $(GO_FLAGS) $(GO_PACKAGES)

clean:
$(RM) kubeapps $(EMBEDDED_STATIC)

.PHONY: default binary test fmt vet clean
6 changes: 5 additions & 1 deletion cmd/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ var downCmd = &cobra.Command{
return err
}

objs, err := parseObjects(MANIFEST)
manifest, err := fsGetFile("/kubeapps-objs.yaml")
if err != nil {
return err
}
objs, err := parseObjects(manifest)
if err != nil {
return err
}
Expand Down
32 changes: 32 additions & 0 deletions cmd/fs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cmd

import (
"bytes"
_ "github.com/kubeapps/installer/generated/statik"
"github.com/rakyll/statik/fs"
"io"
"log"
"net/http"
)

var statikFS http.FileSystem

func init() {
var err error
statikFS, err = fs.New()
if err != nil {
log.Fatalf("ERROR initializing statikFS")
}
}

func fsGetFile(fname string) (string, error) {
buf := bytes.NewBuffer(nil)
statik_file, err := statikFS.Open(fname)
if err != nil {
log.Fatalf("ERROR: Static file '%s' not found", fname)
return "", err
}
io.Copy(buf, statik_file)
content := string(buf.Bytes())
return content, nil
}
Loading