Skip to content

Commit b73087c

Browse files
Bordaalecmerdleredenlightningethanwharris
authored
Releasing app 0.7 (#15197)
* Support Injecting Secrets into Apps Running in the Cloud (#14612) Adds a new '--secret' flag to 'lightning run app': lightning run app --cloud --secret MY_SECRET=my-secret-name app.py When the Lightning App runs in the cloud, the 'MY_SECRET' environment variable will be populated with the value of the referenced Secret. The value of the Secret is encrypted in the database, and will only be decrypted and accessible to the Flow/Work processes in the cloud. Co-authored-by: Sherin Thomas <[email protected]> Co-authored-by: Noha Alon <[email protected]> Co-authored-by: thomas chaton <[email protected]> (cherry picked from commit 71719b9) * secrets docs (#14951) * secrets docs * Update docs/source-app/glossary/secrets.rst Co-authored-by: Yurij Mikhalevich <[email protected]> * Apply suggestions from code review Co-authored-by: Adrian Wälchli <[email protected]> * Update secrets.rst * links Co-authored-by: Yurij Mikhalevich <[email protected]> Co-authored-by: Jirka Borovec <[email protected]> Co-authored-by: Adrian Wälchli <[email protected]> Co-authored-by: Jirka <[email protected]> (cherry picked from commit 8715cd0) # Conflicts: # docs/source-app/glossary/secrets.rst * Add support for command descriptions (#15193) (cherry picked from commit 4acb10f) * docs: temp drop S3 from index (#15099) Co-authored-by: awaelchli <[email protected]> (cherry picked from commit 05d91c8) * version 0.7.0 * chlog join 0.6.3 & 0.7 Co-authored-by: Alec Merdler <[email protected]> Co-authored-by: edenlightning <[email protected]> Co-authored-by: Ethan Harris <[email protected]>
1 parent 9417739 commit b73087c

File tree

29 files changed

+479
-30
lines changed

29 files changed

+479
-30
lines changed

docs/source-app/glossary/environment_variables.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
Environment Variables
55
*********************
66

7-
If your app is using secrets or values you don't want to expose in your app code such as API keys or access tokens, you can use environment variables.
7+
If your App is using configuration values you don't want to commit with your App source code, you can use environment variables.
88

9-
Lightning allows you to set environment variables when running the app from the CLI with the `lightning run app` command. You can use environment variables to pass any value such as API keys or other similar configurations to the app, avoiding having to stick them in the source code.
9+
Lightning allows you to set environment variables when running the App from the CLI with the `lightning run app` command. You can use environment variables to pass any values to the App, and avoiding sticking those values in the source code.
1010

1111
Set one or multiple variables using the **--env** option:
1212

1313
.. code:: bash
1414
1515
lightning run app app.py --cloud --env FOO=BAR --env BAZ=FAZ
1616
17-
The environment variables are available in all flows and works, and can be accessed as follows:
17+
Environment variables are available in all Flows and Works, and can be accessed as follows:
1818

1919
.. code:: python
2020
@@ -24,4 +24,4 @@ The environment variables are available in all flows and works, and can be acces
2424
print(os.environ["BAZ"]) # FAZ
2525
2626
.. note::
27-
Environment variables are currently not encrypted.
27+
Environment variables are not encrypted. For sensitive values, we recommend using :ref:`Encrypted Secrets <secrets>`.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
.. _secrets:
2+
3+
#################
4+
Encrypted Secrets
5+
#################
6+
7+
Encrypted Secrets allow you to pass private data to your apps, like API keys, access tokens, database passwords, or other credentials, in a secure way without exposing them in your code.
8+
Secrets provide you with a secure way to store this data in a way that is accessible to Apps so that they can authenticate third-party services/solutions.
9+
10+
.. tip::
11+
For non-sensitive configuration values, we recommend using :ref:`plain-text Environment Variables <environment_variables>`.
12+
13+
************
14+
Add a secret
15+
************
16+
17+
Add the secret to your profile on lightning.ai.
18+
Log in to your lightning.ai account > **Profile** > **Secrets** tab > click the **+New** button.
19+
Provide a name and value to your secret, for example, name could be "github_api_token".
20+
21+
.. note::
22+
Secret names must start with a letter and can only contain letters, numbers, dashes, and periods. The Secret names must comply with `RFC1123 naming conventions <https://www.rfc-editor.org/rfc/rfc1123>`_. The Secret value has no restrictions.
23+
24+
.. raw:: html
25+
26+
<br />
27+
<video id="background-video" autoplay loop muted controls poster="https://pl-flash-data.s3.amazonaws.com/assets_lightning/docs/images/storage/encrypted_secrets_login.png" width="100%">
28+
<source src="https://pl-flash-data.s3.amazonaws.com/assets_lightning/docs/images/storage/encrypted_secrets_login.mp4" type="video/mp4" width="100%">
29+
</video>
30+
<br />
31+
<br />
32+
33+
************
34+
Use a secret
35+
************
36+
37+
1. Add an environment variable to your app to read the secret. For example, add an "api_token" environment variable:
38+
39+
.. code:: python
40+
41+
import os
42+
43+
component.connect(api_token=os.environ["api_token"])
44+
45+
2. Pass the secret to your app run with the following command:
46+
47+
.. code:: bash
48+
49+
lightning run app app.py --cloud --secret <environment-variable>=<secret-name>
50+
51+
In this example, the command would be:
52+
53+
.. code:: bash
54+
55+
lightning run app app.py --cloud --secret api_token=github_api_token
56+
57+
58+
The ``--secret`` option can be used for multiple Secrets, and alongside the ``--env`` option.
59+
60+
Here's an example:
61+
62+
.. code:: bash
63+
64+
lightning run app app.py --cloud --env FOO=bar --secret MY_APP_SECRET=my-secret --secret ANOTHER_SECRET=another-secret
65+
66+
67+
----
68+
69+
******************
70+
How does this work
71+
******************
72+
73+
When a Lightning App (App) **runs in the cloud**, a Secret can be exposed to the App using environment variables.
74+
The value of the Secret is encrypted in the Lightning.ai database, and is only decrypted and accessible to
75+
LightningFlow (Flow) or LightningWork (Work) processes in the cloud (when you use the ``--cloud`` option running your App).

docs/source-app/glossary/storage/drive.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ Drive Storage
1010

1111
----
1212

13-
.. include:: ../../glossary/storage/drive_content.rst
13+
.. include:: ../../glossary/storage/drive_content_old.rst

docs/source-app/glossary/storage/drive_content.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
:orphan:
12

23

34
************
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
:orphan:
2+
3+
4+
************
5+
About Drives
6+
************
7+
8+
Lightning Drive storage makes it easy to share files between LightningWorks so you can run your Lightning App both locally and in the cloud without changing the code.
9+
10+
The Drive object provides a central place for your components to share data.
11+
12+
The Drive acts as an isolate folder and any component can access it by knowing its name.
13+
14+
Your components can put, list, get, and delete files from and to the Drive (except LightningFlows).
15+
16+
----
17+
18+
***********************
19+
What Drive does for you
20+
***********************
21+
22+
Think of every instance of the Drive object acting like a Google Drive or like Dropbox.
23+
24+
By sharing the Drive between components through the LightningFlow,
25+
several components can have a shared place to read and write files from.
26+
27+
----
28+
29+
**************
30+
Create a Drive
31+
**************
32+
33+
In order to create a Drive, you simply need to pass its name with the prefix ``lit://`` as follows:
34+
35+
.. code-block:: python
36+
37+
from lightning_app.storage import Drive
38+
39+
# The identifier of this Drive is ``drive_1``
40+
# Note: You need to add Lightning protocol ``lit://`` as a prefix.
41+
42+
drive_1 = Drive("lit://drive_1")
43+
44+
# The identifier of this Drive is ``drive_2``
45+
drive_2 = Drive("lit://drive_2")
46+
47+
Any components can create a drive object.
48+
49+
.. code-block:: python
50+
51+
from lightning_app import LightningFlow, LightningWork
52+
from lightning_app.storage import Drive
53+
54+
55+
class Flow(LightningFlow):
56+
def __init__(self):
57+
super().__init__()
58+
self.drive_1 = Drive("lit://drive_1")
59+
60+
def run(self):
61+
...
62+
63+
64+
class Work(LightningWork):
65+
def __init__(self):
66+
super().__init__()
67+
self.drive_1 = Drive("lit://drive_1")
68+
69+
def run(self):
70+
...
71+
72+
----
73+
74+
*****************************
75+
Supported actions with Drives
76+
*****************************
77+
78+
A Drive supports put, list, get, and delete actions.
79+
80+
.. code-block:: python
81+
82+
from lightning_app.storage import Drive
83+
84+
drive = Drive("lit://drive")
85+
86+
drive.list(".") # Returns [] as empty
87+
88+
# Created file.
89+
with open("a.txt", "w") as f:
90+
f.write("Hello World !")
91+
92+
drive.put("a.txt")
93+
94+
drive.list(".") # Returns ["a.txt"] as the file copied in the Drive during the put action.
95+
96+
drive.get("a.txt") # Get the file into the current worker
97+
98+
drive.delete("a.txt")
99+
100+
drive.list(".") # Returns [] as empty
101+
102+
----
103+
104+
**********************************
105+
Component interactions with Drives
106+
**********************************
107+
108+
Here is an illustrated code example on how to create drives within works.
109+
110+
.. figure:: https://pl-flash-data.s3.amazonaws.com/assets_lightning/drive_2.png
111+
112+
.. code-block:: python
113+
114+
from lightning_app import LightningFlow, LightningWork
115+
from lightning_app.core.app import LightningApp
116+
from lightning_app.storage.drive import Drive
117+
118+
119+
class Work_A(LightningWork):
120+
def __init__(self):
121+
super().__init__()
122+
# The identifier of the Drive is ``drive_1``
123+
# Note: You need to add Lightning protocol ``lit://`` as a prefix.
124+
self.drive_1 = Drive("lit://drive_1")
125+
126+
def run(self):
127+
# 1. Create a file.
128+
with open("a.txt", "w") as f:
129+
f.write("Hello World !")
130+
131+
# 2. Put the file into the drive.
132+
self.drive_1.put("a.txt")
133+
134+
135+
class Work_B(LightningWork):
136+
def __init__(self):
137+
super().__init__()
138+
139+
# Note: Work B has access 2 drives.
140+
141+
# The identifier of this Drive is ``drive_1``
142+
self.drive_1 = Drive("lit://drive_1")
143+
# The identifier of this Drive is ``drive_2``
144+
self.drive_2 = Drive("lit://drive_2")
145+
146+
def run(self):
147+
# 1. Create a file.
148+
with open("b.txt", "w") as f:
149+
f.write("Hello World !")
150+
151+
# 2. Put the file into both drives.
152+
self.drive_1.put("b.txt")
153+
self.drive_2.put("b.txt")
154+
155+
156+
class Work_C(LightningWork):
157+
def __init__(self):
158+
super().__init__()
159+
self.drive_2 = Drive("lit://drive_2")
160+
161+
def run(self):
162+
# 1. Create a file.
163+
with open("c.txt", "w") as f:
164+
f.write("Hello World !")
165+
166+
# 2. Put the file into the drive.
167+
self.drive_2.put("c.txt")
168+
169+
----
170+
171+
*****************************
172+
Transfer files with Drive
173+
*****************************
174+
175+
In the example below, the Drive is created by the flow and passed to its LightningWork's.
176+
177+
The ``Work_1`` put a file **a.txt** in the **Drive("lit://this_drive_id")** and the ``Work_2`` can list and get the **a.txt** file from it.
178+
179+
.. literalinclude:: ../../../examples/app_drive/app.py
180+
181+
182+
----
183+
184+
.. raw:: html
185+
186+
<div class="display-card-container">
187+
<div class="row">
188+
189+
.. displayitem::
190+
:header: Learn about the Path Object.
191+
:description: Transfer Files From One Component to Another by Reference.
192+
:col_css: col-md-4
193+
:button_link: path.html
194+
:height: 180
195+
:tag: Intermediate
196+
197+
.. raw:: html
198+
199+
</div>
200+
</div>

docs/source-app/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ Keep Learning
219219
Access the App State <workflows/access_app_state/access_app_state>
220220
Add a web user interface (UI) <workflows/add_web_ui/index>
221221
Add a web link <workflows/add_web_link>
222+
Add encrypted secrets <glossary/secrets>
222223
Arrange app tabs <workflows/arrange_tabs/index>
223224
Develop a Command Line Interface (CLI) <workflows/build_command_line_interface/index>
224225
Develop a Lightning App <workflows/build_lightning_app/index>
@@ -232,6 +233,7 @@ Keep Learning
232233
Run an App on the cloud <workflows/run_app_on_cloud/index>
233234
Run Apps on your cloud account (BYOC) <workflows/byoc/index>
234235
Run work in parallel <workflows/run_work_in_parallel>
236+
Save files <glossary/storage/drive.rst>
235237
Share an app <workflows/share_app>
236238
Share files between components <workflows/share_files_between_components>
237239

@@ -270,6 +272,7 @@ Keep Learning
270272
DAG <glossary/dag>
271273
Event Loop <glossary/event_loop>
272274
Environment Variables <glossary/environment_variables>
275+
Encrypted Secrets <glossary/secrets>
273276
Frontend <workflows/add_web_ui/glossary_front_end.rst>
274277
Apple and Android mobile devices with Lighting Apps <glossary/ios_and_android>
275278
REST API <glossary/restful_api/restful_api>

docs/source-app/workflows/build_command_line_interface/cli.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ To see a list of available commands:
6464
--help Show this message and exit.
6565
6666
Lightning App Commands
67-
add Description
67+
add Add a name.
6868
6969
To find the arguments of the commands:
7070

docs/source-app/workflows/build_command_line_interface/cli_client.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ To see a list of available commands:
8080
--help Show this message and exit.
8181
8282
Lightning App Commands
83-
run notebook Description
83+
run notebook Run a Notebook.
8484
8585
8686
To find the arguments of the commands:

docs/source-app/workflows/build_command_line_interface/commands/notebook/run.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class RunNotebookConfig(BaseModel):
1313

1414
class RunNotebook(ClientCommand):
1515

16+
DESCRIPTION = "Run a Notebook."
17+
1618
def run(self):
1719
# 1. Define your own argument parser. You can use argparse, click, etc...
1820
parser = ArgumentParser(description='Run Notebook Parser')

docs/source-app/workflows/build_command_line_interface/example_command.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def run(self):
1010
print(self.names)
1111

1212
def add_name(self, name: str):
13+
"""Add a name."""
1314
print(f"Received name: {name}")
1415
self.names.append(name)
1516

0 commit comments

Comments
 (0)