我创建了一个 Node 应用程序,我想为其自动部署。到目前为止,我只自动化了构建过程,即安装依赖项、创建 docker 映像并推送到 Azure 容器注册表。这工作得很好,并且对应于下面没有被注释掉的代码。在目前的过程中,我仍然需要
- 手动更改我的 helmfile 配置中的图像标签和
- 手动执行一个
helmfile -environment=<my-environment> sync
.
我的斗争是在第二部分,因为我相信当我有第二部分的设置时,第一部分很容易实现。
在存储库的源目录中,我helmfile.yaml
可以在构建后立即调用它。这是我试图通过以下评论的设置来实现的。我的想法是有一个helfmile
已经安装的容器,例如cablespaghetti/helmfile-docker
,然后使用 Azure 任务连接到 K8s 集群kubectl
,然后执行helmfile sync
命令。这种方法失败了,因为我得到了一个Docker exec fail with exit code 1
,可能是因为指定的容器使用了 ENTRYPOINT 方法,这在 Azure Pipeline 中是不允许的。
然而,这种方法感觉有些麻烦,好像我错过了一种更简单的“简单”执行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