rn-environment v0.1.22
RN Environment
Description
A react native library to manage environment and configuration files for every server configuration eg. local, development, staging and production.
Features
- Setup Environments and configuration files.
- Set Current environment using command
Dependency
No Dependencies so far.
Installation
Setup
- Insert following line in the scripts section of your
package.json
file.
"rn-environment": "rn-environment"
- Insert following lines in your
.gitignore
file
# Environment files
app/src/config/environment.json
ios/GoogleService-Info.plist
android/app/google-services.json
# Secrets
.decrypted
*.dec.yaml
- Run Setup script in your project directory. See syntax below.
npm run rn-environment -- --setup
- Update configuration files.
After running above command you can see that your project directory have a environment
folder and inside the folder have some server environment folders local
, development
, staging
and production
. Inside each of these server environment folder you have some configurations files environment.json
, google-services.json
, and GoogleService-Info.plist
.
Now you have to update all these files as per the server environment values or only those files which you are going to use. For example replace BaseUrl
value in each environment.json
file to choose different server base url in local
, development
, staging
and production
. You can also add other you own values in environment.json
file. I have given some example there.
- Create GPG Key please refer gpg tutorial or run following command
gpg --full-generate-key
- Once the gpg key is created you can check the appropriate fingerprint using following command
gpg --fingerprint
- Copy the correct fingerprint and run following commands
export SOPS_GPG_EXEC="gpg"
export SOPS_PGP_FP="<fingerprint>"
export SOPS_GPG_KEYSERVER="keyserver.ubuntu.com"
Fill the secrets that you dont want to commit in
environment/secrets.dec.yaml
fileThen encryp the file using sops. The
environment/secrets.yaml
file can be commited.
sops --encrypt environment/secrets.dec.yaml > environment/secrets.yaml
Setup environment files
Once all possible fields are filled out you can run following command to set current environment. Becore you can run this command you need to have following directory structure app/src/config
so that you can place environment.json
file in there.
npm run rn-environment -- --current $ENV
with $ENV
be one of:
- local
- development
- staging
- production
If this command gives following error.
Failed to get the data key required to decrypt the SOPS file.
Group 0: FAILED
<Random digist>: FAILED
- | could not decrypt data key with PGP key:
| golang.org/x/crypto/openpgp error: Could not load secring:
| open /Users/<username>/.gnupg/secring.gpg: no such file
| or directory; GPG binary error: exit status 2
Recovery failed because no master key was able to decrypt the file. In
order for SOPS to recover the file, at least one key has to be successful,
but none were.
Run below commands and then run current command again.
reset
GPG_TTY=$(tty)
export GPG_TTY
How to run scripts
You can use the below command to run any script. Note that rn-environment
should be added in script section of your package.json
file before running any script.
npm run rn-environment -- --<script-name>
Scripts
- Setup Script :
--setup
this script is used to setup the environment files and configuration files in a react native project. - Current Script :
--current
this script is used to setup the current environment and replace all files. Available environments arelocal
,development
,staging
andproduction
. - Help Script :
--help
this script is used for displaying available scripts.
Requirements
- Initialize directries and create files
- Set PGP key and secrets files
- Set Current environment using command
- Configure more secrets without updating decrypt-env.sh
- Add example
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago