How do I add local .env files to PaaS for faster deployment? - heroku

There is something I have never figured how to do with any PaaS provider.
How can I automatically deploy locally stored environment variables to PaaS when deploying the application? I know I can go to Heroku, AWS or Bluemix console and manually add my .envfile content as keys, but what I would really want to do is >
Pseudo code !
provider CLI deploy --ENV=.env.dev
Where --ENV is flag to use env. file stored in project root.
This would take my API keys from .env file and populate the provider environment variables. Preferably, the file would be usable across providers. Is this possible?

If you're using IBM BlueMix (or another Cloud Foundry), you can just list them in the application's manifest.yml file and cf push it with the rest of the application.

Related

Is it possible for .gcloudignore in Google Cloud to skip updating a file?

I have just started developing a Golang app, and have deployed it on Google App Engine. But, when I try to connect my local server to CloudSQL instance through proxy, I am able to connect only through TCP.
However, when connecting with the same CloudSQL instance in AppEngine, I am able to connect only through UNIX.
To cope with this, I have made changes in my local environment handler file, so that it can adapt to local and GCloud config, but I'm not sure how I can skip the update on just this file for GCloud? Again, I don't want AppEngine to delete this file, I just want the CLI to avoid uploading the new version of the handler file.
I use this command for deploying: gcloud app deploy
Currently, I deploy directly to AppEngine, instead of pushing it through VCS. Also, if there is an option to detect if the app is running on AppEngine, then it'd be really great.
TIA
Got it, in case anyone gets stuck in such situation, we can make use of environment variables set in GCloud AppEngine. Although there is documentation stating the environment variables, I would still give importance to checking the environment variables in Cloud Console.
Documentation link for Go 1.12+ Runtime env:
https://cloud.google.com/appengine/docs/standard/go/runtime

What is the correct method to deploy a Laravel/Vue application using Forge with MIX local/production environment variables

I understand the process of local > staging > production deployment, although I've come across one issue which I have a solution, but it doesn't feel like it's the correct method.
I have a production .env on the server and a local .env for local development which is all fine for storing my environment variables. Although, I am using Stripe API and have testing API keys locally and live API keys for production.
My Stripe public key gets pulled into public.app.js the Vue/Inertia compilation using the MIX_ prefix in my .env. I first push this to GitHub and then Deploy this to Laravel Forge where in my deploy script it runs yarn prod, pulling in the live Stripe public API key once compiled by the server.
Basically, what I am asking is: Is there a standard deployment process where you compile production ready files locally pulling the correct API keys and push to GitHub, or is there a better way which removes the need of compiling assets on the server?

How can i view environment variables of pivotal cloud foundry app while running the app on localhost

I used to view all the environment variables(defined in application.properties) of traditional springboot app by going to http://localhost:8080/env. Now, i am running the app on pivotal cloud foundry environment and trying to hit the : http://localhost:8080/env but is not working for me for pivotal cloud foundry set up.
Note: i know how to view the environment variables from CF CLI or APP Manager. But i dont want to do it that way. I am trying to fetch them through localhost:8080 link only.
One solution is to use the config server for this which basically gets the application.properties from a git repository.
Please find the references here.
https://docs.pivotal.io/spring-cloud-services/1-5/common/config-server/index.html
The second option will be to get it as a static file and like a js or CSS file the references for this option can be found here.
https://www.baeldung.com/spring-mvc-static-resources
Use Spring-Actuator to enable such functionality https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html

How can I configure application.properties using AWS CodeDeploy and/or CloudFormation?

