我已经创建了一个Node应用程序,我想为其自动化部署。到目前为止,我只自动化了构建过程,即安装依赖关系,创建对接者映像,并推送到Azure容器注册表。这非常好,并且与下面没有注释的代码相对应。在目前的过程中,我仍然需要
手动更改helmfile配置中的图像标记,并手动执行helmfile -environment=<my-environment> sync.的
我的斗争是在第二部分,因为我相信第一部分是很容易实现的,当我为第二个设置。
在存储库的源目录中,我有一个helmfile.yaml,它可以在构建后立即调用。这就是我试图用下面的设置实现的,这是注释。我的想法是有一个已经安装了helfmile的容器,例如cablespaghetti/helmfile-docker,然后使用Azure kubectl任务连接到K8s集群,然后执行helmfile sync命令。当我得到一个Docker exec fail with exit code 1时,这个方法失败了,可能是因为指定的容器使用入口点方法,这在Azure管道中是不允许的。
然而,这种方法感觉有些麻烦,好像我缺少了一种简单得多的“简单”执行helmfile sync命令的方法。我怎么才能让这个起作用?
trigger:
- dev
resources:
- repo: self
variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: <service-connection>
imageRepository: <node-app-image>
containerRegistry: <registry-name>
dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
tag: '$(Build.BuildId)'
# Agent VM image name
vmImageName: 'ubuntu-latest'
## This was an approach I tried but failed, because the below image is not suitable
# helmfileImageName: 'cablespaghetti/helmfile-docker:3.3.4.1'
# azureSubscriptionEndpoint: <endpoint>
# azureResourceGroup: <resource-group>
# kubernetesCluster: <cluster-name>
# stage: <stage>
stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: NodeTool@0
inputs:
versionSpec: '13.x'
displayName: 'Install Node.js'
- script: |
yarn install
yarn run build
displayName: 'yarn install'
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
## Attempted deploy stage - still missing here is using the above $(tag) to select the correct image
# - stage: Deploy
# displayName: Deploy with helmfile
# jobs:
# - job: Deploy
# displayName: Deploy
# container: cablespaghetti/helmfile-docker:3.3.4.1
# steps:
# - task: Kubernetes@1
# displayName: kubectl login
# inputs:
# connectionType: Azure Resource Manager
# azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
# azureResourceGroup: $(azureResourceGroup)
# kubernetesCluster: $(kubernetesCluster)
# useClusterAdmin: $(useClusterAdmin)
# command: login
# - script: |
# helmfile -environment=$(stage) sync发布于 2020-12-22 07:58:20
由于helmfile未预装在管道代理中。您可以使用脚本任务手动安装helmfile。请查看下面的示例:
- bash: |
curl -L https://github.com/roboll/helmfile/releases/download/v0.135.0/helmfile_linux_amd64 > helmfile
chmod +x helmfile
displayName: 'Install helm'上面的bash任务将在默认的工作目录中安装hemlfile (您可以更改文件路径以将其安装到另一个文件夹)。然后,您可以在下面的脚本任务中使用helmfile命令,如下面的./helmfile -environment=<my-environment> sync。见下文:
- bash: |
az login --service-principal -u "$(AZURE_SERVICE_PRINCIPAL_USER)" -p "$(AZURE_SERVICE_PRINCIPAL_PW_OR_CERT)" --tenant "$(AZURE_SERVICE_PRINCIPAL_TENANT)"
az aks get-credentials --resource-group "$(AZURE_RESOURCE_GROUP)" --name "$(CLUSTER_NAME)"
./helmfile -environment=<my-environment> sync
displayName: 'helmfile sync'https://stackoverflow.com/questions/65397633
复制相似问题