From 3ac519b7921d6b4c616cf9c21699d30e1e217382 Mon Sep 17 00:00:00 2001 From: Hunter Long Date: Wed, 19 Dec 2018 20:29:38 -0800 Subject: [PATCH] port and ip as ENV for docker --- Dockerfile | 4 ++-- cmd/cli.go | 4 +++- cmd/main.go | 6 ++++++ heroku.yml | 4 +++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 90233700..c49a4140 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,6 +30,6 @@ WORKDIR /app VOLUME /app EXPOSE $PORT -HEALTHCHECK --interval=5s --timeout=5s --retries=5 CMD curl -s "http://localhost:8080/health" | jq -r -e ".online==true" +HEALTHCHECK --interval=5s --timeout=5s --retries=5 CMD curl -s "http://localhost:$PORT/health" | jq -r -e ".online==true" -CMD ["statping", "--port", "$PORT"] +CMD statping -port $PORT diff --git a/cmd/cli.go b/cmd/cli.go index e515980a..ae78a73c 100644 --- a/cmd/cli.go +++ b/cmd/cli.go @@ -217,7 +217,9 @@ func HelpEcho() { fmt.Println(" -ip 127.0.0.1 - Run HTTP server on specific IP address (default: localhost)") fmt.Println(" -port 8080 - Run HTTP server on Port (default: 8080)") fmt.Printf("Environment Variables:\n") - fmt.Println(" STATPING_DIR - Set a absolute path for the root path of Statping server (logs, assets, SQL db)") + fmt.Println(" PORT - Set the outgoing port for the HTTP server (or use -port)") + fmt.Println(" IP - Bind a specific IP address to the HTTP server (or use -ip)") + fmt.Println(" STATPING_DIR - Set a absolute path for the root path of Statping server (logs, assets, SQL db)") fmt.Println(" DB_CONN - Automatic Database connection (sqlite, postgres, mysql)") fmt.Println(" DB_HOST - Database hostname or IP address") fmt.Println(" DB_USER - Database username") diff --git a/cmd/main.go b/cmd/main.go index 12a9f28f..d58d6f41 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -51,6 +51,12 @@ func parseFlags() { flag.Parse() ipAddress = *ip port = *p + if os.Getenv("PORT") != "" { + port = int(utils.ToInt(os.Getenv("PORT"))) + } + if os.Getenv("IP") != "" { + ipAddress = os.Getenv("IP") + } } // main will run the Statping application diff --git a/heroku.yml b/heroku.yml index 2b8f79bb..8b223336 100644 --- a/heroku.yml +++ b/heroku.yml @@ -1,3 +1,5 @@ build: docker: - web: Dockerfile \ No newline at end of file + web: Dockerfile +run: + web: statping -port $PORT \ No newline at end of file