Skip to content

Commit

Permalink
Merge pull request #12 from jjo/jjo-use-statik-for-embedded-manifests
Browse files Browse the repository at this point in the history
[jjo] use statik for embedded manifests
  • Loading branch information
ngtuna authored Nov 7, 2017
2 parents a0bc68d + ebeba22 commit c85c2ee
Show file tree
Hide file tree
Showing 273 changed files with 61,127 additions and 24,121 deletions.
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

0 comments on commit c85c2ee

Please sign in to comment.