Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ARG RELEASE_TAG=develop
ARG RELEASE_TAG=develop
ARG STATIC_DIR=public

FROM golang:alpine as builder

Expand Down Expand Up @@ -34,17 +35,20 @@ RUN make generate
# Build the binary
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags='-w -s -extldflags "-static"' -a \
-o /go/bin/id .
-o $GOPATH/bin/id .

FROM scratch

ARG STATIC_DIR

# Import from builder.
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group

COPY --from=builder /go/bin/id /go/bin/id
COPY --from=builder /go/src/resonatecoop/id/public ${STATIC_DIR}

# Use an unprivileged user.
USER appuser:appuser
Expand Down
7 changes: 2 additions & 5 deletions cmd/run_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// RunServer runs the app
func RunServer(configBackend string) error {
func RunServer(configBackend, staticDir string) error {
cnf, db, err := initConfigDB(true, true, configBackend)
if err != nil {
return err
Expand All @@ -40,7 +40,7 @@ func RunServer(configBackend string) error {
app.Use(negroni.NewLogger())
app.Use(gzip.Gzip(gzip.DefaultCompression))
app.Use(negroni.HandlerFunc(secureMiddleware.HandlerFuncWithNext))
app.Use(negroni.NewStatic(http.Dir("public")))
app.Use(negroni.NewStatic(http.Dir(staticDir)))

// Create a router instance
router := mux.NewRouter()
Expand All @@ -51,9 +51,6 @@ func RunServer(configBackend string) error {

webRoutes := mux.NewRouter()

// Serve static files under ../public
webRoutes.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("../public/"))))

services.WebService.RegisterRoutes(webRoutes, "/web")

CSRF := csrf.Protect(
Expand Down
8 changes: 7 additions & 1 deletion go-oauth2-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
var (
cliApp *cli.App
configBackend string
staticDir string
)

func init() {
Expand All @@ -27,6 +28,11 @@ func init() {
Value: "etcd",
Destination: &configBackend,
},
cli.StringFlag{
Name: "staticDir",
Value: "public",
Destination: &staticDir,
},
}
}

Expand All @@ -37,7 +43,7 @@ func main() {
Name: "runserver",
Usage: "run web server",
Action: func(c *cli.Context) error {
return cmd.RunServer(configBackend)
return cmd.RunServer(configBackend, staticDir)
},
},
}
Expand Down