Add webbundle implementation

This commit is contained in:
Simone Gotti 2019-02-21 16:08:02 +01:00
parent 18c4b631bf
commit 4c0edd6374
2 changed files with 79 additions and 1 deletions

View File

@ -16,6 +16,19 @@ $(shell mkdir -p tools/bin )
AGOLA_TAGS = sqlite_unlock_notify
AGOLA_WEBBUNDLE_DEPS = webbundle/bindata.go
AGOLA_WEBBUNDLE_TAGS = webbundle
ifdef WEBBUNDLE
ifndef WEBDISTPATH
$(error WEBDISTPATH must be provided when building the webbundle)
endif
AGOLA_DEPS = $(AGOLA_WEBBUNDLE_DEPS)
AGOLA_TAGS += $(AGOLA_WEBBUNDLE_TAGS)
endif
.PHONY: all
all: build
@ -28,7 +41,7 @@ test: tools/bin/gocovmerge
# don't use existing file names and track go sources, let's do this to the go tool
.PHONY: bin/agola
bin/agola:
bin/agola: $(AGOLA_DEPS)
GO111MODULE=on go build $(if $(AGOLA_TAGS),-tags "$(AGOLA_TAGS)") -ldflags $(LD_FLAGS) -o $(PROJDIR)/bin/agola $(REPO_PATH)/cmd/agola
# toolbox MUST be statically compiled so it can be used in any image for that arch
@ -37,6 +50,13 @@ bin/agola:
bin/agola-toolbox:
CGO_ENABLED=0 GO111MODULE=on go build $(if $(AGOLA_TAGS),-tags "$(AGOLA_TAGS)") -ldflags $(LD_FLAGS) -o $(PROJDIR)/bin/agola-toolbox $(REPO_PATH)/cmd/toolbox
.PHONY: tools/bin/go-bindata
tools/bin/go-bindata:
GOBIN=$(PROJDIR)/tools/bin go install github.com/go-bindata/go-bindata/go-bindata
.PHONY: tools/bin/gocovmerge
tools/bin/gocovmerge:
GOBIN=$(PROJDIR)/tools/bin go install github.com/wadey/gocovmerge
webbundle/bindata.go: tools/bin/go-bindata $(WEBDISTPATH)
./tools/bin/go-bindata -o webbundle/bindata.go -tags webbundle -pkg webbundle -prefix "$(WEBDISTPATH)" -nocompress=true "$(WEBDISTPATH)/..."

58
webbundle/emptybindata.go Normal file
View File

@ -0,0 +1,58 @@
// Copyright 2019 Sorint.lab
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
// See the License for the specific language governing permissions and
// limitations under the License.
// +build !webbundle
package webbundle
import (
"fmt"
"os"
)
// Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func Asset(name string) ([]byte, error) {
return nil, fmt.Errorf("Asset %s not found", name)
}
// AssetInfo loads and returns the asset info for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func AssetInfo(name string) (os.FileInfo, error) {
return nil, fmt.Errorf("AssetInfo %s not found", name)
}
// AssetNames returns the names of the assets.
func AssetNames() []string {
return []string{}
}
// AssetDir returns the file names below a certain
// directory embedded in the file by go-bindata.
// For example if you run go-bindata on data/... and data contains the
// following hierarchy:
// data/
// foo.txt
// img/
// a.png
// b.png
// then AssetDir("data") would return []string{"foo.txt", "img"}
// AssetDir("data/img") would return []string{"a.png", "b.png"}
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
// AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error) {
return []string{}, nil
}