How to set up environment variables for development environment - configuration

This Twelve-Factor App manifesto insists on putting configuration variables in the environment rather than in the code. I'm using Supervisord to daemonize server processes, which allows for adding environment variables in the configuration, but when I work on a particular server's code, I'll stop the Supervisord process and run the same command from the console in order to see the output conveniently.
If I move the configuration to environment variables from the code, how should I set up the development environment variables? Should I just have a Bash script to run before running the server process, or is there a better way?

Related

Elastic Beanstalk - Environment properties not saving

I have a load balanced EB environment, running a PHP application on an Apache server.
We have successfully deployed the identical software to a test environment in this AWS account, as a pre-production test. This went as expected, and updated the sortware with each CLI deployment.
I cloned this environment in order to deploy the production instance. Generally, deploying the application via EB CLI results in a healthy instance. I say generally because occasionally this shows as degraded - to fix this, I select the latest application version and deploy it to the instance via the admin interface. This feels like a workaround because the console already shows the correct version as the one deployed.
The problem I am having now is in changing the environment variables, to point to the production database. When I change this via the configuration>software section, no changes are stored. When I hit 'apply' the environment starts to transition. When this is complete, the instance health has degraded and the changes made to the configuration are not persisted.
I don't really see a pattern here, and it's behaving in a way that differs from the way the test instance did - I had no problems there.
Any suggestions on how to get past this?

STRAPI MODEL IN PRODUCTION MODE (PM2 & BUDDY)

My previous models are working right but when I added the interview model it works in development mode but not in production. I'm using pm2 and buddy (CI).
What type of commands I need to pass to pm2?
I'm not sure about what is your development / production workflow with Strapi but.
When you are in you local machine with development environment, you have to start your application with strapi start. With this command, some feature to restart your app automatically when you create/update/delete content type are available. If you don't use this command you can have some trouble during your development process.
When you are done with your development. You have to push all you code in your production server (use the way you want to do that). And then you can start Strapi using pm2 NODE_ENV=production pm2 start npm --name api -- start
Note in production you will not have access to the Content Type Builder and Settings Manager (you haven't to update config in production).

How to run a .NET Core project without doing any configuration in a local development environment and in a CI/CD pipeline?

First let me give some background
We have our own VPS, so we do not wish to use Azure to host our web applications.
We have already successfully created a CI/CD pipeline to our VPS by installing an agent on it for a .NET Core project.
We use Azure DevOps (formerly known as VSTS) to host our code in GIT and handle our backlogs and CI/CD pipelines.
We have several .NET Framework projects where we use XTD transforms to transform our web.config files on delivery/deployment to have the correct connection strings and other configuration properties.
This makes it possible to pull the master branch from our remote repo and have it working in seconds on a previously unused (for this application) development environment without the need for any configuration.
Now to get to my question
The master branch of the .NET Core project for which we already have the CI/CD pipeline in place holds the configuration in the json files for the staging environment it is continuously delivered to. When a developer pull the master branch, he/she first needs to configure these to suite the local debug environment.
This is an undesirable situation for us.
How can we make it so that if we use .NET Core we can use a mechanism that will allow us to have the project work on a local debug environment without any configuration and in the CI/CD pipeline?
What have we already tried?
we have found that we can have multiple versions of the appsettings.json file for the different environments like appsettings.debug.json and than in the static method CreateWebhost of the Program class we can call on or the other. But how we can automate this is something that we haven't been able to figure out or find documentation about.
Okay, so here are some options you can take advantage of TODAY. (there are im sure more options/approaches)
Option A
Configure the master branch to have appsetting.development.json with connection string to DEV database( or lowest environment)
remove any connection string from appsettings.json
Merge master accordingly.
Create environment variables on each of the backend servers for the connection string; ex, system environment variable named ConnectionStrings:cartDB with connection string to the database for the environment for which the backend server used.
The result of this will be that when running using DEVELOPMENT as the environment variable, then it will be able to connect to database everyone can access.
However, since all OTHER web servers have environment variables with connection string, they will take highest level of precedence, and will therefore be the values set when calling something such as
string connectionString = Configuration.GetConnectionString("cartDB");
This will satisfy the requirements you mentioned above.
Option B:
Configure the master branch to have appsetting.development.json with connection string to DEV database( or lowest environment)
remove any connection string from appsettings.json
Place appsetting.staging.json, appsettings.prod.json in source control, and set environment name variable in web servers. :/ not the best of options/advised against.
(its worth mentioning since I have seen this happen, we all have)
Option C
Add appsetting.staging.json, appsettings.prod.json to source control and use a token in place of the connection string value. Then, leverage some type of Tokenization Task to replace those tokens with the appropriate values.

Getting error trying to run nsolid standalone

I am attempting to profile an application standalone (i.e. on the same machine as a developer). I'm not sure I'm configuring it right, but I do:
NSOLID_PROXY=0.0.0.0:0 npm run myserverlauncher
The application fires up and uses a random port for NSolid
Now, I want to fire up the nsolid console, and it starts but cannot find my machine. I tried:
npm start
NSOLID_PROXY=0.0.0.0:0 npm start
NSOLID_PROXY=0.0.0.0:47020 npm start (using the port given during launch)
None of these can discover my server.
Any clues on how to troubleshoot the standalone configuration?
To avoid overload on your application when profiling you don't connect directly to N|Solid. We designed a Hub for use to gathering the information for profiling without any overload.
You'll need a etcd server running and the N|Solid Hub. Afterwards you point your application to connect to the Hub using NSOLID_HUB env var (note that NSOLID_PROXY is wrong).
We have a very complete guide to run N|Solid in a standalone and development environment, take a look and also check out the scripts used there to make it all work out of the box.
Feel free to reach us anytime!

Executing junit on remote server in jenkins

can anyone help with this.
I am using Jenkins to deploy a build to a remote server, so far so good. However, I want to run JUnit tests on that remote server, but I cannot find how to do this within Jenkins. I have tried it within the ANT but it gives me an error regarding the junit.jar.
I believe that the tests are executing locally rather than remotely.
Any help would be appreciated; Jenkins is a very new experience to me.
Initially you have to be aware of few things. Jenkins is a CI tool which built with plenty of features to make things automated. If you need to run tests on remote server, then follow the sequences to create such a setup :
Install jenkins on a Machine and properly configure it as CI-Server.
Deploy your remote server with necessary tools and configure well.
On Jenkins server, install SSH plugin to run jobs on remote machine via ssh.
Add the remote server as slave node under Jenkins -> Manage Jenkins -> Manage Nodes -> Add Node menu on Jenkins server.
Configure the node as per your requirement.
Create a new job which could run the junit tests with pre/post build actions in jenkins.
Finally schedule the build for slave node and kick it off.
For step by step instructions, refer this answer.