aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaul Benencia <raul@thousandeyes.com>2021-01-12 16:57:26 -0800
committerRaul Benencia <46945030+raul-te@users.noreply.github.com>2021-01-13 10:50:35 -0800
commitcfa915142c2bbff8d1572488b6343e56dfef9b64 (patch)
tree66961e8009fb10e84ddec3b55633d8cd4769cff8
parentfa13436d4ceba235081c9eedb8d6f586ea21e7aa (diff)
Segregate BindAddr and BaseURL
-rw-r--r--Dockerfile6
-rw-r--r--configs/shoelaces.conf3
-rw-r--r--docs/shoelaces.8.scd20
-rw-r--r--internal/environment/environment.go10
-rw-r--r--internal/environment/flags.go4
-rw-r--r--main.go4
-rwxr-xr-xtest/integ-test/integ_test.py11
7 files changed, 29 insertions, 29 deletions
diff --git a/Dockerfile b/Dockerfile
index 3c9da89..b2c4904 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -13,7 +13,9 @@ COPY --from=build /tmp/shoelaces /shoelaces
WORKDIR /data
COPY --from=build /tmp/mappings.yaml mappings.yaml
COPY --from=build /shoelaces/web /web
-ENV DOMAIN=0.0.0.0
-ENV PORT=8081
+
+ENV BIND_ADDR=0.0.0.0:8081
+EXPOSE 8081
+
ENTRYPOINT ["/shoelaces"]
CMD ["-data-dir", "/data", "-static-dir", "/web"]
diff --git a/configs/shoelaces.conf b/configs/shoelaces.conf
index b4ed606..5e69d74 100644
--- a/configs/shoelaces.conf
+++ b/configs/shoelaces.conf
@@ -1,5 +1,4 @@
-port=8081
-domain=localhost
+bind-addr=localhost:8081
data-dir=configs/data-dir/
template-extension=.slc
mappings-file=mappings.yaml
diff --git a/docs/shoelaces.8.scd b/docs/shoelaces.8.scd
index ec38101..492b452 100644
--- a/docs/shoelaces.8.scd
+++ b/docs/shoelaces.8.scd
@@ -10,6 +10,15 @@ shoelaces - automated server bootstrapping
# OPTIONS
+*-base-url* <string>
+ Optional parameter. Specifies the base address that will be used when
+ generating URLs.
+ If it's not specified, the value of "-bind-addr" will be used.
+
+*-bind-addr* <host:port>
+ The address where Shoelaces will listen for requests. Defaults to
+ "localhost:8081".
+
*-config* <config>
Specifies a config file. All the following options can be specified in
the config.
@@ -20,10 +29,6 @@ shoelaces - automated server bootstrapping
*-debug*
Enables debug mode.
-*-domain* <hostname>
- Specifies the address where the server is going to listen.
- Defaults to "localhost".
-
*-env-dir* <directory>
Specifies a directory with environment overrides. Refer to the README of
the project for more information about environment overrides.
@@ -32,10 +37,6 @@ shoelaces - automated server bootstrapping
Specifies a mappings YAML file. Defaults to "mappings.yaml". Refer to the
README of the project for more information about mappings.
-*-port* <port>
- Specifies the port where the server is going to listen.
- Defaults to 8080.
-
*-static-dir* <directory>
Specifies a custom web directory with static files. Defaults to "web".
@@ -73,8 +74,7 @@ specified.
Here is example config file:
```
-port=8081
-domain=localhost
+bind-addr=localhost:8081
data-dir=/etc/shoelaces/data-dir/
template-extension=.slc
mappings-file=mappings.yaml
diff --git a/internal/environment/environment.go b/internal/environment/environment.go
index eac0430..8dad2c9 100644
--- a/internal/environment/environment.go
+++ b/internal/environment/environment.go
@@ -35,7 +35,6 @@ import (
// Environment struct holds the shoelaces instance global data.
type Environment struct {
ConfigFile string
- BaseURL string
HostnameMaps []mappings.HostnameMap
NetworkMaps []mappings.NetworkMap
ServerStates *server.States
@@ -46,8 +45,8 @@ type Environment struct {
Environments []string // Valid config environments
Logger log.Logger
- Port int
- Domain string
+ BindAddr string
+ BaseURL string
DataDir string
StaticDir string
EnvDir string
@@ -66,7 +65,10 @@ func New() *Environment {
env.Logger = log.AllowDebug(env.Logger)
}
- env.BaseURL = fmt.Sprintf("%s:%d", env.Domain, env.Port)
+ if env.BaseURL == "" {
+ env.BaseURL = env.BindAddr
+ }
+
env.Environments = env.initEnvOverrides()
env.EventLog = &event.Log{}
diff --git a/internal/environment/flags.go b/internal/environment/flags.go
index 8250690..bbb7d1a 100644
--- a/internal/environment/flags.go
+++ b/internal/environment/flags.go
@@ -23,8 +23,8 @@ import (
func (env *Environment) setFlags() {
flag.StringVar(&env.ConfigFile, "config", "", "My config file")
- flag.IntVar(&env.Port, "port", 8080, "The port where I'm going to listen")
- flag.StringVar(&env.Domain, "domain", "localhost", "The address where I'm going to listen")
+ flag.StringVar(&env.BindAddr, "bind-addr", "localhost:8081", "The address where I'm going to listen")
+ flag.StringVar(&env.BaseURL, "base-url", "", "The base shoelaces URL. If it's not defined, it will default to bind-addr.")
flag.StringVar(&env.DataDir, "data-dir", "", "Directory with mappings, configs, templates, etc.")
flag.StringVar(&env.StaticDir, "static-dir", "web", "A custom web directory with static files")
flag.StringVar(&env.EnvDir, "env-dir", "env_overrides", "Directory with overrides")
diff --git a/main.go b/main.go
index e66f6e4..9d5c148 100644
--- a/main.go
+++ b/main.go
@@ -27,8 +27,8 @@ func main() {
env := environment.New()
app := handlers.MiddlewareChain(env).Then(router.ShoelacesRouter(env))
- env.Logger.Info("component", "main", "transport", "http", "addr", env.BaseURL, "msg", "listening")
- env.Logger.Error("component", "main", "err", http.ListenAndServe(env.BaseURL, app))
+ env.Logger.Info("component", "main", "transport", "http", "addr", env.BindAddr, "msg", "listening")
+ env.Logger.Error("component", "main", "err", http.ListenAndServe(env.BindAddr, app))
os.Exit(1)
}
diff --git a/test/integ-test/integ_test.py b/test/integ-test/integ_test.py
index 4f02fe3..8cc1761 100755
--- a/test/integ-test/integ_test.py
+++ b/test/integ-test/integ_test.py
@@ -29,9 +29,8 @@ import datetime
import dateutil.parser
from requests.exceptions import RequestException
-API_HOST = 'localhost'
-API_PORT = '18888'
-API_URL = "http://{}:{}".format(API_HOST, API_PORT)
+API_ADDR = 'localhost:18888'
+API_URL = "http://{}".format(API_ADDR)
TEST_DIR = os.path.dirname(os.path.abspath(__file__))
BASE_DIR = os.path.dirname(os.path.dirname(TEST_DIR))
FIXTURE_DIR = os.path.join(TEST_DIR, 'expected-results')
@@ -49,15 +48,13 @@ def shoelaces_binary():
@pytest.fixture(scope="session", autouse=True)
def config_file(shoelaces_binary):
""" Create a temporary config file """
- temp_config_tpl = string.Template("domain=$host\n"
- "port=$port\n"
+ temp_config_tpl = string.Template("bind-addr=$bind_addr\n"
"data-dir=integ-test-configs\n"
"static-dir=$static_dir\n"
"template-extension=.slc\n"
"mappings-file=mappings.yaml\n"
"debug=true\n")
- temp_config = temp_config_tpl.substitute(host=API_HOST,
- port=API_PORT,
+ temp_config = temp_config_tpl.substitute(bind_addr=API_ADDR,
static_dir=STATIC_DIR)
sys.stderr.write("Using:\n{}".format(temp_config))
nihil fit ex nihilo