diff --git a/Dockerfile b/Dockerfile index c859b65..59fbb9a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.11.1-alpine AS builder +FROM golang:1.12-alpine AS builder RUN apk update && apk add --no-cache git gcc musl-dev WORKDIR /build COPY . . diff --git a/README.md b/README.md index 3c6e5c0..6017342 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,13 @@ Download the latest release and run the command: ./jira-to-slack ``` +It binds port 3000 by default. +You can set the port by `PORT` environment variable. + +```sh +PORT=8080 ./jira-to-slack +``` + ### Docker Run the Docker image as follows: diff --git a/main.go b/main.go index 138c865..edde051 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,8 @@ import ( var version string +const defaultPort = "3000" + func router() http.Handler { r := mux.NewRouter() r.Handle("/", &handlers.Index{}).Methods("GET") @@ -25,7 +27,13 @@ func router() http.Handler { func main() { log.Printf("jira-to-slack %s", version) - addr := ":3000" + + port := os.Getenv("PORT") + if port == "" { + port = defaultPort + } + addr := ":" + port + log.Printf("Listening on %s", addr) if err := http.ListenAndServe(addr, router()); err != nil { log.Fatalf("Error while listening on %s: %s", addr, err)