mirror of
https://github.com/Threnklyn/wg-ui.git
synced 2026-05-18 21:03:30 +02:00
Use Go embed.FS instead of external tool to embed assets (#135)
* Use Go embed.FS instead of external tool to embed assets * remove go-bindata from dockerfiles and bump ci to golang 1.16.x * remove more go-bindata related stuff Co-authored-by: Markus Viitamäki <markus.viitamaki@embark-studios.com>
This commit is contained in:
@@ -23,11 +23,6 @@ jobs:
|
|||||||
npm install --prefix ui
|
npm install --prefix ui
|
||||||
npm run --prefix ui build
|
npm run --prefix ui build
|
||||||
|
|
||||||
- name: Get and install bindfs
|
|
||||||
uses: "cedrickring/golang-action@1.7.0"
|
|
||||||
with:
|
|
||||||
args: go get -u github.com/go-bindata/go-bindata/... && go get -u github.com/elazarl/go-bindata-assetfs/... && go-bindata-assetfs -prefix ui/dist ui/dist
|
|
||||||
|
|
||||||
- name: Check styling error
|
- name: Check styling error
|
||||||
uses: "cedrickring/golang-action@1.7.0"
|
uses: "cedrickring/golang-action@1.7.0"
|
||||||
with:
|
with:
|
||||||
@@ -51,8 +46,7 @@ jobs:
|
|||||||
- name: Check security issues with gosec
|
- name: Check security issues with gosec
|
||||||
uses: "cedrickring/golang-action@1.7.0"
|
uses: "cedrickring/golang-action@1.7.0"
|
||||||
with:
|
with:
|
||||||
# TODO: remove `-exclude=G110` once https://github.com/go-bindata/go-bindata/pull/50 is merged and released
|
args: go get -u github.com/securego/gosec/cmd/gosec; gosec ./... # https://github.com/securego/gosec
|
||||||
args: go get -u github.com/securego/gosec/cmd/gosec; gosec -exclude=G110 ./... # https://github.com/securego/gosec
|
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: Build wg-ui
|
name: Build wg-ui
|
||||||
|
|||||||
@@ -7,14 +7,11 @@ RUN npm run build
|
|||||||
|
|
||||||
FROM docker.io/golang:latest AS build
|
FROM docker.io/golang:latest AS build
|
||||||
WORKDIR /wg
|
WORKDIR /wg
|
||||||
RUN go get github.com/go-bindata/go-bindata/...
|
|
||||||
RUN go get github.com/elazarl/go-bindata-assetfs/...
|
|
||||||
COPY go.mod .
|
COPY go.mod .
|
||||||
COPY go.sum .
|
COPY go.sum .
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
COPY . .
|
COPY . .
|
||||||
COPY --from=ui /ui/dist ui/dist
|
COPY --from=ui /ui/dist ui/dist
|
||||||
RUN go-bindata-assetfs -prefix ui/dist ui/dist
|
|
||||||
RUN go install .
|
RUN go install .
|
||||||
|
|
||||||
FROM gcr.io/distroless/base
|
FROM gcr.io/distroless/base
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ GOCLEAN=$(GOCMD) clean
|
|||||||
GOGET=$(GOCMD) get
|
GOGET=$(GOCMD) get
|
||||||
BINARY_NAME=wireguard-ui
|
BINARY_NAME=wireguard-ui
|
||||||
|
|
||||||
.PHONY: build container ui assets
|
.PHONY: build container ui
|
||||||
|
|
||||||
all: build
|
all: build
|
||||||
|
|
||||||
@@ -17,27 +17,22 @@ clean:
|
|||||||
ui:
|
ui:
|
||||||
cd ui && npm install && npm run build
|
cd ui && npm install && npm run build
|
||||||
|
|
||||||
assets:
|
build: ui
|
||||||
$(GOGET) github.com/go-bindata/go-bindata/...
|
|
||||||
$(GOGET) github.com/elazarl/go-bindata-assetfs/...
|
|
||||||
go-bindata-assetfs -prefix ui/dist ui/dist
|
|
||||||
|
|
||||||
build: ui assets
|
|
||||||
CGO_ENABLED=0 $(GOBUILD) -o bin/$(BINARY_NAME) -v
|
CGO_ENABLED=0 $(GOBUILD) -o bin/$(BINARY_NAME) -v
|
||||||
|
|
||||||
build-amd64: ui assets
|
build-amd64: ui
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o bin/$(BINARY_NAME)-amd64 -v
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o bin/$(BINARY_NAME)-amd64 -v
|
||||||
|
|
||||||
build-armv5: ui assets
|
build-armv5: ui
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 $(GOBUILD) -o bin/$(BINARY_NAME)-armv5 -v
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 $(GOBUILD) -o bin/$(BINARY_NAME)-armv5 -v
|
||||||
|
|
||||||
build-armv6: ui assets
|
build-armv6: ui
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 $(GOBUILD) -o bin/$(BINARY_NAME)-armv6 -v
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 $(GOBUILD) -o bin/$(BINARY_NAME)-armv6 -v
|
||||||
|
|
||||||
build-armv7: ui assets
|
build-armv7: ui
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 $(GOBUILD) -o bin/$(BINARY_NAME)-armv7 -v
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 $(GOBUILD) -o bin/$(BINARY_NAME)-armv7 -v
|
||||||
|
|
||||||
build-armv8: ui assets
|
build-armv8: ui
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GOBUILD) -o bin/$(BINARY_NAME)-armv8 -v
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GOBUILD) -o bin/$(BINARY_NAME)-armv8 -v
|
||||||
|
|
||||||
container:
|
container:
|
||||||
|
|||||||
@@ -133,7 +133,6 @@ make build-armv7
|
|||||||
|
|
||||||
```
|
```
|
||||||
make ui
|
make ui
|
||||||
make assets
|
|
||||||
make build
|
make build
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -7,14 +7,11 @@ RUN npm run build
|
|||||||
|
|
||||||
FROM docker.io/golang:latest AS build
|
FROM docker.io/golang:latest AS build
|
||||||
WORKDIR /wg
|
WORKDIR /wg
|
||||||
RUN go get github.com/go-bindata/go-bindata/...
|
|
||||||
RUN go get github.com/elazarl/go-bindata-assetfs/...
|
|
||||||
COPY go.mod .
|
COPY go.mod .
|
||||||
COPY go.sum .
|
COPY go.sum .
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
COPY . .
|
COPY . .
|
||||||
COPY --from=ui /ui/dist ui/dist
|
COPY --from=ui /ui/dist ui/dist
|
||||||
RUN go-bindata-assetfs -prefix ui/dist ui/dist
|
|
||||||
RUN go install .
|
RUN go install .
|
||||||
|
|
||||||
FROM docker.io/golang:latest AS wg_go_build
|
FROM docker.io/golang:latest AS wg_go_build
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
module github.com/embarkstudios/wireguard-ui
|
module github.com/embarkstudios/wireguard-ui
|
||||||
|
|
||||||
go 1.13
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
|
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
|
||||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
|
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
|
||||||
github.com/elazarl/go-bindata-assetfs v1.0.1
|
|
||||||
github.com/fujiwara/go-amzn-oidc v0.0.2
|
github.com/fujiwara/go-amzn-oidc v0.0.2
|
||||||
github.com/google/nftables v0.0.0-20200316075819-7127d9d22474
|
github.com/google/nftables v0.0.0-20200316075819-7127d9d22474
|
||||||
github.com/julienschmidt/httprouter v1.3.0
|
github.com/julienschmidt/httprouter v1.3.0
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||||
github.com/elazarl/go-bindata-assetfs v1.0.1 h1:m0kkaHRKEu7tUIUFVwhGGGYClXvyl4RE03qmvRTNfbw=
|
|
||||||
github.com/elazarl/go-bindata-assetfs v1.0.1/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
|
|
||||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||||
github.com/fujiwara/go-amzn-oidc v0.0.2 h1:BcniaR2fJFik2koEK6Vm80Kk/vg6uoGTyckNwuGKO48=
|
github.com/fujiwara/go-amzn-oidc v0.0.2 h1:BcniaR2fJFik2koEK6Vm80Kk/vg6uoGTyckNwuGKO48=
|
||||||
@@ -171,7 +169,6 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi
|
|||||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
|
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
|
||||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -17,7 +19,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
assetfs "github.com/elazarl/go-bindata-assetfs"
|
|
||||||
validator "github.com/fujiwara/go-amzn-oidc/validator"
|
validator "github.com/fujiwara/go-amzn-oidc/validator"
|
||||||
"github.com/google/nftables"
|
"github.com/google/nftables"
|
||||||
"github.com/google/nftables/expr"
|
"github.com/google/nftables/expr"
|
||||||
@@ -85,6 +86,9 @@ func ifname(n string) []byte {
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:embed ui/dist
|
||||||
|
var assetsFS embed.FS
|
||||||
|
|
||||||
// NewServer returns an instance of Server which contains both the webserver and the reference to Wireguard
|
// NewServer returns an instance of Server which contains both the webserver and the reference to Wireguard
|
||||||
func NewServer() *Server {
|
func NewServer() *Server {
|
||||||
ipAddr, ipNet, err := net.ParseCIDR(*clientIPRange)
|
ipAddr, ipNet, err := net.ParseCIDR(*clientIPRange)
|
||||||
@@ -102,7 +106,16 @@ func NewServer() *Server {
|
|||||||
config := NewServerConfig(cfgPath)
|
config := NewServerConfig(cfgPath)
|
||||||
|
|
||||||
log.Debug("Configuration loaded with public key: ", config.PublicKey)
|
log.Debug("Configuration loaded with public key: ", config.PublicKey)
|
||||||
assets := http.FileServer(&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: AssetInfo, Prefix: ""})
|
|
||||||
|
var fsys fs.FS = assetsFS
|
||||||
|
if f, err := fs.Sub(fsys, "ui/dist"); err != nil {
|
||||||
|
log.Error(fmt.Errorf("ui/dist does not exist in fs :%w", err))
|
||||||
|
} else {
|
||||||
|
fsys = f
|
||||||
|
}
|
||||||
|
fmt.Println(fs.Glob(fsys, "*"))
|
||||||
|
|
||||||
|
assets := http.FileServer(http.FS(fsys))
|
||||||
|
|
||||||
s := Server{
|
s := Server{
|
||||||
serverConfigPath: cfgPath,
|
serverConfigPath: cfgPath,
|
||||||
|
|||||||
Reference in New Issue
Block a user