I have a Spring Web Service deployed on Elastic Beanstalk. I'm using AWS CloudFormation for the infrastructure and I'm using AWS CodePipeline to deploy the web service automatically from merges to the master branch.
Recently I added DynamoDB integration, and I need to configure a couple things in my application.properties. I attempted to use environment variables to configure the application.properties but I hit a wall when trying to set the environment variables from CodeDeploy.
This is my application.properties
amazon.dynamodb.endpoint=${DYNAMODB_ENDPOINT:http://localhost:8000}
amazon.dynamodb.region=${AWS_REGION:default-region}
amazon.dynamodb.accesskey=${DYNAMODB_ACCESS_KEY:TestAccessKey}
amazon.dynamodb.secretkey=${DYNAMODB_SECRET_KEY:TestSecretKey}
spring.data.dynamodb.entity2ddl.auto = create-drop
spring.data.dynamodb.entity2ddl.gsiProjectionType = ALL
spring.data.dynamodb.entity2ddl.readCapacity = 10
spring.data.dynamodb.entity2ddl.writeCapacity = 1
The defaults are for when I'm running a local DynamoDB instance and they work fine. However, I can't figure out how to get CodeDeploy to set environment variables for me, I also considered getting CloudFormation to set the environment variables, but couldn't find how to do that either. I tried manually setting the environment variables in the EC2 instance but that didn't work and isn't the solution I'm looking for as I'm using EB and want this project to use fully automated deployments. Please let me know if this is possible, what the industry standard is for configuring web services, and if I'm misunderstanding either CodeDeploy or CloudFormation.
In general, it is a bad practice to include access and secret keys in any sort of files or in your deployment automation.
Your instance that your application is deployed to should have an instance profile (i.e. IAM Role) attached to it which should have the appropriate DynamoDB permissions you need.
If you have that instance profile attached, the SDK should automatically be able to detect the credentials, region and endpoint is needs to communicate with.
You may need to update the way you are creating your DynamoDB client to just use the defaults.
To setup your development machine with these properties in a way that the AWS SDK can retrieve without explicitly putting them in properties files, you can run the aws configure command of the AWS CLI which should setup your ~/.aws/ folder with information about your region and credentials to use on your dev machine.

How can I change the database name according to the database credentials provided by heroku during production?

Heroku provides its own database name and other credentials, but my local database name is different.How can I change the database name according to the database credentials provided by heroku during production?
Use a package like dotenv. dotenv and variants of it likely exist for whatever language you're using.
Basically, you want to use environment variables instead of hard coding values into your code. So, instead of writing something like this:
my_database_connect('my_username', 'abc123')
You'd write:
my_database_connect(process.env.DB_USERNAME, process.env.DB_PASSWORD)
Heroku will already have these environment variables set on the "config" tab of your app. Then for local development, you'll create a file called .env and have this text in it:
DB_USERNAME=my_username
DB_PASSWORD=abc123
Don't commit .env to your git repository – it should only live on your machine where you develop. Now your code will run locally as well as on Heroku, and connect to the proper database depending on the environment it's running in.
Here's an article that explains this more thoroughly for node.js, although this is basically the best practice for general development: https://medium.com/#rafaelvidaurre/managing-environment-variables-in-node-js-2cb45a55195f
First I created an application name on Heroku. Then I deployed my app to heroku by connecting to github.
Heroku provides the database credentials after we deploy our applications. Then I redeployed the app through github by changing the configuration in application.properties file as follows:
#localhost configuration
SPRING_DATASOURCE_DRIVER_CLASS_NAME=org.postgresql.Driver
SPRING_DATASOURCE_URL=jdbc:postgresql://localhost/transactions?useSSL=false
SPRING_DATASOURCE_USER=postgres
SPRING_DATASOURCE_PASSWORD=some_pass
#server database configuration
SPRING_DATASOURCE_DRIVER_CLASS_NAME=org.postgresql.Driver
SPRING_DATASOURCE_URL=jdbc:postgresql://ec2-23-23-247-222.compute-1.amazonaws.com/d6kk9c4s7onnu?useSSL=false
SPRING_DATASOURCE_USER=rimjvlxrdswwou
SPRING_DATASOURCE_PASSWORD=dd903753bc0adffb96ce541b1d55fb043472e32e28031ddc334175066aa42f69
Then you have to edit the config vars according to your application.properties files as shown in the figure below
config_var.png

Resources