How to pass environment variables during program runtime for docker container in azure - azure

I have my connection string inside a .env file, which I don't commit into the git repo. And I have my app up and running on Azure.
So the way my app works is, when I push my code to Github, Azure Container Registry will build the image on the committed code, and then Azure App Service is going to pull and build a container for my app.
So my question is, how do I pass that connection string to the Docker container? What I could do is put the .env file into the git repo, but I don't think I should put it up there.

Thank you Rimaz Mohommed. Posting comment section discussion into Answer section to help other community users.
Couple of approaches
Add the Variables directly as part of the app settings and it should be available as part of your app environment.
Reference : https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-rm-web-app-deployment?view=azure-devops
You can pass/set your environment variables by Configure environment variables.
You can run this Azure CLI command as part of your devops pipeline (https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-cli?view=azure-devops)

Related

Azure pipelines secret variable and react app deployment

I have been trying for a few days on how to use an environment secret variable set in azure pipelines.
Here is source code where I get the environment variable value.
Here is the .env file I used with the value
Below is the TEST word successfully shown when I try to run in vscode via yarn start.
I setup environment variable and set variable as secret in the azure pipeline.
I followed some microsoft tutorial as well as some other answers here in stackoverflow.
I setup powershell task in azure pipelines to get secret variable.
All task run successfully. All task for IIS Deployment also run successfully.
But when I open the web app in the II Server, the result is TEST is not displayed at all.
Heading
If I use the pipeline variable as plaintext instead of secret, TEST is successfully displayed.
Did someone encountered this before and solved it?

Azure deployment The value of deployment parameter 'dockerRegistryUrl' is null

Trying to deploy a web app using docker-compose and azure container registry and some public images but when I get to the review it gives me this error.
The value of deployment parameter 'dockerRegistryUrl' is null. Please specify the value or use the parameter reference. See https://aka.ms/resource-manager-parameter-files for details.
here is how I'm linking the azure container registry
image: csym023.azurecr.io/csym023_api:latest
...
image: csym023.azurecr.io/csym023_app:latest
think I may have set up the docker-compose file incorrectly for the azure container registry but I am not sure. the documentation link isn't very clear to me it doesn't say anything about the 'dockerRegistryUrl' or where to upload the resource manager parameter file.
here is the Docker compose file
For your issue, actually, the "dockerRegistryUrl" is not a property in the docker-compose file, it's an environment variable of the Azure Web App for Container if you use the template.
So if you use the ACR for you images, you need to set the environment variables DOCKER-REGISTRY-SERVER-UTL, DOCKER-REGISTRY-SERVER-PASSWORD and DOCKER-REGISTRY-SERVER-USERNAME in the app settings. Also, WEBSITES_ENABLE_APP_SERVICE_STORAGE is necessary.
In addition, you need to meet the Docker compose options which supported in Azure. And you can the details here.

Azure Web App for Containers not setting Environment Variables

I have a docker image being deployed from Azure Container Registry. Everything works fine except that I expect to be able to
see environment variables being passed to my running docker image from the Application Settings configured in the portal. It is a Node app accessing environment variables with process.env.VariableName.
As an example its says here
https://blogs.msdn.microsoft.com/waws/2017/09/08/things-you-should-know-web-apps-and-linux/#SetEnvVar …
"App Settings are injected into your app as environment variables at runtime"
I have tried the following.
Setting Applications Settings in the Azure Portal. These are supposed to get passed to the running Docker image as per the documentation but process.env.VariableName in my Node application is not set.
I have tried using a Docker compose file that sets the environment variables but again process.env.VariableName is empty.
I have even updated the VSTS build arguments passing the Variable to my Docker file on build which in turn sets the environment variable. Again no variable passed to the running Docker image.
My conclusion is that custom environment variables are not allowed in Azure Web App for Containers?
Am I doing something wrong?
As per the documentation the app settings are injected into the process as environment variables, however the environment variable name is prefixed with APPSETTING_, so in your Node application you would need to access the app setting with process.env.APPSETTING_VariableName.

Deploy to Azure from CircleCI

