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

Drop go-bindata dependency #843

Merged
merged 6 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
10 changes: 3 additions & 7 deletions .github/workflows/on_pr_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ jobs:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Go 1.16
- name: Set up Go 1.18
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.18

- name: Env Debug
run: |
Expand Down Expand Up @@ -100,12 +100,8 @@ jobs:
go install -mod=vendor github.com/mattn/goveralls
$(go env GOPATH)/bin/goveralls -coverprofile=profile.cov -service=github

# converts viewer code (HTML, CSS, JS) into Go binary data
# this is run to make sure the client side code builds but the bindata
# is not used for compiling at this point
- name: Generate bindata
- name: Build embeded UI
run: |
go install -mod=vendor github.com/jteeuwen/go-bindata/go-bindata
pushd ${GITHUB_WORKSPACE}/server
go generate ./...
popd
4 changes: 2 additions & 2 deletions .github/workflows/on_release_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ jobs:
- name: Set tegola version
run: echo "VERSION=$(cat version/version.txt)" >> $GITHUB_ENV

- name: Set up Go 1.16
- name: Set up Go 1.18
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.18

- name: Build for Linux
env:
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ require (
github.com/jackc/pgproto3/v2 v2.2.0
github.com/jackc/pgtype v1.9.1
github.com/jackc/pgx/v4 v4.14.1
github.com/jteeuwen/go-bindata v3.0.8-0.20151023091102-a0ff2567cfb7+incompatible
github.com/mattn/go-sqlite3 v1.14.6
github.com/mattn/goveralls v0.0.5
github.com/pborman/uuid v1.2.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCV
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jteeuwen/go-bindata v3.0.8-0.20151023091102-a0ff2567cfb7+incompatible h1:KTM14h3AKWWcPf5IWS/pcFTZosRmoqdIYzqi0mMG7es=
github.com/jteeuwen/go-bindata v3.0.8-0.20151023091102-a0ff2567cfb7+incompatible/go.mod h1:JVvhzYOiGBnFSYRyV00iY8q7/0PThjIYav1p9h5dmKs=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
Expand Down
12 changes: 0 additions & 12 deletions internal/build/bindata_debug.generated.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/build/build.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package build

//go:generate go run build_tags.go -v -source=../..
//go:generate go run tags/tags.go -v -runCommand="internal/build/tags.go" -source=../..

import (
"sort"
Expand Down
2 changes: 1 addition & 1 deletion internal/build/cgo.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build cgo

// This file was autogenerated DO NOT EDIT
// the file was generated with the following command /tmp/go-build2334189108/b001/exe/build_tags -v -source=../..
// the file was generated with the following command "internal/build/tags.go"

package build

Expand Down
2 changes: 1 addition & 1 deletion internal/build/no_azblob_cache.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build noAzblobCache

// This file was autogenerated DO NOT EDIT
// the file was generated with the following command /tmp/go-build2334189108/b001/exe/build_tags -v -source=../..
// the file was generated with the following command "internal/build/tags.go"

package build

Expand Down
2 changes: 1 addition & 1 deletion internal/build/no_gpkg_provider.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build noGpkgProvider

// This file was autogenerated DO NOT EDIT
// the file was generated with the following command /tmp/go-build2334189108/b001/exe/build_tags -v -source=../..
// the file was generated with the following command "internal/build/tags.go"

package build

Expand Down
2 changes: 1 addition & 1 deletion internal/build/no_postgis_provider.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build noPostgisProvider

// This file was autogenerated DO NOT EDIT
// the file was generated with the following command /tmp/go-build2334189108/b001/exe/build_tags -v -source=../..
// the file was generated with the following command "internal/build/tags.go"

package build

Expand Down
2 changes: 1 addition & 1 deletion internal/build/no_prometheus_observer.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build noPrometheusObserver

// This file was autogenerated DO NOT EDIT
// the file was generated with the following command /tmp/go-build2334189108/b001/exe/build_tags -v -source=../..
// the file was generated with the following command "internal/build/tags.go"

package build

Expand Down
2 changes: 1 addition & 1 deletion internal/build/no_redis_cache.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build noRedisCache

// This file was autogenerated DO NOT EDIT
// the file was generated with the following command /tmp/go-build2334189108/b001/exe/build_tags -v -source=../..
// the file was generated with the following command "internal/build/tags.go"

package build

Expand Down
2 changes: 1 addition & 1 deletion internal/build/no_s3_cache.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build noS3Cache

// This file was autogenerated DO NOT EDIT
// the file was generated with the following command /tmp/go-build2334189108/b001/exe/build_tags -v -source=../..
// the file was generated with the following command "internal/build/tags.go"

package build

Expand Down
2 changes: 1 addition & 1 deletion internal/build/no_viewer.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build noViewer

// This file was autogenerated DO NOT EDIT
// the file was generated with the following command /tmp/go-build2334189108/b001/exe/build_tags -v -source=../..
// the file was generated with the following command "internal/build/tags.go"

package build

Expand Down
12 changes: 0 additions & 12 deletions internal/build/not_bindata_debug.generated.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/build/not_cgo.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build !cgo

// This file was autogenerated DO NOT EDIT
// the file was generated with the following command /tmp/go-build2334189108/b001/exe/build_tags -v -source=../..
// the file was generated with the following command "internal/build/tags.go"

package build

Expand Down
2 changes: 1 addition & 1 deletion internal/build/not_no_azblob_cache.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build !noAzblobCache

// This file was autogenerated DO NOT EDIT
// the file was generated with the following command /tmp/go-build2334189108/b001/exe/build_tags -v -source=../..
// the file was generated with the following command "internal/build/tags.go"

package build

Expand Down
2 changes: 1 addition & 1 deletion internal/build/not_no_gpkg_provider.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build !noGpkgProvider

// This file was autogenerated DO NOT EDIT
// the file was generated with the following command /tmp/go-build2334189108/b001/exe/build_tags -v -source=../..
// the file was generated with the following command "internal/build/tags.go"

package build

Expand Down
2 changes: 1 addition & 1 deletion internal/build/not_no_postgis_provider.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build !noPostgisProvider

// This file was autogenerated DO NOT EDIT
// the file was generated with the following command /tmp/go-build2334189108/b001/exe/build_tags -v -source=../..
// the file was generated with the following command "internal/build/tags.go"

package build

Expand Down
2 changes: 1 addition & 1 deletion internal/build/not_no_prometheus_observer.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build !noPrometheusObserver

// This file was autogenerated DO NOT EDIT
// the file was generated with the following command /tmp/go-build2334189108/b001/exe/build_tags -v -source=../..
// the file was generated with the following command "internal/build/tags.go"

package build

Expand Down
2 changes: 1 addition & 1 deletion internal/build/not_no_redis_cache.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build !noRedisCache

// This file was autogenerated DO NOT EDIT
// the file was generated with the following command /tmp/go-build2334189108/b001/exe/build_tags -v -source=../..
// the file was generated with the following command "internal/build/tags.go"

package build

Expand Down
2 changes: 1 addition & 1 deletion internal/build/not_no_s3_cache.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build !noS3Cache

// This file was autogenerated DO NOT EDIT
// the file was generated with the following command /tmp/go-build2334189108/b001/exe/build_tags -v -source=../..
// the file was generated with the following command "internal/build/tags.go"

package build

Expand Down
2 changes: 1 addition & 1 deletion internal/build/not_no_viewer.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build !noViewer

// This file was autogenerated DO NOT EDIT
// the file was generated with the following command /tmp/go-build2334189108/b001/exe/build_tags -v -source=../..
// the file was generated with the following command "internal/build/tags.go"

package build

Expand Down
2 changes: 1 addition & 1 deletion internal/build/not_pprof.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build !pprof

// This file was autogenerated DO NOT EDIT
// the file was generated with the following command /tmp/go-build2334189108/b001/exe/build_tags -v -source=../..
// the file was generated with the following command "internal/build/tags.go"

package build

Expand Down
2 changes: 1 addition & 1 deletion internal/build/pprof.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build pprof

// This file was autogenerated DO NOT EDIT
// the file was generated with the following command /tmp/go-build2334189108/b001/exe/build_tags -v -source=../..
// the file was generated with the following command "internal/build/tags.go"

package build

Expand Down
54 changes: 40 additions & 14 deletions internal/build/build_tags.go → internal/build/tags/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package main
import (
"bufio"
"bytes"
"encoding/json"
"flag"
"fmt"
"go/build"
Expand Down Expand Up @@ -61,23 +62,20 @@ func getPackages(dir string) (pkgs []string, err error) {
panic(err)
return nil, err
}
errChan := make(chan error, 1)

if err = list.Start(); err != nil {
return nil, err
}
scanner := bufio.NewScanner(stdout)
go func() {
errChan <- list.Run()
}()
for scanner.Scan() {
pkgs = append(pkgs, scanner.Text())
}
if err = list.Wait(); err != nil {
return pkgs, fmt.Errorf("failed on close: %w",err)
}

// wait for the list.Run to finish
err = <-errChan
if err != nil {
return nil, err
}
if err = scanner.Err(); err != nil {
return nil, err
return nil, fmt.Errorf("scanner error: %w",err)
}
return pkgs, nil
}
Expand All @@ -91,6 +89,14 @@ type getTagsOptions struct {
IgnoreTags []string
}

func getImportPackage(path string, srcDir string, mode build.ImportMode) (*build.Package, error) {
_, dir, err := buildPackageSource(srcDir, path)
if err != nil {
return nil, err
}
return build.ImportDir(dir, build.IgnoreVendor)
}

// getTags will get the list of packages in the source directory and then return all the build tags
// in those packages. One can ignore command packages (packages that are called main) by setting
// ignoreCommands to true, as well as provide a list of packages to ignore. The list of `ignorePackages`
Expand Down Expand Up @@ -123,9 +129,9 @@ NextPackagePath:
continue NextPackagePath
}
}
pkg, err := build.Import(pkgPath, sourceDir, build.IgnoreVendor)
pkg, err := getImportPackage(pkgPath, sourceDir, build.IgnoreVendor)
if err != nil {
return nil, err
return nil, fmt.Errorf("Failed to import `%v` from `%v` (ignore vendor directory): %w", pkgPath, sourceDir, err)
}
if options.IgnoreCommands && pkg.IsCommand() {
continue
Expand Down Expand Up @@ -153,10 +159,30 @@ NextPackagePath:
}

