-
Notifications
You must be signed in to change notification settings - Fork 87
[Docs]: Add comprehensive environment variables documentation #602
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
Open
Copilot
wants to merge
2
commits into
main
Choose a base branch
from
copilot/fix-df0d8f4e-9cfa-4aaa-bd62-2fa28a0a4469
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -308,6 +308,71 @@ Just like with the `docker compose` CLI, you can use the global `--file | -f` co | |
|
|
||
| In addition to the project compose files, an optional Preevy-specific Compose file can be used. Preevy attempts to load files named `compose.preevy.yaml`, `compose.preevy.yml`, `docker-compose.preevy.yaml` or `docker-compose.preevy.yml`. If one of these exists, it is loaded BEFORE the project composes file(s). The name of the Preevy-specific compose file can be overridden by specifying the argument `--system-compose-file`. | ||
|
|
||
| ### Environment Variables | ||
|
|
||
| Preevy supports all Docker Compose environment variable features. You can pass environment variables to your preview environments in multiple ways: | ||
|
|
||
| #### Setting environment variables in Compose files | ||
|
|
||
| You can set environment variables directly in your `docker-compose.yml` or `compose.yml` files using standard Docker Compose syntax: | ||
|
|
||
| ```yaml | ||
| services: | ||
| web: | ||
| environment: | ||
| # Assign a fixed value to MY_ENV_VAR | ||
| - MY_ENV_VAR=production | ||
|
|
||
| # Load the value of EXTERNAL_ENV_VAR from the host environment | ||
| # and assign it to MY_ENV_VAR in the container | ||
| - MY_ENV_VAR=${EXTERNAL_ENV_VAR} | ||
|
|
||
| # Pass MY_ENV_VAR directly from the host environment to the container | ||
| # (equivalent to MY_ENV_VAR=${MY_ENV_VAR} if MY_ENV_VAR exists in the host environment) | ||
| - MY_ENV_VAR | ||
|
|
||
| # Set MY_ENV_VAR to the value from the host if it exists, | ||
| # otherwise use "production" as a default value in the container | ||
| - MY_ENV_VAR=${MY_ENV_VAR:-production} | ||
| ``` | ||
|
|
||
| #### Using .env files | ||
|
|
||
| Docker Compose supports loading environment variables from `.env` files. Preevy supports this feature: | ||
|
|
||
| ```yaml | ||
| services: | ||
| web: | ||
| env_file: | ||
| - .env # Base environment variables | ||
| - .env.override # Override specific values | ||
| - ${ENV_NAME}.env # Environment-specific variables (e.g., dev.env, prod.env) | ||
| ``` | ||
|
|
||
| #### Passing environment variables from the host | ||
|
|
||
| When running `preevy up`, environment variables from your local machine (or CI environment) are automatically available for Docker Compose interpolation. This means you can: | ||
|
|
||
| 1. Set environment variables in your terminal: | ||
| ```bash | ||
| export DATABASE_URL=postgres://user:pass@host:5432/db | ||
| export API_KEY=your-secret-key | ||
| preevy up | ||
| ``` | ||
|
|
||
| 2. Set environment variables in your CI environment and they will be automatically passed through to your preview environment. | ||
|
|
||
| 3. Use environment variables in GitHub Actions: | ||
| ```yaml | ||
| - name: Deploy preview environment | ||
| uses: livecycle/[email protected] | ||
| env: | ||
| DATABASE_URL: ${{ secrets.DATABASE_URL }} | ||
| API_KEY: ${{ secrets.API_KEY }} | ||
| ``` | ||
|
|
||
| For more details, see the [Docker Compose environment variables documentation](https://docs.docker.com/compose/how-tos/environment-variables/set-environment-variables/). | ||
|
|
||
| ### `x-preevy`: Preevy-specific configuration in the Compose file(s) | ||
|
|
||
| A `x-preevy` top-level element can be added to the Compose file(s). | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,6 +122,33 @@ LIGHTSAIL DRIVER FLAGS | |
| DESCRIPTION | ||
| Bring up a preview environment | ||
|
|
||
| ENVIRONMENT VARIABLES | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is generated, so no need to add it here |
||
| Preevy supports all Docker Compose environment variable features: | ||
|
|
||
| • Environment variables set in your shell are automatically available to Docker Compose | ||
| • Use .env files to define environment variables | ||
| • Set environment variables directly in your compose files | ||
|
|
||
| Examples: | ||
|
|
||
| 1. Pass environment variables from your shell: | ||
| $ export DATABASE_URL=postgres://localhost/mydb | ||
| $ preevy up | ||
|
|
||
| 2. Use environment variable substitution in compose files: | ||
| services: | ||
| web: | ||
| environment: | ||
| - DATABASE_URL=${DATABASE_URL} | ||
| - NODE_ENV=${NODE_ENV:-production} | ||
|
|
||
| 3. Use .env files: | ||
| services: | ||
| web: | ||
| env_file: | ||
| - .env | ||
| - .env.production | ||
|
|
||
| FLAG DESCRIPTIONS | ||
| --id=<value> Environment id | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Try to minimize it and a link to recpies example you've created (and docker compose relevant documentation)