deploy-appengine icon indicating copy to clipboard operation
deploy-appengine copied to clipboard

Support env vars

Open maxwell-oroark opened this issue 4 years ago • 5 comments

TL;DR

Could we please support adding environment variables to the deploy? These could be templated into app.yaml or something. Maybe expose the api like:

steps:
- id: deploy
  uses: google-github-actions/deploy-appengine@main
  with:
    credentials: ${{ secrets.gcp_credentials }}
    env_vars:
        envVarName: ${{ secrets.envVarName }}
    

Design

Action YAML

# Paste your proposed GitHub Actions YAML here.

Resources

  • Link to documentation

Additional information

maxwell-oroark avatar Feb 07 '21 16:02 maxwell-oroark

Yes this would be super useful, especially if you need a frontend application to point to different version of the staging url.

I hope someone works on this~!

SeanningTatum avatar Mar 17 '21 16:03 SeanningTatum

This would be so useful! At the moment, forced to do a dance like this:

name: CD workflow

on:
  push:
    branches: app-engine

jobs:
  deploy_to_google_cloud:
    runs-on: ubuntu-20.04

    steps:
    - uses: actions/checkout@v2

    - id: generate_dotenv_file
      env:
        MY_DOTENV: ${{ secrets.MY_DOTENV }}
      run: echo "$MY_DOTENV" > .env-for-app-yaml

    - id: prepare-app-yaml
      uses: mshick/fast-envsubst@v1
      with:
        env-file: .env-for-app-yaml
        in-file: app.yaml.template
        out-file: app.yaml

    - id: actual-deploy-to-gae
      # ...

gmile avatar Jun 17 '21 16:06 gmile

This would be so useful! At the moment, forced to do a dance like this:

name: CD workflow

on:
  push:
    branches: app-engine

jobs:
  deploy_to_google_cloud:
    runs-on: ubuntu-20.04

    steps:
    - uses: actions/checkout@v2

    - id: generate_dotenv_file
      env:
        MY_DOTENV: ${{ secrets.MY_DOTENV }}
      run: echo "$MY_DOTENV" > .env-for-app-yaml

    - id: prepare-app-yaml
      uses: mshick/fast-envsubst@v1
      with:
        env-file: .env-for-app-yaml
        in-file: app.yaml.template
        out-file: app.yaml

    - id: actual-deploy-to-gae
      # ...

Thank you for this little bit of information. Been racking my brain trying to figure out a way around this, and this works nicely, even if it is a dance. :)

flashadvocate avatar Jun 18 '21 19:06 flashadvocate

This would be very useful, yes.

oskarhane avatar Mar 24 '22 19:03 oskarhane

My current script for handling that:

/**
 * Replace the environment variables values in app.yaml that match the $NAME
 * with the corresponding environment variable with the name NAME
 */

import * as fs from "fs";
import * as path from "path";

const APP_YAML_PATH = path.join(__dirname, "..", "app.yaml");

if (require.main === module) {
  main().catch((error) => {
    console.error(error);
    process.exit(1);
  });
}

async function main() {
  const contents = await fs.promises.readFile(APP_YAML_PATH, "utf-8");
  const missingVariables: string[] = [];
  const updated = contents.replace(/\$[A-Z0-9_]+\b/g, (match) => {
    // Remove the leading dollar sign
    const name = match.substring(1);
    const value = process.env[name];
    if (typeof value !== "string") {
      missingVariables.push(name);
      return match;
    }
    return value;
  });
  if (missingVariables.length) {
    throw new Error(
      `The variables: ${missingVariables.join(", ")} are not defined in the environment`
    );
  }
  await fs.promises.writeFile(APP_YAML_PATH, updated);
}

Where the app.yaml file looks like:

env_variables:
  # $ variables are expected to be replaced by environment variables
  FOO: $FOO

And call to the script looks like:

     - name: Prepare environment variables
        run: yarn app-engine:replace-env-vars
        env:
          FOO: value

iddan avatar May 24 '22 21:05 iddan

Is there an update on the progress on this issue? Is there anything I can do to help? I was about to implement the workaround presented here but with a standby pull request I could wait.

Jipje avatar Mar 09 '23 08:03 Jipje