func buildPackageSource(sourceDir, pkgPath string) (name, dir string, err error) {
pkg, err := build.Import(pkgPath, sourceDir, build.IgnoreVendor)
list := exec.Command("go", "list", "-json", pkgPath)
list.Dir = sourceDir
so, err := list.StdoutPipe()
if err != nil {
return "", "", err
panic(err)
}
if err = list.Start(); err != nil {
panic(err)
}

type pkgInfo struct {
Dir string
Name string
Root string
}
var pkg pkgInfo

if err = json.NewDecoder(so).Decode(&pkg); err != nil {
panic(err)
}
if err = list.Wait(); err != nil {
panic(err)
}

return pkg.Name, pkg.Dir, nil
}

Expand Down
16 changes: 1 addition & 15 deletions server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,12 @@ Access-Control-Allow-Origin = "*"

## Local development of the embedded viewer

Tegola's built in viewer code is stored in the `ui/` directory. In order to embed the static files into the tegola binary the package [go-bindata](github.com/jteeuwen/go-bindata) is used. To insatll `go-bindata` run the following command from the repository root:

```
go install -mod=vendor github.com/jteeuwen/go-bindata/go-bindata
```

Once `go-bindata` is installed the following command can be run from the repository root to generate a .go file for inclusion in the tegola binary:
Tegola's built in viewer code is stored in the `ui/` directory. To build the ui `npm` must be installed. Once `npm` is installed the following command can be run from the repository root to generate a .go file for inclusion in the tegola binary:

```
go generate ./server
```

go-bindata also supports a debug mode which is descried as "Do not embed the assets, but provide the embedding API. Contents will still be loaded from disk." This mode is ideal for development and can be configured using the following command:

```
go generate -tags bindataDebug ./server
```

**Important**: Once updates to the viewer are complete, `go generate ./server` should be run and the bindata output should be committed to the repository.

## Disabling the viewer

The viewer can be excluded during building by using the build flag `noViewer`. For example, building tegola from the `cmd/tegola` directory:
Expand Down
Loading