Environment variables exposed by Patr
When running a container on Patr, there are several environment variables that are automatically set by the platform to provide information about the deployment environment. These variables can be used to perform special actions within the container, such as accessing configuration information or verifying the deployment environment.
PATR
The PATR
environment variable is a constant value that is always set to true
. This variable can be used to check if the container is running on Patr, allowing for custom logic to be applied for containers running on the platform.
if [ "$PATR" = true ]; then
# Perform special actions for containers running on Patr
else
# Perform default actions for containers running outside of Patr
fi
WORKSPACE_ID
The WORKSPACE_ID
environment variable is set to the unique identifier of the workspace that the deployment is running on. This variable can be used to access workspace-specific configuration information or to perform actions specific to the workspace.
# Access workspace-specific configuration information
CONFIG_FILE=/path/to/config/${WORKSPACE_ID}.config
DEPLOYMENT_ID
The DEPLOYMENT_ID
environment variable is set to the unique identifier of the deployment that is currently running. This variable can be used to track and log deployment activity, or to perform actions specific to the deployment.
# Log deployment activity
echo "Deployment ${DEPLOYMENT_ID} started at $(date)"
DEPLOYMENT_NAME
The DEPLOYMENT_NAME
environment variable is set to the name of the deployment that is currently running. This variable can be used to perform actions specific to the deployment name, such as accessing deployment-specific configuration information.
# Access deployment-specific configuration information
CONFIG_FILE=/path/to/config/${DEPLOYMENT_NAME}.config
CONFIG_MAP_HASH
The CONFIG_MAP_HASH
environment variable is set to an sha512 sum of all the config mount contents for the deployment. This variable can be used to verify the validity of the config mounts, in case of any tampering.
# Verify config mount contents
if [ "$(echo $CONFIG_MAP_HASH | sha512sum -c --status)" != "OK" ]; then
echo "Config mount contents have been tampered with"
fi
Overall, these environment variables provide a convenient and powerful way to perform actions specific to the deployment environment on Patr. By utilizing these variables, you can create more robust and flexible containerized applications on the platform.