Use embed.fs for self-contained build
This commit is contained in:
parent
0effaaa586
commit
695f5cae6b
12 changed files with 47 additions and 19 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,5 +1,8 @@
|
|||
.idea/
|
||||
/cacert-idp
|
||||
/static
|
||||
/ui/css/
|
||||
/ui/images/
|
||||
/ui/js/
|
||||
certs/
|
||||
idp.toml
|
||||
|
|
16
Makefile
16
Makefile
|
@ -1,9 +1,19 @@
|
|||
GOFILES = $(wildcard */*.go)
|
||||
TEMPLATES = $(wildcard templates/*.gohtml)
|
||||
TEMPLATES = $(wildcard ui/templates/*.gohtml)
|
||||
TRANSLATIONS = $(wildcard active.*.toml)
|
||||
RESOURCES = ui/css ui/images ui/js
|
||||
|
||||
all: cacert-idp
|
||||
|
||||
ui/css: ../cacert_resources/static/css
|
||||
cp -r ../cacert_resources/static/css ui/
|
||||
|
||||
ui/js: ../cacert_resources/static/js
|
||||
cp -r ../cacert_resources/static/js ui/
|
||||
|
||||
ui/images: ../cacert_resources/static/images
|
||||
cp -r ../cacert_resources/static/images ui/
|
||||
|
||||
go.sum: go.mod
|
||||
go mod tidy
|
||||
|
||||
|
@ -15,11 +25,11 @@ translations: $(TRANSLATIONS) $(GOFILES)
|
|||
goi18n merge active.*.toml translate.*.toml; \
|
||||
fi
|
||||
|
||||
cacert-idp: go.sum $(GOFILES) $(TEMPLATES) translations
|
||||
cacert-idp: go.sum $(GOFILES) $(TEMPLATES) translations $(RESOURCES)
|
||||
CGO_ENABLED=0 go build -o $@ ./cmd/idp.go
|
||||
|
||||
clean:
|
||||
rm -f cacert-idp
|
||||
rm -rf cacert-idp ui/css ui/js ui/images
|
||||
|
||||
.PHONY: all translations clean
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import (
|
|||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"git.cacert.org/oidc_idp/ui"
|
||||
"github.com/go-openapi/runtime/client"
|
||||
"github.com/gorilla/csrf"
|
||||
"github.com/knadh/koanf"
|
||||
|
@ -103,7 +104,7 @@ func main() {
|
|||
logoutHandler := handlers.NewLogoutHandler(handlerContext, logger)
|
||||
logoutSuccessHandler := handlers.NewLogoutSuccessHandler()
|
||||
errorHandler := handlers.NewErrorHandler()
|
||||
staticFiles := http.FileServer(http.Dir("static"))
|
||||
staticFiles := http.FileServer(http.FS(ui.Static))
|
||||
|
||||
router := http.NewServeMux()
|
||||
router.Handle("/login", loginHandler)
|
||||
|
@ -140,7 +141,7 @@ func main() {
|
|||
errorMiddleware, err := handlers.ErrorHandling(
|
||||
ctx,
|
||||
logger,
|
||||
"templates",
|
||||
ui.Templates,
|
||||
)
|
||||
if err != nil {
|
||||
logger.Fatalf("could not initialize request error handling: %v", err)
|
||||
|
|
|
@ -27,6 +27,7 @@ import (
|
|||
"time"
|
||||
|
||||
commonModels "git.cacert.org/oidc_idp/models"
|
||||
"git.cacert.org/oidc_idp/ui"
|
||||
"github.com/go-playground/form/v4"
|
||||
"github.com/gorilla/csrf"
|
||||
"github.com/lestrrat-go/jwx/jwt/openid"
|
||||
|
@ -430,8 +431,12 @@ func (h *consentHandler) GetUserInfoFromClientCertificate(r *http.Request, subje
|
|||
}
|
||||
|
||||
func NewConsentHandler(ctx context.Context, logger *log.Logger) (*consentHandler, error) {
|
||||
consentTemplate := template.Must(template.ParseFiles(
|
||||
"templates/base.gohtml", "templates/consent.gohtml"))
|
||||
consentTemplate := template.Must(
|
||||
template.ParseFS(
|
||||
ui.Templates,
|
||||
"templates/base.gohtml",
|
||||
"templates/consent.gohtml",
|
||||
))
|
||||
|
||||
return &consentHandler{
|
||||
adminClient: ctx.Value(CtxAdminClient).(*admin.Client),
|
||||
|
|
|
@ -21,8 +21,8 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
"git.cacert.org/oidc_idp/services"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
|
@ -118,14 +118,11 @@ func (w *errorResponseWriter) Write(content []byte) (int, error) {
|
|||
return w.ResponseWriter.Write(content)
|
||||
}
|
||||
|
||||
func ErrorHandling(
|
||||
handlerContext context.Context,
|
||||
logger *log.Logger,
|
||||
templateBaseDir string,
|
||||
) (func(http.Handler) http.Handler, error) {
|
||||
errorTemplates, err := template.ParseFiles(
|
||||
path.Join(templateBaseDir, "base.gohtml"),
|
||||
path.Join(templateBaseDir, "errors.gohtml"),
|
||||
func ErrorHandling(handlerContext context.Context, logger *log.Logger, templateFS fs.FS) (func(http.Handler) http.Handler, error) {
|
||||
errorTemplates, err := template.ParseFS(
|
||||
templateFS,
|
||||
"templates/base.gohtml",
|
||||
"templates/errors.gohtml",
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -27,6 +27,7 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"git.cacert.org/oidc_idp/ui"
|
||||
"github.com/gorilla/csrf"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
"github.com/ory/hydra-client-go/client/admin"
|
||||
|
@ -237,11 +238,13 @@ func NewLoginHandler(ctx context.Context, logger *log.Logger) (*loginHandler, er
|
|||
context: ctx,
|
||||
logger: logger,
|
||||
templates: map[templateName]*template.Template{
|
||||
CertificateLogin: template.Must(template.ParseFiles(
|
||||
CertificateLogin: template.Must(template.ParseFS(
|
||||
ui.Templates,
|
||||
"templates/base.gohtml",
|
||||
"templates/client_certificate.gohtml",
|
||||
)),
|
||||
NoEmailsInClientCertificate: template.Must(template.ParseFiles(
|
||||
NoEmailsInClientCertificate: template.Must(template.ParseFS(
|
||||
ui.Templates,
|
||||
"templates/base.gohtml",
|
||||
"templates/no_email_in_client_certificate.gohtml",
|
||||
)),
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
</main>
|
||||
<footer class="footer mt-auto py-3">
|
||||
<div class="container">
|
||||
<span class="text-muted small">© 2020, 2021 <a href="https://www.cacert.org/">CAcert</a></span>
|
||||
<span class="text-muted small">© 2020-2022 <a href="https://www.cacert.org/">CAcert</a></span>
|
||||
</div>
|
||||
</footer>
|
||||
<script type="text/javascript" src="/js/cacert.bundle.js"></script>
|
9
ui/ui.go
Normal file
9
ui/ui.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package ui
|
||||
|
||||
import "embed"
|
||||
|
||||
//go:embed templates/*
|
||||
var Templates embed.FS
|
||||
|
||||
//go:embed css/* js/* images/*
|
||||
var Static embed.FS
|
Loading…
Reference in a new issue