Pau*_*rry 6 powershell docker-compose azure-devops-pipelines
我正在编写一个测试管道并动态创建一系列容器来设置各个部分。
我需要能够将秘密变量从 Pipeline 传递到 Docker Compose 构造中,以使容器能够连接到数据库服务器。
我的管道中有许多非秘密变量,它们都已成功传递。
我已经在 powershell 测试中映射了$env:addressdatabase_password来验证我的变量是否可用。
#To Verify if mapped secret variables are coming through (reverse the string)
- powershell: |
$a = $env:addressdatabase_password
Write-Host "$a"
$b = $a.ToCharArray()
[Array]::Reverse($b)
$c = -join($b)
Write-Host "$c"
env:
addressdatabase_password: $(database-address-password) #pipeline secret
Run Code Online (Sandbox Code Playgroud)
我的任务azure-pipelines.yml看起来像这样(未显示所有参数)
- task: DockerCompose@0
displayName: 'Container Start'
inputs:
containerregistrytype: 'Azure Container Registry'
azureSubscription: '$(containerSubscription)'
azureContainerRegistry: '{"loginServer":"$(containerLoginServer)", "id" : "$(containerRegistryId)"}'
dockerComposeFile: '**/docker-compose.yml'
action: 'Run a Docker Compose command'
dockerComposeCommand: 'up -d'
arguments: mycontainer
containerName: 'cf_$(CreateDb.buildidentifier)'
detached: true
dockerComposeFileArgs: |
addressdatabase_name=$(database-address-name)
addressdatabase_user=$(database-address-user)
addressdatabase_pass=$(addressdatabase_password)
env:
addressdatabase_password: $(database-address-password) #pipeline secret
Run Code Online (Sandbox Code Playgroud)
docker-compose.yml文件的相关部分
mycontainer:
image: mycontainer-runtime:latest
ports:
- "80:80"
volumes:
- ${mount_1}:C:/mount1
- ${mount_2}:C:/mount2
environment:
ADDRESS_DATABASE_NAME: ${addressdatabase_name}
ADDRESS_DATABASE_USERNAME: ${addressdatabase_user}
ADDRESS_DATABASE_PASSWORD: ${addressdatabase_pass} #pipeline secret
Run Code Online (Sandbox Code Playgroud)
容器启动成功,但是当我检查容器内的环境变量时
ADDRESS_DATABASE_NAME=pr_address
ADDRESS_DATABASE_USER=test-addressuser
ADDRESS_DATABASE_PASSWORD=$(addressdatabase_password)
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种方法来将该值安全地获取到我的容器,而不会将其暴露在管道中。
将管道机密映射到环境变量只是将机密传递给脚本的一种方法。对于其他类型的任务,您应该能够直接在输入中使用秘密,即:
- task: DockerCompose@0
displayName: 'Container Start'
inputs:
containerregistrytype: 'Azure Container Registry'
azureSubscription: '$(containerSubscription)'
azureContainerRegistry: '{"loginServer":"$(containerLoginServer)", "id" : "$(containerRegistryId)"}'
dockerComposeFile: '**/docker-compose.yml'
action: 'Run a Docker Compose command'
dockerComposeCommand: 'up -d'
arguments: mycontainer
containerName: 'cf_$(CreateDb.buildidentifier)'
detached: true
dockerComposeFileArgs: |
addressdatabase_name=$(database-address-name)
addressdatabase_user=$(database-address-user)
addressdatabase_pass=$(database-address-password)
Run Code Online (Sandbox Code Playgroud)
无论您如何传递秘密值,它仍然会在日志中被屏蔽。
| 归档时间: |
|
| 查看次数: |
1049 次 |
| 最近记录: |