Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Environment Variables section in docs #171

Merged
merged 6 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ parts:
chapters:
- file: user-guide/cli
- file: user-guide/github
- file: user-guide/env-vars
- file: user-guide/secrets
- file: user-guide/password
- file: user-guide/resources
- file: user-guide/gpu
Expand Down
2 changes: 1 addition & 1 deletion doc/apps/chainlit.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ we can still use Chainlit's authentication feature.
First, download the [sample code](https://github.com/ploomber/doc/tree/main/examples/chainlit/chainlit-with-password).
The `Dockerfile` remains the same, the only change happens in the `app.py`.

During deployment, you need to provide three [environment variables](../user-guide/env-vars.md):
During deployment, you need to provide three [secrets](../user-guide/secrets.md):

```sh
CHAINTLIT_USERNAME="user"
Expand Down
2 changes: 1 addition & 1 deletion doc/apps/jupyterlab.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ following locally (you can define an alternative token, but this is more secure)
python -c 'import secrets; print(secrets.token_urlsafe())'
```

Copy the printed value (store it somewhere safe) and save it as a [secret](../user-guide/env-vars.md), with
Copy the printed value (store it somewhere safe) and save it as a [secret](../user-guide/secrets.md), with
the name `KG_AUTH_TOKEN`, now click on `CREATE`.

Once the application is running, copy the URL (the `someid.ploomberapp.io` URL):
Expand Down
Binary file removed doc/static/env-vars/env-vars-plus.png
Binary file not shown.
Binary file removed doc/static/env-vars/env-vars-sample.png
Binary file not shown.
Binary file removed doc/static/env-vars/env-vars-section.png
Binary file not shown.
Binary file added doc/static/secrets/secrets-plus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/static/secrets/secrets-sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/static/secrets/secrets-section.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions doc/user-guide/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ ploomber-cloud examples flask/basic-app

A full list of example applications is available [here](https://github.com/bryannho/doc/tree/main/examples)

## Defining environment variables
## Defining secrets

If your project uses environment variables, you can define them in an `.env` file.
If your project uses secrets, you can define them in an `.env` file.

In your main project directory, create an `.env` file. Open it in your code editor, and enter your environment variables. It should look like this:
In your main project directory, create an `.env` file. Open it in your code editor, and enter your secrets. It should look like this:
neelasha23 marked this conversation as resolved.
Show resolved Hide resolved

```
MY_ENV_VAR_1=value_1
MY_ENV_VAR_2=value_2
MY_SECRET_1=value_1
MY_SECRET_2=value_2
```

Now make sure your project has been [initialized](init), and deploy it:
Expand All @@ -111,7 +111,7 @@ Now make sure your project has been [initialized](init), and deploy it:
ploomber-cloud deploy
```

The command-line interface will automatically read and encrypt your environment variables and include them in the deployment.
For security reasons, your `.env` file is replaced with an empty file at runtime. Ploomber only stores your encrypted environment variables.
The command-line interface will automatically read and encrypt your secrets and include them in the deployment.
For security reasons, your `.env` file is replaced with an empty file at runtime. Ploomber only stores your encrypted secrets.

To learn how to read your environment variables from within your application, see [Reading variables.](./env-vars.md)
To learn how to read your secrets from within your application, see [Reading secrets.](./secrets.md)
47 changes: 0 additions & 47 deletions doc/user-guide/env-vars.md

This file was deleted.

2 changes: 1 addition & 1 deletion doc/user-guide/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ If you want to increase or reduce the resources provisioned for an existing appl

![](../static/resources/redeploy.png)

You'll need to provide the source code and environment variables again. In the last section, you'll be able to choose the resources to provision.
You'll need to provide the source code again. In the last section, you'll be able to choose the resources to provision.
43 changes: 43 additions & 0 deletions doc/user-guide/secrets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Secrets

```{tip}
You can safely store API keys as secrets as all values are encrypted.
```

If your application requires secrets, you can define them when
deploying it. To expand the section click on the triangle to the left:


![](../static/secrets/secrets-section.png)


Then, add the secrets keys and values:

![](../static/secrets/secrets-sample.png)

To add more, click on the button below:

![](../static/secrets/secrets-plus.png)


```{tip}
You can also define secrets using the [command-line interface.](./cli.md)
```

## Reading secrets

To read the secrets, use the following Python code:

```python
from os import environ

value = environ.get("MY_SECRET")

if value is None:
print("MY_SECRET is undefined!")
else:
print(f"MY_SECRET: {value}")
```


A complete example is available [here.](https://github.com/ploomber/doc/blob/main/examples/voila/secret/app.ipynb)
3 changes: 0 additions & 3 deletions examples/voila/env-variable/README.md

This file was deleted.

3 changes: 3 additions & 0 deletions examples/voila/secret/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Secret

A simple app for demonstrating how to access secrets in Ploomber Cloud.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"source": [
"from os import environ\n",
"\n",
"value = environ.get(\"ENV_VAR\", None)"
"value = environ.get(\"SECRET\", None)"
]
},
{
Expand All @@ -28,15 +28,15 @@
],
"source": [
"if value is None:\n",
" print(\"ENV_VAR is undefined\")\n",
" print(\"SECRET is undefined\")\n",
"else:\n",
" print(f\"EN_VAR: {value}\")"
" print(f\"SECRET: {value}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3.11.5 64-bit",
"language": "python",
"name": "python3"
},
Expand All @@ -51,6 +51,11 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
},
"vscode": {
"interpreter": {
"hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e"
}
}
},
"nbformat": 4,
Expand Down