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

✨ feat: Add support for environment variables in deployment action #21

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

danton267
Copy link
Member

allows users to add env variables via setup

  • env_vars: "FOO=BAR FOO_SECRET=${{ secrets.FOO_SECRET }}"

Needs to be tested

@danton267 danton267 requested a review from ndrezn June 3, 2024 12:59
@danton267 danton267 self-assigned this Jun 3, 2024
@danton267 danton267 linked an issue Jun 3, 2024 that may be closed by this pull request
@ndrezn
Copy link
Member

ndrezn commented Jun 4, 2024

I don't think I understand the proposed API; can you show a full example?

@danton267
Copy link
Member Author

danton267 commented Jun 6, 2024

in your deploy script you can add

        with:
          env_vars: "HARD_CODED_ENV_VAR=VALUE GITHUB_SECRET_ENV_VAR=${{ secrets.NAME}}"`

which will then create the corresponding key/value environmental variables (separated by space) and add them into your app's Environment Variables.

I just tested:

  • deploying hardcoded env var env_vars: "HARD_CODED_ENV_VAR=VALUE
  • deploying envvar value via github secret env_vars: "GITHUB_SECRET_ENV_VAR=${{ secrets.NAME}}"
  • deploying multiple env vars
  • changing value of the env var in the deploy script, redeploying, and seeing the DE env var change to the new value

all work 💯

One note:
in README I changed - uses: plotly/de-deploy@v2 to @main - I thought it was only a placeholder, but I now looking at it, it stands for a version release? Shall I change it back to v2. Or change it to v3 (newest)

README.md Show resolved Hide resolved
@@ -55,6 +55,7 @@ The inputs this action uses are:
| `create_redis` | `false` | None | True to create a Redis instance for the app. |
| `create_postgres` | `false` | None | True to create a Postgres instance for the app. |
| `create_persistent_filesystem` | `false` | None | True to create a persistent filesystem for the app. |
| `env_vars` | `false` | None | Environment variables to add. Separate multiple variables with a space. Example: `env_vars: "FOO=BAR FOO_SECRET=${{ secrets.FOO_SECRET }}"` |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work without quotation marks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the current design, no. Without string, it would not be possible to split them. But er cam change it

To make it more transparent/less error prone, we can do this:

name: Deploy to Dash Enterprise

on:
  push:
    branches:
      - main

jobs:
  deploy:
    name: 'Deploy to Dash Enterprise'
    runs-on: ubuntu-latest
    strategy:
      matrix:
        env_var:
          - name: "FOO"
            value: "BAR"
          - name: "FOO_SECRET"
            value: "${{ secrets.FOO_SECRET }}"

  

Or

name: Deploy to Dash Enterprise

on:
  push:
    branches:
      - main

jobs:
  deploy:
    name: 'Deploy to Dash Enterprise'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: plotly/de-deploy@add-adding-env-variables
        with:
           env_vars: FOO=BAR FOO_SECRET=${{ secrets.FOO_SECRET }}

Or

name: Deploy to Dash Enterprise

on:
  push:
    branches:
      - main

jobs:
  deploy:
    name: 'Deploy to Dash Enterprise'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: plotly/de-deploy@add-adding-env-variables
        with:
          env_vars: |
            FOO=BAR
            FOO_SECRET=${{ secrets.FOO_SECRET }}

(Note that | must be there)

What do you think?

@emilykl
Copy link

emilykl commented Jun 6, 2024

This is a great addition.

@danton267 Out of the alternative options you listed, I think I like the first one -- that would allow users to define each env var separately rather than passing them as a space-separated string, right? That feels overall easier to use and less error-prone.

@ndrezn
Copy link
Member

ndrezn commented Jun 6, 2024

Agreed with @emilykl! Love the first option.

@danton267
Copy link
Member Author

danton267 commented Jun 11, 2024

@emilykl @ndrezn I've had a look at it, and it is not possible to GitHub secrets in the strategy -> matrix -> env_var :

name: Deploy to Dash Enterprise

on:
  push:
    branches:
      - main
  pull_request:
    types: ['opened', 'edited', 'synchronize', 'closed']
  workflow_dispatch:

jobs:
  deploy:
    name: 'Deploy to Dash Enterprise'
    runs-on: ubuntu-latest
    strategy:
      matrix:
        env_var:
          - name: "FOO"
            value: "BAR"
          - name: "FOO_SECRET"
            value: "${{ secrets.BAR_SECRET }}"
    steps:
      - uses: actions/checkout@v2
      - uses: plotly/de-deploy@add-adding-env-variables
        with:
          DE_HOST: ${{ secrets.DASH_ENTERPRISE_HOST }}
          DE_USERNAME: ${{ secrets.DASH_ENTERPRISE_USERNAME }}
          DE_PASSWORD: ${{ secrets.DASH_ENTERPRISE_PASSWORD }}
          GH_ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}

The best next thing we can do, is

name: Deploy to Dash Enterprise

on:
  push:
    branches:
      - main

jobs:
  deploy:
    name: 'Deploy to Dash Enterprise'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: plotly/de-deploy@add-adding-env-variables
        with:
          DE_HOST: ${{ secrets.DASH_ENTERPRISE_HOST }}
          DE_USERNAME: ${{ secrets.DASH_ENTERPRISE_USERNAME }}
          DE_ENV_VAR: |
            FOO=BAR
            FOO_SECRET=${{ secrets.FOO_SECRET }}

Add it to with - along other user-defined vars, and one line = one env var key/value pair, starting with | to indicate multiline syntax expression.

The question is do you want

          DE_ENV_VAR: |
            - name: "FOO"
              value: "BAR"
            - name: "FOO_SECRET"
              value: "${{ secrets.FOO_SECRET }}"

or

          DE_ENV_VAR: |
            "FOO"="BAR"
           " FOO_SECRET"="${{ secrets.FOO_SECRET }}"

Is that ok? Or any thoughts about a different approach

@ndrezn
Copy link
Member

ndrezn commented Jun 27, 2024

I prefer:

          DE_ENV_VAR: |
            - name: "FOO"
              value: "BAR"
            - name: "FOO_SECRET"
              value: "${{ secrets.FOO_SECRET }}"

Would work without quotes too right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add environment variables using action inputs
3 participants