Port offset

Table of contents

Introduction

Every product shifts the host ports of its features by an amount derived from its name, so several products run on one machine without collisions. The shift is the same on every run, so your ports never move.

  ports    adjusted 4 feature port(s) (+591)

That is product:env --merge in my_first_app, whose offset is 591.


How the offset is applied

One feature default, a different host port per product splent_feature_cache REDIS_HOST_PORT=6380 the feature's default + crc32(product) % 1000 my_first_app 6380 + 591 = 6971 my_shop 6380 + 702 = 7082
Both products run Redis at once, each on its own host port. A port the product sets itself is used as written.
offset = crc32(product_name.encode("utf-8")) % 1000

product:env --merge and product:build add the offset to every feature port, a numeric variable whose name ends in _HOST_PORT or contains _PORT_ONE or _PORT_TWO. A port your product sets itself, in its env file or its [tool.splent.config], is used as written. The features’ own files and your product’s ports, such as the web server’s, are never touched.

Server Variable Base port In my_first_app
A cache REDIS_HOST_PORT 6380 6971
A database UI DBUI_HOST_PORT 8081 8672
A mail catcher, SMTP MAILCATCHER_SMTP_HOST_PORT 1025 1616
A mail catcher, web UI MAILCATCHER_UI_HOST_PORT 8025 8616

Declaring a port in your feature

Name the variable with a _HOST_PORT suffix, give it a base value away from common system ports in docker/.env.example, and use it in the compose file.

PROXY_HTTP_HOST_PORT=8088
ports:
  - "${PROXY_HTTP_HOST_PORT}:80"

Features that run a server has the rest of the rules.


See also


Back to top

splent. Distributed by an LGPL license v3. Contact us: drorganvidez@us.es