diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4aa0571 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +/release +/data +/bin +/.vscode +/vendor \ No newline at end of file diff --git a/Makefile b/Makefile index 76d5aa7..4f59177 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,10 @@ -build: vendor - CGO_ENABLED=0 go build -mod=vendor -v -o bin/server ./cmd/server +DOKKU_HOST := dokku@dev.lookingfora.name +SHELL := /bin/bash +DOCKER_IMAGE_NAME ?= bornholm/hydra-passwordless +DOCKER_IMAGE_TAG ?= $(shell git describe --always) + +build: + CGO_ENABLED=0 go build -v -o bin/server ./cmd/server test: go test -v -race ./... @@ -7,9 +12,6 @@ test: release: @$(SHELL) ./misc/script/release.sh -vendor: - go mod vendor - tidy: go mod tidy @@ -31,8 +33,9 @@ create-default-client: hydra \ hydra clients create \ -c http://localhost:3002/oauth2/callback \ - --post-logout-callbacks http://localhost:3002 - + --post-logout-callbacks http://localhost:3002 \ + -n "Default App" \ + -a "openid" -a "email" list-clients: docker-compose exec \ @@ -46,10 +49,50 @@ hydra-interactive: hydra \ /bin/sh +dokku-build: + docker build \ + -t hydra-passwordless-dokku:latest \ + . + +dokku-run: + docker run -it --rm -p 4444:4444 -p 3002:3002 hydra-passwordless-dokku:latest + +dokku-deploy: dokku-deploy-passwordless dokku-deploy-sso + +dokku-deploy-passwordless: + $(if $(shell git config remote.dokku-passwordless.url),, git remote add dokku-passwordless $(DOKKU_HOST):passwordless) + git push -f dokku-passwordless $(shell git rev-parse HEAD):refs/heads/master + +dokku-deploy-sso: + $(if $(shell git config remote.dokku-sso.url),, git remote add dokku-sso $(DOKKU_HOST):sso) + git push -f dokku-sso $(shell git rev-parse HEAD):refs/heads/master + +docker-build: + docker build \ + --build-arg="HTTP_PROXY=$(HTTP_PROXY)" \ + --build-arg="HTTPS_PROXY=${HTTP_PROXY}" \ + --build-arg="https_proxy=${https_proxy}" \ + --build-arg="http_proxy=${http_proxy}" \ + -t hydra-passwordless:latest \ + -f ./misc/docker/Dockerfile \ + . + +docker-run: + docker run \ + -it --rm \ + -p 3000:3000 \ + hydra-passwordless:latest + +docker-release: docker-build + docker image tag hydra-passwordless:latest $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG) + docker image tag hydra-passwordless:latest $(DOCKER_IMAGE_NAME):latest + docker login + docker push $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG) + docker push $(DOCKER_IMAGE_NAME):latest + clean: rm -rf release rm -rf data - rm -rf vendor rm -rf bin -.PHONY: lint watch build vendor tidy release \ No newline at end of file +.PHONY: lint watch build tidy release \ No newline at end of file diff --git a/cmd/server/container.go b/cmd/server/container.go index 2feb23b..8c0a9ae 100644 --- a/cmd/server/container.go +++ b/cmd/server/container.go @@ -3,7 +3,6 @@ package main import ( "log" "net/http" - "time" "gitlab.com/wpetit/goweb/cqrs" "gitlab.com/wpetit/goweb/template/html" @@ -104,7 +103,14 @@ func getServiceContainer(conf *config.Config) (*service.Container, error) { // Create and expose config service provider ctn.Provide(config.ServiceName, config.ServiceProvider(conf)) - ctn.Provide(hydra.ServiceName, hydra.ServiceProvider(conf.Hydra.BaseURL, 30*time.Second)) + ctn.Provide( + hydra.ServiceName, + hydra.ServiceProvider( + conf.Hydra.BaseURL, + conf.Hydra.FakeSSLTermination, + conf.Hydra.HTTPClientTimeout, + ), + ) ctn.Provide(mail.ServiceName, mail.ServiceProvider( mail.WithServer(conf.SMTP.Host, conf.SMTP.Port), diff --git a/cmd/server/main.go b/cmd/server/main.go index 29f22c7..7fa98df 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -1,20 +1,20 @@ package main import ( + "flag" + "fmt" + "log" "net/http" + "os" "forge.cadoles.com/wpetit/hydra-passwordless/internal/route" + "github.com/getsentry/sentry-go" "github.com/go-chi/chi" "github.com/go-chi/chi/middleware" "gitlab.com/wpetit/goweb/middleware/container" - "flag" - "fmt" - "log" - - "os" - "forge.cadoles.com/wpetit/hydra-passwordless/internal/config" + sentryhttp "github.com/getsentry/sentry-go/http" "github.com/pkg/errors" ) @@ -73,7 +73,6 @@ func main() { } else { conf = config.NewDefault() } - } // Dump configuration if asked @@ -85,6 +84,34 @@ func main() { os.Exit(0) } + if err := config.WithEnvironment(conf); err != nil { + log.Fatalf("%+v", errors.Wrap(err, "could not override config with environment")) + } + + useSentry := conf.Sentry.DSN != "" + + if useSentry { + var sentryEnv string + if conf.Sentry.Environment == "" { + sentryEnv, _ = os.Hostname() + } else { + sentryEnv = conf.Sentry.Environment + } + + err := sentry.Init(sentry.ClientOptions{ + Dsn: conf.Sentry.DSN, + Debug: conf.Debug, + SampleRate: conf.Sentry.ServerSampleRate, + Release: ProjectVersion + "-" + GitRef, + Environment: sentryEnv, + }) + if err != nil { + log.Fatalf("%+v", errors.Wrap(err, "could not initialize sentry")) + } + + defer sentry.Flush(conf.Sentry.ServerFlushTimeout) + } + // Create service container ctn, err := getServiceContainer(conf) if err != nil { @@ -95,7 +122,15 @@ func main() { // Define base middlewares r.Use(middleware.Logger) - r.Use(middleware.Recoverer) + // r.Use(middleware.Recoverer) + + if useSentry { + sentryMiddleware := sentryhttp.New(sentryhttp.Options{ + Repanic: true, + }) + + r.Use(sentryMiddleware.Handle) + } // Expose service container on router r.Use(container.ServiceContainer(ctn)) @@ -109,4 +144,4 @@ func main() { if err := http.ListenAndServe(conf.HTTP.Address, r); err != nil { log.Fatalf("%+v", errors.Wrapf(err, "could not listen on '%s'", conf.HTTP.Address)) } -} \ No newline at end of file +} diff --git a/cmd/server/template/blocks/base.html.tmpl b/cmd/server/template/blocks/base.html.tmpl index 5efee57..dde7bae 100644 --- a/cmd/server/template/blocks/base.html.tmpl +++ b/cmd/server/template/blocks/base.html.tmpl @@ -7,7 +7,7 @@ {{block "title" . -}}{{- end}} {{- block "head_style" . -}} - + {{end}} {{- block "head_script" . -}}{{end}} diff --git a/cmd/server/template/layouts/consent.html.tmpl b/cmd/server/template/layouts/consent.html.tmpl index 0c86046..731a1e4 100644 --- a/cmd/server/template/layouts/consent.html.tmpl +++ b/cmd/server/template/layouts/consent.html.tmpl @@ -13,7 +13,7 @@ Autorisez vous l'application à utiliser ces informations vous concernant ?

-
+ {{range .RequestedScope}}