Skip to content

Commit f155100

Browse files
authored
Add .env to export environment variables (#1154)
1 parent 1428523 commit f155100

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

Diff for: cli/cmd/deploy.go

+5
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ func findProjectFiles(provider types.ProviderType, configPath string) ([]string,
149149
return nil, err
150150
}
151151

152+
dotEnvPath := path.Join(projectRoot, ".env")
153+
if files.IsFile(dotEnvPath) {
154+
projectPaths = append(projectPaths, dotEnvPath)
155+
}
156+
152157
return projectPaths, nil
153158
}
154159

Diff for: docs/deployments/predictors.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ The response type of the predictor can vary depending on your requirements, see
1414

1515
## Project files
1616

17-
Cortex makes all files in the project directory (i.e. the directory which contains `cortex.yaml`) available for use in your Predictor implementation. Python bytecode files (`*.pyc`, `*.pyo`, `*.pyd`), files or folders that start with `.`, and the api configuration file (e.g. `cortex.yaml`) are excluded. You may also add a `.cortexignore` file at the root of the project directory, which follows the same syntax and behavior as a [.gitignore file](https://git-scm.com/docs/gitignore).
17+
Cortex makes all files in the project directory (i.e. the directory which contains `cortex.yaml`) available for use in your Predictor implementation. Python bytecode files (`*.pyc`, `*.pyo`, `*.pyd`), files or folders that start with `.`, and the api configuration file (e.g. `cortex.yaml`) are excluded.
1818

19-
For example, if this is your project directory:
19+
The following files can also be added at the root of the project's directory:
20+
21+
* `.cortexignore` file, which follows the same syntax and behavior as a [.gitignore file](https://git-scm.com/docs/gitignore).
22+
* `.env` file, which exports environment variables that can be used in the predictor. Each line of this file must follow the `VARIABLE=value` format.
2023

2124
```text
2225
./iris-classifier/

Diff for: pkg/workloads/cortex/serve/run.sh

+12-5
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,29 @@ mkdir -p /mnt/requests
2121

2222
cd /mnt/project
2323

24-
# If the container restarted, ensure that it is not perceived as ready
24+
# if the container restarted, ensure that it is not perceived as ready
2525
rm -rf /mnt/workspace/api_readiness.txt
2626

27-
# Allow for the liveness check to pass until the API is running
27+
# allow for the liveness check to pass until the API is running
2828
echo "9999999999" > /mnt/workspace/api_liveness.txt
2929

3030
export PYTHONPATH=$PYTHONPATH:$PYTHON_PATH
31+
# ensure predictor print() statements are always flushed
32+
export PYTHONUNBUFFERED=TRUE
3133

3234
if [ "$CORTEX_PROVIDER" != "local" ]; then
3335
sysctl -w net.core.somaxconn=$CORTEX_SO_MAX_CONN >/dev/null
3436
sysctl -w net.ipv4.ip_local_port_range="15000 64000" >/dev/null
3537
sysctl -w net.ipv4.tcp_fin_timeout=30 >/dev/null
3638
fi
3739

40+
# export environment variables
41+
if [ -f "/mnt/project/.env" ]; then
42+
set -a
43+
source /mnt/project/.env
44+
set +a
45+
fi
46+
3847
# execute script if present in project's directory
3948
if [ -f "/mnt/project/dependencies.sh" ]; then
4049
bash -e /mnt/project/dependencies.sh
@@ -62,7 +71,5 @@ if [ -f "/mnt/project/requirements.txt" ]; then
6271
pip --no-cache-dir install -r /mnt/project/requirements.txt
6372
fi
6473

65-
# Ensure predictor print() statements are always flushed
66-
export PYTHONUNBUFFERED=TRUE
67-
74+
# run webserver
6875
/opt/conda/envs/env/bin/python /src/cortex/serve/start_uvicorn.py

0 commit comments

Comments
 (0)