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

injecting faunadb secret as env var via .toml build command #36

Closed
hwlmatt opened this issue Jul 19, 2020 · 4 comments
Closed

injecting faunadb secret as env var via .toml build command #36

hwlmatt opened this issue Jul 19, 2020 · 4 comments

Comments

@hwlmatt
Copy link

hwlmatt commented Jul 19, 2020

This is just a quick change to keep faunadb secret out of any files in repository; easing Netlify's github-to-netlify continuous integration.

(can do a pull request if you like as well)

Steps are below, but for reference: Netlify docs on injecting environment variables

Step 1/4 - netlify.toml

in netlify.toml
change
[build] command = "npm run build

to

[build] command = "sed -i s/FAUNADB_SERVER_SECRET/$FAUNADB_SERVER_SECRET/g netlify.toml && npm run build"

then also in netlify.toml change
[template.environment] FAUNADB_SERVER_SECRET = "your FaunaDB server secret"
to
[template.environment] FAUNADB_SERVER_SECRET = ""

Step 2/4 - .env

in local environment add a .env with
FAUNADB_SERVER_SECRET=youractualkeyfromfauna

(i suppose this could be part of template as a file like template.env.txt that has FAUNADB_SERVER_SECRET=yourkeygoeshere and instructions to rename it, etc.)

Step 3/4 - .gitignore

in .gitignore add .env to the # local env files block

Step 4/4 - Netlify UI

in Netlify UI go to Settings>Build and Deploy>Environment
and a variable with key FAUNADB_SERVER_SECRET and value of your key from Faunadb.

After that

All appears to be working as intended for both local dev, npm start, and for the github linked deploy.
Cheers, hope it's useful.

@chiubaca
Copy link
Owner

Thanks for taking the time to write this up. I'll have a go at setting this up later today 👍

@chiubaca
Copy link
Owner

I don't think if this is necessary to be honest. If you deployed via the "Deploy to Netlify" button, this is all managed for you. Nice trick though, I'll take this with me for my other Netlify projects.

@hwlmatt
Copy link
Author

hwlmatt commented Jul 20, 2020

Yeah I suppose the only real benefits in this scenario are for
a) someone that cloned the template into a public repo but wants to have a local dev version updating a branch that Netlify is using for CI, AND doesn't want that .toml file holding the key (that's what lead me to doing it this way)
b) someone that wants ability for separate dbs for local and live, but the same .toml file ? (which is probably far afield for the template's use case anyhow)

Cheers

@chiubaca
Copy link
Owner

chiubaca commented Jul 21, 2020

I did consider these scenarios. But I figured the more savvy users would probably figure out how to make this more "production" ready and fork off this if they really wanted to. As this repo is tightly couple to a blog tutorial i think it being a bit more opinionated will benefit beginners more. Thanks for your contribution nonetheless. As it's a pretty good tip I've pinned the issue so hopefully others will find it useful too.

@chiubaca chiubaca pinned this issue Jul 21, 2020
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

No branches or pull requests

2 participants