I'm wondering how can I set up the MS AppCenter to use the specific .env file, let' say the .env.staging for example:
and the CI/CD of the AppCenter will do the build for me with that .env file
If you have separate branches for staging, release etc. this can be made to work.
For each of the branches have a common environment variable to identify the specific release. Ex: TARGET = staging
(Or you can even use Appcente's pre-defined variable APPCENTER_BRANCH to grab the branch name. Depends on the strategy you follow.)
Next create a either a appcenter-pre-build.sh or appcenter-post-build.sh and update it as follows. This will create a copy of your TARGET env file as .env
#!/usr/bin/env bash
# Appcenter pre-build hook to setup amplify.
set -e
IFS='|'
echo "Making a copy of .env file"
cp .env.${TARGET} .env
Related
I started using MS appcenter in my bare react-native app, and during the set up they ask me to add two new files to the project:
For IOS: AppCenter-Config.plist with
<dict>
<key>AppSecret</key>
<string><MY_SECRET_KEY></string>
</dict>
And for Android I need to add a JSON file with the key:
{
"app_secret": "<MY_SECRET_KEY>"
}
I'm already using a package in my app to handle .env files: https://github.com/luggit/react-native-config
Is there any way to use this package or another one, in order to get the APP_SECRET for the appcenter config files from a ENV variable?
I just don't want to keep these keys under version control.
Appcenter allows us to use build scripts, you can see more details here:
https://learn.microsoft.com/en-us/appcenter/build/custom/scripts
The workaround I found to fix this was using a post-clone script. You need to create a bash script on the root folder of your app that will write the .env file using the environment variables.
First, create a new file called appcenter-post-clone.sh.
And after you can write your .env file with something like this:
#!/usr/bin/env bash
echo "Creating .env file"
cat > ./.env <<EOL
API_URL=${API_URL}
API_KEY=${API_KEY}
EOL
Found this - The app secret (name is a bit confusing) is only for checking in-app updates - its seems you cannot trigger release with it.
So I think it is unnecessary to move the secret to the .env file.
I'm building an app using Vue CLI 3.
I've included .env in my project and everything works fine.
But when i'm building the app for production via npm run build there is no .env file in my dist folder, so i can't change my environmental variables in production server.
Any solution or it's just fine?
This is supposed to happen. The env variables are embedded in your build.
You can make seperate .env files for production. These variables will be used during the production build.
Create a new .env file named: .env.production
Source: https://cli.vuejs.org/guide/mode-and-env.html#modes
It is normal because application needed to be recompiled when .env file changed.
For convenience you can use .env.prod or .env.dev for your CI/CD pipeline.
I have config server which is a containerized. now my task to create a API in express. the problem i am facing is how to read the common properties defined in the config server in my express api.
Create a .env File to store your environment variables. Example: .env.development or .env.test or .env.production files that you can put into a config folder.
Download the node module "node-foreman" https://github.com/strongloop/node-foreman
Now run your web server using foreman and specify which environment you want with the following command line command.
./node_modules/foreman/nf.js --env ./config/.env.development start web=1
That will load the correct environment that you want.
Then to access your environment variables in the actual code, you use "process.env".
For example if you have a key-value pair in your .env file like version=5.5 then to access it in the code you do process.env.version.
I have build and distributed my iOS app using fastlane, for that I have created script in fast file, so now I want pass the env variable in this script for creating the template, this same template I can use my other iOS apps as well, so how can I pass env variables in my fastlane script?
Fastfile and Co are just Ruby code, so you can use ENV['XYZ'] to access any environment variables.
To set environment variables, there are multiple options in fastlane. Some are described at https://docs.fastlane.tools/advanced/other/#environment-variables
Fastlane also supports dotenv to set environment variables via files: https://docs.fastlane.tools/best-practices/keys/#dotenv
Using the Serverless framework, I want to be able to change the AWS region from an envrionment variable.
provider:
name: aws
region: ${env:AWS_REGION}
Then, AWS_REGION can be set to eu-west-2.
However, I want to have that set in a .env file:
AWS_REGION=eu-west-2
And then have that .env read by Serverless.
There are many topics about setting variables in the serverless.yml file, and exporting them from that file, but I want to put them into the file.
Out of the box serverless doesn't parse .env, that part belongs to you.
I see three options for you:
Use the serverless-dotenv-plugin.
Write a script that exports .env vars to your local environment before you run serverless.
Run serverless in docker-compose which is .env aware -- I use this in combination with Makefile, even in a CI/CD context.
Serverless now supports .env files without the need for a plugin
Add useDotenv: true to your serverless.yml file. The variable should be at the root level, same as service: ...
Add a .env file at the root of your project and serverless will load the variables.
Example:
// .env
MY_TABLE=A_TABLE_NAME
use this plugin to write .env with serverless.yaml serverless-export-env. so you just need to overwrite your region inside serverless yaml, and your env will be generated based on whay you've written in serverless.yaml.