-
Notifications
You must be signed in to change notification settings - Fork 109
docs: Improve Actors environment variables docs #1668
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
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Patrik Braborec <patrikbraborec@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Misleading Variable Assignment in Python Example
In the Python example for accessing environment variables, the variable userId
is misleadingly assigned the value of os.environ['api_token']
. This contradicts the variable's name and the surrounding comments, causing confusion.
sources/platform/actors/development/programming_interface/environment_variables.md#L157-L161
apify-docs/sources/platform/actors/development/programming_interface/environment_variables.md
Lines 157 to 161 in ff39d10
# get api_token | |
userId = os.environ['api_token'] | |
# print api_token to console | |
print(userId) |
Comment bugbot run
to trigger another review on this PR
Was this report helpful? Give feedback by reacting with 👍 or 👎
Preview for this PR was built for commit |
Signed-off-by: Patrik Braborec <patrikbraborec@gmail.com>
Signed-off-by: Patrik Braborec <patrikbraborec@gmail.com>
Preview for this PR was built for commit |
Preview for this PR was built for commit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did few rewrites for clarity & conciseness
rewrote notes to be more active voice to adhere to msoft style guide and general technical writing principle
sources/platform/actors/development/programming_interface/environment_variables.md
Outdated
Show resolved
Hide resolved
sources/platform/actors/development/programming_interface/environment_variables.md
Outdated
Show resolved
Hide resolved
sources/platform/actors/development/programming_interface/environment_variables.md
Outdated
Show resolved
Hide resolved
sources/platform/actors/development/programming_interface/environment_variables.md
Outdated
Show resolved
Hide resolved
sources/platform/actors/development/programming_interface/environment_variables.md
Outdated
Show resolved
Hide resolved
sources/platform/actors/development/programming_interface/environment_variables.md
Outdated
Show resolved
Hide resolved
sources/platform/actors/development/programming_interface/environment_variables.md
Outdated
Show resolved
Hide resolved
Preview for this PR was built for commit |
sources/platform/actors/development/programming_interface/environment_variables.md
Outdated
Show resolved
Hide resolved
@@ -14,6 +14,21 @@ import TabItem from '@theme/TabItem'; | |||
|
|||
--- | |||
|
|||
## How to use environment variables in Actors | |||
|
|||
There are two ways how you can set up environment variables for Actors: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I explain below, actor.json env vars only work with Apify CLI. So I think that was partially a reason why we didn't explain it much here, it might confuse users that use git integration (which is most serious users). So I would reword this a bit to make sure it is clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added note to the Set up environment variables in actor.json
section about the Git workflows.
sources/platform/actors/development/programming_interface/environment_variables.md
Outdated
Show resolved
Hide resolved
sources/platform/actors/development/programming_interface/environment_variables.md
Show resolved
Hide resolved
:::info Build-time variables | ||
|
||
Custom environment variables are set during the Actor's build process and cannot be changed for existing builds. For more information, check out the [Builds](../builds_and_runs/builds.md) page. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is confusing. Yes, it is true but Build-time variables
resembles the Apply environment variables also to the build process
option which we have next to env vars which is about injecting env vars to be available to the Dockerfile, not about needing to rebuild.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I see you just copied existing text so then that's more on @TC-MO. Even if I check the current page, it is wrong, because the banner is unrelated to section below Build-time environment variables
so I would just find a better name for :::info Build-time variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would something like:
Variables set during the build
Build-specific environment variables
work better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the info note Variables set during the build
is ok. I can think also of Variables bound to a build
, Variables set to a specific build
etc.
For the section Build-time environment variables
sounds better than Build-specific environment variables
(that suggests it is bound to a single build).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the info note to Variables set during the build
sources/platform/actors/development/programming_interface/environment_variables.md
Outdated
Show resolved
Hide resolved
sources/platform/actors/development/programming_interface/environment_variables.md
Outdated
Show resolved
Hide resolved
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
## Use the `Configuration` class | ||
## Access system environment variables |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why we recommend using Configuration @TC-MO ? For Apify injected env vars, it is better to use Actor.getEnv() which is fully typed with autocompletion. Configuration class is more general config file that you can use also for non-env settings (Cralwee also uses it for some scraping settings). So I would replace it completely, Configuration is only for very advanced users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked history and the Configuration
class was there since the beginning. I made it more prominent during one of the rewrites that aimed for one voice & tone throughout whole documentation. We can remove it completely if you think that this is an anti-pattern that we would not like to promote, or create a disclaimer/note that would warn users about dangers of using this approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see now. What confused me that @patrikbraborec added it under Access system environment variables
where we should use Actor.getEnv()
. But in the original text, Configuration is mentioned on its own which is ok (although the use-case is quite niche)
The only reason to use Configuration instead of Actor.getEnv() is that it can set env vars (3rd way instead of Console or actor.json but it is the only programmatic way).
I would revert this change and update it in another PR. In there, I would mention Actor.getEnv in https://docs.apify.com/platform/actors/development/programming-interface/environment-variables#system-environment-variables and then just in Configuration note that it for reading env vars, users should prefer typed Actor.getEnv
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about removing the section completely, if the use case is quite niche?
…ronment_variables.md Co-authored-by: Michał Olender <92638966+TC-MO@users.noreply.github.com>
Preview for this PR was built for commit |
…ronment_variables.md Co-authored-by: Michał Olender <92638966+TC-MO@users.noreply.github.com>
…ronment_variables.md Co-authored-by: Michał Olender <92638966+TC-MO@users.noreply.github.com>
…ronment_variables.md Co-authored-by: Michał Olender <92638966+TC-MO@users.noreply.github.com>
Preview for this PR was built for commit |
Preview for this PR was built for commit |
…ronment_variables.md Co-authored-by: Michał Olender <92638966+TC-MO@users.noreply.github.com>
Preview for this PR was built for commit |
Signed-off-by: Patrik Braborec <patrikbraborec@gmail.com>
Preview for this PR was built for commit |
Signed-off-by: Patrik Braborec <patrikbraborec@gmail.com>
…ronment_variables.md Co-authored-by: Michał Olender <92638966+TC-MO@users.noreply.github.com>
Preview for this PR was built for commit |
…ronment_variables.md Co-authored-by: Michał Olender <92638966+TC-MO@users.noreply.github.com>
Preview for this PR was built for commit |
Signed-off-by: Patrik Braborec <patrikbraborec@gmail.com>
Preview for this PR was built for commit |
Preview for this PR was built for commit |
Configuration
class and how I described it, but I tried it locally and in Apify console, and it worked that way, but I just maybe do not understand it yet.