替换Docker映像中的数据库连接字符串 [英] Replacing database connection strings in the Docker image

查看:130
本文介绍了替换Docker映像中的数据库连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序的发布过程中遇到困难.该应用程序是在.NET Core中开发的,并使用"appsettings.json"来保存到数据库的连接字符串.该应用程序应部署到Azure中的Kubernetes群集中.尽管问题在于必须将其部署到多个环境(DEV/QA/UAT)中,并且每个环境都使用自己的数据库,但我们在Azure DevOps中拥有一个生成和发布过程,因此该过程是自动化的.当我们构建Docker映像时,包含连接字符串的'appsettings.json'被烘焙到映像中.下一步将映像推送到容器存储库,然后释放过程将其用于将映像部署到群集(步骤很经典).

I'm having hard times with the application's release process. The app is being developed in .NET Core and uses 'appsettings.json' that holds connection string to a database. The app should be deployed to Kubernetes cluster in Azure. We have a build and release processes in Azure DevOps so the process is automated, although the problem belongs to a necessity to deploy the same to multiple environments (DEV/QA/UAT) and every env is using its own database. When we build Docker image, the 'appsettings.json' that holds a connection string is being baked-in to the image. The next step pushes the image to a container repository which Release process then uses to deploy the image to a cluster (the steps are classics).

在构建步骤中将连接参数替换或放入变量中没什么大不了的.但是,这是一个发行过程,控制着到多个环境的部署.我看不到如何在Release管道中将连接字符串替换为数据库...或更确切地说,如何在为每个应用程序正确设置数据库连接字符串的情况下,将其部署到三个不同的环境中.

Replacing or putting the connection parameters into the variables on the build step is not a big deal. However, this is a Release process that controls the deployment to multiple environments. I don't see how I can substitute the connection string to a database in the Release pipeline... or better to say, how to deploy to three different environments with database connection string properly set for each of them.

请提出如何实现的建议.我想出的唯一选择是为每个环境创建三个独立的构建管道,这看起来并不漂亮. Release的整个想法是,您可以在将更改推广到下一个环境之前管理批准过程.

Please suggest how it can be achieved. The only option I came up with is having three separate build pipelines for every env which doesn't look pretty. The entire idea behind Release is that you can manage the approval process before rolling out the changes to the next environment.

推荐答案

决定继续使用Kubernetes机密.在这里找到有关此问题的好文章:

Decided to proceed with Kubernetes secrets. Found a good article around this issue here: https://strive2code.net/post/2018/12/07/devops-friday-build-a-deployment-pipeline-using-k8s-secrets

这篇关于替换Docker映像中的数据库连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