Skip to content

Commit

Permalink
Include static files in prod dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
peppys committed May 31, 2021
1 parent cb51f41 commit e33c21a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
11 changes: 2 additions & 9 deletions cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,14 @@ import (
"google.golang.org/grpc/reflection"
"log"
"net/http"
"os"
"path"
"strings"

"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
)

var workingDirectory string

func main() {
dir, err := os.Getwd(); if err != nil {
log.Fatal(err)
}
workingDirectory = dir
server := grpc.NewServer(buildServerOpts()...)
reflection.Register(server)

Expand Down Expand Up @@ -75,7 +68,7 @@ func openapiFileHandler() http.Handler {

log.Printf("Serving %s", r.URL.Path)
p := strings.TrimPrefix(r.URL.Path, "/openapiv2/")
p = path.Join(workingDirectory, "gen/openapiv2/", p)
p = path.Join("gen/openapiv2/", p)
http.ServeFile(w, r, p)
})
}
Expand All @@ -92,7 +85,7 @@ func swaggerUIHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Printf("Serving %s", r.URL.Path)
p := strings.TrimPrefix(r.URL.Path, "/swagger-ui/")
p = path.Join(workingDirectory, "swagger-ui/", p)
p = path.Join("swagger-ui/", p)
http.ServeFile(w, r, p)
})
}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
api:
build:
context: .
dockerfile: ./infra/dev/.
dockerfile: ./infra/dev/Dockerfile
ports:
- '8080:8080'
working_dir: /opt/app
Expand Down
2 changes: 2 additions & 0 deletions infra/prod/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ RUN apt-get update
RUN apt-get install -y ca-certificates

COPY --from=builder /bin/api /bin/api
COPY --from=builder /opt/app/swagger-ui ./swagger-ui
COPY --from=builder /opt/app/gen/openapiv2 ./gen/openapiv2

# Start API
ENTRYPOINT /bin/api

0 comments on commit e33c21a

Please sign in to comment.