copy static files directly in go
Alan Pearce alan@alanpearce.eu
Thu, 18 Apr 2024 17:37:07 +0200
4 files changed, 16 insertions(+), 1 deletions(-)
M Dockerfile → Dockerfile
@@ -14,7 +14,6 @@ # RUN go vet ./... ENV ENV=production RUN go run ./cmd/build -RUN cp -r static/.well-known static/* public ENV GOOS=linux GOARCH=amd64 CGO_ENABLED=0 RUN go build server.go
M cmd/build/build.go → cmd/build/build.go
@@ -26,6 +26,7 @@ "github.com/adrg/frontmatter" "github.com/antchfx/xmlquery" "github.com/antchfx/xpath" mapset "github.com/deckarep/golang-set/v2" + cp "github.com/otiai10/copy" "github.com/pkg/errors" "github.com/yuin/goldmark" "github.com/yuin/goldmark/extension" @@ -527,6 +528,15 @@ slog.Debug("starting build process") _, err := os.Getwd() if err != nil { log.Panic(errors.Errorf("working directory does not exist: %v", err)) + } + + err = os.RemoveAll("public") + if err != nil { + log.Panic(errors.Errorf("could not remove public directory: %v", err)) + } + err = cp.Copy("static", "public", cp.Options{}) + if err != nil { + log.Panic(errors.Errorf("could not copy static files: %v", err)) } if err := build(); err != nil {
M go.mod → go.mod
@@ -14,6 +14,7 @@ github.com/deckarep/golang-set/v2 v2.6.0 github.com/getsentry/sentry-go v0.27.0 github.com/gofiber/contrib/fibersentry v1.0.4 github.com/gofiber/fiber/v2 v2.52.4 + github.com/otiai10/copy v1.14.0 github.com/pkg/errors v0.9.1 github.com/shengyanli1982/law v0.1.12 github.com/yuin/goldmark v1.7.1 @@ -45,6 +46,7 @@ github.com/tinylib/msgp v1.1.8 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasthttp v1.52.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect + golang.org/x/sync v0.3.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/protobuf v1.30.0 // indirect
M go.sum → go.sum
@@ -62,6 +62,8 @@ github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= +github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= +github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= github.com/philhofer/fwd v1.1.2 h1:bnDivRJ1EWPjUIRXV5KfORO897HTbpFAQddBdE8t7Gw= github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= @@ -116,6 +118,8 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=