From c43d0e729502eff04ffc1f4c27067961d7dfd8ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=B6hlmann?= Date: Tue, 28 Mar 2023 16:43:25 +0300 Subject: [PATCH] feat: add docker file for static server example --- example/server/main.go | 11 ++++++++--- static-op.Dockerfile | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 static-op.Dockerfile diff --git a/example/server/main.go b/example/server/main.go index a2836ea..cab5e30 100644 --- a/example/server/main.go +++ b/example/server/main.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "net/http" + "os" "github.com/zitadel/oidc/v2/example/server/exampleop" "github.com/zitadel/oidc/v2/example/server/storage" @@ -12,8 +13,12 @@ import ( func main() { //we will run on :9998 port := "9998" - //which gives us the issuer: http://localhost:9998/ - issuer := fmt.Sprintf("http://localhost:%s/", port) + + issuer, ok := os.LookupEnv("ISSUER") + if !ok { + //which gives us the issuer: http://localhost:9998/ + issuer = fmt.Sprintf("http://localhost:%s/", port) + } // the OpenIDProvider interface needs a Storage interface handling various checks and state manipulations // this might be the layer for accessing your database @@ -26,7 +31,7 @@ func main() { Addr: ":" + port, Handler: router, } - log.Printf("server listening on http://localhost:%s/", port) + log.Printf("server listening on %s", issuer) log.Println("press ctrl+c to stop") err := server.ListenAndServe() if err != nil { diff --git a/static-op.Dockerfile b/static-op.Dockerfile new file mode 100644 index 0000000..6d154cb --- /dev/null +++ b/static-op.Dockerfile @@ -0,0 +1,15 @@ +FROM golang:latest as build + +COPY go.mod go.sum /build/ +WORKDIR /build +RUN go mod download -x + +COPY . /build/ +RUN go build ./example/server + +FROM busybox:glibc +COPY --from=build /build/server /usr/local/bin/server + +ENV ISSUER=http://localhost:9998/ +EXPOSE 9998 +CMD [ "/usr/local/bin/server" ]