PortSpec
The PortSpec constructor creates a PortSpec object that encapsulates information pertaining to a port.
port_spec = PortSpec(
# The port number which we want to expose
# MANDATORY
number = 3000,
# Transport protocol for the port (can be either "TCP" or "UDP")
# OPTIONAL (DEFAULT:"TCP")
transport_protocol = "TCP",
# Application protocol for the port that will be displayed in front of URLs containing the port
# For example:
# "http" to get a URL of "http://..."
# "postgresql" to get a URL of "postgresql://..."
# OPTIONAL (DEFAULT:"http")
application_protocol = "http",
# Kurtosis will automatically perform a check to ensure all declared UDP and TCP ports are open and ready for traffic and connections upon startup.
# You may specify a custom wait timeout duration or disable the feature entirely.
# You may specify a custom wait timeout duration with a string:
# wait = "2m"
# Or, you can disable this feature by setting the value to None:
# wait = None
# The feature is enabled by default with a default timeout of 15s
# OPTIONAL (DEFAULT:"15s")
wait = "4s"
# A url that points to this port
# If this is not set then Kurtosis creates a URL using the application protocol, service name and port number
# OPTIONAL (DEFAULT: "")
url = ""
# The IPv4 address of the host machine interface that this port is published on
# Only used on Docker, for ports in `ports` (random host port) and `public_ports` (fixed host port)
# Set it to "0.0.0.0" to make the port reachable from other machines, e.g. for P2P ports
# OPTIONAL (DEFAULT: "127.0.0.1")
host_ip = "127.0.0.1"
)
The above constructor returns a PortSpec object that defines information about a port for use in add_service.
Ports are published on the host machine's loopback interface (127.0.0.1) by default, so they are reachable only from the machine running Kurtosis. To reach a port from another machine, set host_ip = "0.0.0.0" on it; list it in ServiceConfig.public_ports as well if it needs a fixed host port. Anything published this way is reachable by everyone who can reach the host, and Docker publishes ports ahead of host firewalls such as ufw, so only use it for ports that are safe to expose.
The wait field represents the timeout duration that Kurtosis will use when checking whether a service's declared UDP or TCP port are open and ready for traffic and connections upon startup. This is the default way to perform a readiness check using Kurtosis. However, there are other ways to perform a readiness check. Specifically, you can also use ServiceConfig.ReadyConditions to check if a service is ready with a a REST call, or you can use the Wait instruction if you need to perform a one-off readiness check after service startup.