main: embed assets from www to allows PWD to run standalone (#425)
Generate these assets in config because this package is imported by most. Add internal/addgenheader as a simple helper because go-bindata doesn't output the write header. Also update test CI workflow to regenerate and check commit is clean.
This commit is contained in:
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
config/gen_bindata.go linguist-generated
|
||||||
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@@ -22,5 +22,9 @@ jobs:
|
|||||||
uses: actions/setup-go@9fbc767707c286e568c92927bbf57d76b73e0892
|
uses: actions/setup-go@9fbc767707c286e568c92927bbf57d76b73e0892
|
||||||
with:
|
with:
|
||||||
go-version: ${{ matrix.go_version }}
|
go-version: ${{ matrix.go_version }}
|
||||||
|
- name: Generate
|
||||||
|
run: go generate ./...
|
||||||
- name: Test
|
- name: Test
|
||||||
run: go test ./...
|
run: go test ./...
|
||||||
|
- name: Verify clean commit
|
||||||
|
run: test -z "$(git status --porcelain)" || (git status; git diff; false)
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ import (
|
|||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:generate go run github.com/jteeuwen/go-bindata/go-bindata -pkg config -o gen_bindata.go -prefix ../www/ ../www ../www/default ../www/assets ../www/assets/xterm ../www/assets/xterm/addons ../www/assets/xterm/addons/webLinks ../www/assets/xterm/addons/terminado ../www/assets/xterm/addons/fullscreen ../www/assets/xterm/addons/fit ../www/assets/xterm/addons/attach ../www/assets/xterm/addons/zmodem ../www/assets/xterm/addons/search ../www/k8s
|
||||||
|
//go:generate go run github.com/play-with-docker/play-with-docker/internal/addgenheader gen_bindata.go "Code generated by go-bindata."
|
||||||
|
//go:generate gofmt -w -s gen_bindata.go
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PWDHostnameRegex = "[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}"
|
PWDHostnameRegex = "[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}"
|
||||||
PortRegex = "[0-9]{1,5}"
|
PortRegex = "[0-9]{1,5}"
|
||||||
|
|||||||
537
config/gen_bindata.go
generated
Normal file
537
config/gen_bindata.go
generated
Normal file
File diff suppressed because one or more lines are too long
1
go.mod
1
go.mod
@@ -34,6 +34,7 @@ require (
|
|||||||
github.com/hashicorp/golang-lru v0.5.1
|
github.com/hashicorp/golang-lru v0.5.1
|
||||||
github.com/inconshreveable/go-vhost v0.0.0-20160627193104-06d84117953b
|
github.com/inconshreveable/go-vhost v0.0.0-20160627193104-06d84117953b
|
||||||
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 // indirect
|
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 // indirect
|
||||||
|
github.com/jteeuwen/go-bindata v3.0.7+incompatible
|
||||||
github.com/juju/ratelimit v1.0.1 // indirect
|
github.com/juju/ratelimit v1.0.1 // indirect
|
||||||
github.com/mailru/easyjson v0.0.0-20171120080333-32fa128f234d // indirect
|
github.com/mailru/easyjson v0.0.0-20171120080333-32fa128f234d // indirect
|
||||||
github.com/miekg/dns v0.0.0-20171019064225-822ae18e7187
|
github.com/miekg/dns v0.0.0-20171019064225-822ae18e7187
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -187,6 +187,8 @@ github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr
|
|||||||
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
||||||
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
|
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
|
||||||
|
github.com/jteeuwen/go-bindata v3.0.7+incompatible h1:91Uy4d9SYVr1kyTJ15wJsog+esAZZl7JmEfTkwmhJts=
|
||||||
|
github.com/jteeuwen/go-bindata v3.0.7+incompatible/go.mod h1:JVvhzYOiGBnFSYRyV00iY8q7/0PThjIYav1p9h5dmKs=
|
||||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||||
github.com/juju/ratelimit v1.0.1 h1:+7AIFJVQ0EQgq/K9+0Krm7m530Du7tIz0METWzN0RgY=
|
github.com/juju/ratelimit v1.0.1 h1:+7AIFJVQ0EQgq/K9+0Krm7m530Du7tIz0METWzN0RgY=
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -203,8 +204,15 @@ func initAssets(p *types.Playground) {
|
|||||||
p.AssetsDir = "default"
|
p.AssetsDir = "default"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lpath := path.Join(p.AssetsDir, "landing.html")
|
||||||
|
landing, err := config.Asset(lpath)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Error loading %v: %v", lpath, err)
|
||||||
|
}
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
t, err := template.New("landing.html").Delims("[[", "]]").ParseFiles(fmt.Sprintf("./www/%s/landing.html", p.AssetsDir))
|
t := template.New("landing.html").Delims("[[", "]]")
|
||||||
|
t, err = t.Parse(string(landing))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error parsing template %v", err)
|
log.Fatalf("Error parsing template %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
26
internal/addgenheader/addgenheader.go
Normal file
26
internal/addgenheader/addgenheader.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
// addgenheader is a simple program that adds a DO NOT EDIT style
|
||||||
|
// comment at the top of a file. Because some generators do not do
|
||||||
|
// this, e.g. go-bindata
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
fmt.Fprintf(&buf, "// %v DO NOT EDIT\n", strings.TrimSpace(os.Args[2]))
|
||||||
|
fmt.Fprintf(&buf, "\n")
|
||||||
|
byts, err := ioutil.ReadFile(os.Args[1])
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Fprintf(&buf, "%s", byts)
|
||||||
|
if err := ioutil.WriteFile(os.Args[1], buf.Bytes(), 0666); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user