Skip to content

Commit

Permalink
use --port from PORT env var
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Webber <[email protected]>
  • Loading branch information
sebastianwebber committed Sep 29, 2023
1 parent f932895 commit d1fff70
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cmd/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FROM alpine:3.13 as builder
FROM scratch
EXPOSE 3000
ENV PORT=3000

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

WORKDIR /app
COPY api /app
COPY *.yml /app
CMD ["/app/api"]

ENTRYPOINT [ "/app/api" ]
16 changes: 15 additions & 1 deletion cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"flag"
"fmt"
"log"
"os"
"strconv"

_ "github.com/pgconfig/api/cmd/api/docs" // docs is generated by Swag CLI, you have to import it.
v1 "github.com/pgconfig/api/cmd/api/handlers/v1"
Expand All @@ -18,8 +20,20 @@ var (
docsFile string
)

func getDefaultPort(envName string) int {
defaultPort := 3000
val := os.Getenv(envName)

out, err := strconv.Atoi(val)
if err != nil {
return defaultPort
}

return out
}

func init() {
flag.IntVar(&port, "port", 3000, "Listen port")
flag.IntVar(&port, "port", getDefaultPort("PORT"), "Listen port")
flag.StringVar(&rulesFile, "rules-file", "./rules.yml", "Rules file")
flag.StringVar(&docsFile, "docs-file", "./pg-docs.yml", "Rules file")
flag.Parse()
Expand Down

0 comments on commit d1fff70

Please sign in to comment.