diff options
-rw-r--r-- | Dockerfile | 6 | ||||
-rw-r--r-- | configs/shoelaces.conf | 3 | ||||
-rw-r--r-- | docs/shoelaces.8.scd | 20 | ||||
-rw-r--r-- | internal/environment/environment.go | 10 | ||||
-rw-r--r-- | internal/environment/flags.go | 4 | ||||
-rw-r--r-- | main.go | 4 | ||||
-rwxr-xr-x | test/integ-test/integ_test.py | 11 |
7 files changed, 29 insertions, 29 deletions
@@ -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") @@ -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)) |