Support env vars
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
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~!
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
# ...
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. :)
This would be very useful, yes.
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
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.