I'm using CircleCI for the first time and having trouble publishing to Azure.
The docs don't have an example for Azure, they have an example for AWS and a note for Azure saying "To deploy to Azure, use a similar job to the above example that uses an appropriate command."
If anybody has an example YAML file that would be great, if not a nudge in the right direction would be handy. So far I think I've worked out the following.
I need a config that will install the Azure CLI
I need to put my Azure deployment credentials in an environment variable and
I need to run a deploy command in the YAML file to zip up all the right files and deploy to my Azure app service.
I have no idea if the above is correct, or how to do it, but that's my understanding right now.
I've also posted this on the CircleCi forum.
EDIT: Just to add a little more info, the AWS version of the config file used the following command:
- run:
name: Deploy to S3
command: aws s3 sync jekyll/_site/docs s3://circle-production-static-site/docs/ --delete
So I guess I'm looking for the Azure equivalent.
The easiest way is that on the azure management console you setup as deployment from source control and you can follow this two links
https://medium.com/#strid/automatic-deploy-to-azure-web-app-with-circle-ci-v2-0-1e4bda0626e5
https://www.bradleyportnoy.com/how-to-set-up-continuous-deployment-to-azure-from-circle-ci/
if you want to do the copy of the files from ci to the iis server or azure you will need ssh access the keys etc.. and In the Dependencies section of circle.yml you can have a line such as this:
deployment:
production:
branch: master
commands:
- scp -r circle-pushing/* username#my-server:/path-to-put-files-on-server/
“circle-pushing” is your repo name, which is whatever it’s called in GitHub or Bitbucket, and the rest is the hostname and filepath of the server you want to upload files to.
and probably this could help you understand it better
https://learn.microsoft.com/en-us/azure/virtual-machines/linux/copy-files-to-linux-vm-using-scp

Deploy Azure web app with private credentials via Git

I would like to deploy my Node.js app via GitHub to Azure.
I intend to make the app open source, thus no private info would be published in the repo; however, I still need to push the necessary credentials, API keys, etc. for the app to connect to other services.
How can I deploy the app without resorting to the private Git endpoint, and then awkward copy-pasting between the repos?
Typically you'll want to utilize an npm module like nconf to load environment variables from either a file or environment variables.
config.json is just a JSON document listing your key:value pairs. You'll want to add config.json to your .gitignore file to ensure you don't share your credentials publically.
Within the Azure Portal, you'll want to add your credentials as key:value pairs under Application Settings.
Note: You may be wondering what will happen if config.json is not found. nconf will simply move on to the next chained option. You could continue to chain config options together as in the following code snippet:
var nconf = require('nconf');
// Create nconf environtment
nconf
.file({ file: 'config.json' }) // Committed to repo; public settings
.file({file: 'local_config.json'}) // Not committed to repo; private or dev environment settings
.env();
Persistent data can be stored under d:\home, so I would recommend placing your private customizations there. If they need to be applied to the site in some way, you should do this by writing a deployment hook.
Set configuration as environment variables found in the "App Settings" section under Settings->Application Settings. Rationale here.
Your issue seems to be continuous deployment for Web App via Git from GitHub repo.
So I think #Dark Falcon 's answer is correct.
Azure continuous deployment support GitHub just need to do OAuth authentication in Azure Portal.
Find out the link "set up deployment from source control" at Azure WebApp Dashboard page and do it step by step, as the pictures below.
There is some blogs and vedio tutorials for details of helping you.
The blog explains how to use continuous deployment support for repo hosted on GitHub http://azure.microsoft.com/en-us/blog/using-app-service-web-apps-continuous-deployment-with-github-organizations/.
You also can follow these vedio tutorials to try to do it, as the references below.
http://azure.microsoft.com/en-us/documentation/videos/create-a-nodejs-site-deploy-from-github/
http://azure.microsoft.com/en-us/documentation/videos/deploying-to-azure-from-github/
https://channel9.msdn.com/Series/Windows-Azure-Web-Sites-Tutorials/Github-Continuous-Delivery-in-the-Preview-Portal.
Best Regards.

Resources