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

Replace go-bindata-assetfs build dependency with native go:embed #11208

Merged
merged 12 commits into from Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
436 changes: 218 additions & 218 deletions .circleci/config.yml

Large diffs are not rendered by default.

436 changes: 218 additions & 218 deletions .circleci/config/@build-release.yml

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -28,6 +28,9 @@ _testmain.go
/bin/
/pkg/

# Generated Web UI goes here
/http/web_ui/**

# Vault-specific
example.hcl
example.vault.d
Expand Down Expand Up @@ -73,7 +76,6 @@ dist/*
ui/dist
ui/tmp
ui/root
http/bindata_assetfs.go

# dependencies
ui/node_modules
Expand Down
18 changes: 5 additions & 13 deletions Makefile
Expand Up @@ -8,8 +8,6 @@ EXTENDED_TEST_TIMEOUT=60m
INTEG_TEST_TIMEOUT=120m
VETARGS?=-asmdecl -atomic -bool -buildtags -copylocks -methods -nilfunc -printf -rangeloops -shift -structtags -unsafeptr
EXTERNAL_TOOLS_CI=\
github.com/elazarl/go-bindata-assetfs/... \
github.com/hashicorp/go-bindata/... \
github.com/mitchellh/gox \
golang.org/x/tools/cmd/goimports
EXTERNAL_TOOLS=\
Expand Down Expand Up @@ -139,13 +137,7 @@ update-plugins:
grep vault-plugin- vendor/vendor.json | cut -d '"' -f 4 | xargs govendor fetch

static-assets-dir:
@mkdir -p ./pkg/web_ui

static-assets: static-assets-dir
@echo "--> Generating static assets"
@go-bindata-assetfs -o bindata_assetfs.go -pkg http -prefix pkg -modtime 1480000000 -tags ui ./pkg/web_ui/...
@mv bindata_assetfs.go http
@$(MAKE) -f $(THIS_FILE) fmt
@mkdir -p ./http/web_ui

test-ember:
@echo "--> Installing JavaScript assets"
Expand Down Expand Up @@ -187,8 +179,8 @@ ember-dist-dev:
@echo "--> Building Ember application"
@cd ui && yarn run build-dev

static-dist: ember-dist static-assets
static-dist-dev: ember-dist-dev static-assets
static-dist: ember-dist
static-dist-dev: ember-dist-dev

proto:
protoc vault/*.proto --go_out=plugins=grpc,paths=source_relative:.
Expand Down Expand Up @@ -257,8 +249,8 @@ ci-config:
ci-verify:
@$(MAKE) -C .circleci ci-verify

.PHONY: bin default prep test vet bootstrap ci-bootstrap fmt fmtcheck mysql-database-plugin mysql-legacy-database-plugin cassandra-database-plugin influxdb-database-plugin postgresql-database-plugin mssql-database-plugin hana-database-plugin mongodb-database-plugin static-assets ember-dist ember-dist-dev static-dist static-dist-dev assetcheck check-vault-in-path check-browserstack-creds test-ui-browserstack packages build build-ci
.PHONY: bin default prep test vet bootstrap ci-bootstrap fmt fmtcheck mysql-database-plugin mysql-legacy-database-plugin cassandra-database-plugin influxdb-database-plugin postgresql-database-plugin mssql-database-plugin hana-database-plugin mongodb-database-plugin ember-dist ember-dist-dev static-dist static-dist-dev assetcheck check-vault-in-path check-browserstack-creds test-ui-browserstack packages build build-ci

.NOTPARALLEL: ember-dist ember-dist-dev static-assets
.NOTPARALLEL: ember-dist ember-dist-dev

-include packagespec.mk
2 changes: 0 additions & 2 deletions go.mod
Expand Up @@ -39,7 +39,6 @@ require (
github.com/docker/go-connections v0.4.0
github.com/dsnet/compress v0.0.1 // indirect
github.com/duosecurity/duo_api_golang v0.0.0-20190308151101-6c680f768e74
github.com/elazarl/go-bindata-assetfs v1.0.1-0.20200509193318-234c15e7648f
github.com/fatih/color v1.9.0
github.com/fatih/structs v1.1.0
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa
Expand All @@ -56,7 +55,6 @@ require (
github.com/hashicorp/consul-template v0.25.2
github.com/hashicorp/consul/api v1.4.0
github.com/hashicorp/errwrap v1.1.0
github.com/hashicorp/go-bindata v3.0.8-0.20180209072458-bf7910af8997+incompatible
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-discover v0.0.0-20201029210230-738cb3105cd0
github.com/hashicorp/go-gcp-common v0.6.0
Expand Down
39 changes: 2 additions & 37 deletions go.sum

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions http/assets.go
@@ -0,0 +1,24 @@
// +build ui

package http

import (
"embed"
"io/fs"
"net/http"
)

// content is our static web server content.
//go:embed web_ui/*
var content embed.FS

// assetFS is a http Filesystem that serves the generated web UI from the
// "ember-dist" make step
func assetFS() http.FileSystem {
// sub out to web_ui, where the generated content lives
f, err := fs.Sub(content, "web_ui")
if err != nil {
panic(err)
}
return http.FS(f)
}
6 changes: 4 additions & 2 deletions http/stub_assets.go → http/assets_stub.go
Expand Up @@ -3,14 +3,16 @@
package http

import (
assetfs "github.com/elazarl/go-bindata-assetfs"
"net/http"
)

func init() {
// set uiBuiltIn to false to indicate the ui is not built in. See
// http/handler.go
uiBuiltIn = false
}

// assetFS is a stub for building Vault without a UI.
func assetFS() *assetfs.AssetFS {
func assetFS() http.FileSystem {
return nil
}
14 changes: 7 additions & 7 deletions http/handler.go
Expand Up @@ -7,18 +7,17 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"io/ioutil"
"mime"
"net"
"net/http"
"net/textproto"
"net/url"
"os"
"strings"
"time"

"github.com/NYTimes/gziphandler"
assetfs "github.com/elazarl/go-bindata-assetfs"
"github.com/hashicorp/errwrap"
cleanhttp "github.com/hashicorp/go-cleanhttp"
sockaddr "github.com/hashicorp/go-sockaddr"
Expand Down Expand Up @@ -563,17 +562,18 @@ func handleUIRedirect() http.Handler {
}

type UIAssetWrapper struct {
FileSystem *assetfs.AssetFS
FileSystem http.FileSystem
}

func (fs *UIAssetWrapper) Open(name string) (http.File, error) {
file, err := fs.FileSystem.Open(name)
func (fsw *UIAssetWrapper) Open(name string) (http.File, error) {
file, err := fsw.FileSystem.Open(name)
if err == nil {
return file, nil
}
// serve index.html instead of 404ing
if err == os.ErrNotExist {
return fs.FileSystem.Open("index.html")
if errors.Is(err, fs.ErrNotExist) {
file, err := fsw.FileSystem.Open("index.html")
return file, err
}
return nil, err
}
Expand Down
Empty file added http/web_ui/.gitkeep
Empty file.