我们一直在使用带有映像更改触发器的部署配置,以便当新映像出现在配置的映像流中时,将触发新的部署。这相对来说效果很好,但是现在我们面临了新的挑战。管道应等待部署完成,并将成功/失败反映为工作成果。
到目前为止,我们已经考虑到在构建图像时暂停发布。然后,一旦建立,请取消暂停发布和显式发布,然后等待发布完成:
# To work well with previously auto triggered deployments, pause rollouts if present
oc rollout pause dc "$SOURCE_NAME" || true
# apply deployment config
# TODO: Pass all the template parameters
oc process -f delivery-automation/openshift/jdk-service-template.yml -p "SOURCE_NAME=$SOURCE_NAME" -p "IMAGE_NAME=$IMAGE_NAME" | oc apply -f - --validate
# tag the correct image version as latest
# https://docs.openshift.com/container-platform/3.4/dev_guide/application_lifecycle/promoting_applications.html
oc tag "$OC_PROJECT_STORAGE/$IMAGE_NAME:$SOURCE_VERSION" "$IMAGE_NAME:latest"
# gogogogo
oc rollout resume dc "$SOURCE_NAME" || true
#new deployment with latest image
oc rollout latest "$SOURCE_NAME"
#check for rollout is success
oc rollout status "dc/$SOURCE_NAME" --watch
这几乎可以用,除了它仍会触发映像更改部署,然后在oc rollout latest
上失败,因为已经在进行另一部署。
编辑:命令oc rollout resume
实际上启动了图像更改的展示!
我们也尝试修改触发器,以免自动失效:
triggers:
- type: ImageChange
imageChangeParams:
automatic: false
containerNames:
- ${SOURCE_NAME}
from:
kind: ImageStreamTag
name: '${IMAGE_NAME}:latest'
我们也尝试过完全删除图像更改触发器,但是由于无法解析实际图像,因此推出失败了。
答案 0 :(得分:0)
我现在有一个草率的解决方案,如果有人提出更好的选择,我会很高兴:
# reconfigure service and deployment
- oc process -f service-template.yml -p "SOURCE_NAME=$SOURCE_NAME" -p "IMAGE_NAME=$IMAGE_NAME" | oc apply -f - --validate
# tag current version as latest
- oc tag "$OC_PROJECT_STORAGE/$IMAGE_NAME:$SOURCE_VERSION" "$IMAGE_NAME:latest"
# cancel any pending rollout, last one wins!
- oc rollout cancel dc "$SOURCE_NAME" || true
# cancel any pending rollout, make sure cancel completed
- oc rollout status "dc/$SOURCE_NAME" --watch || true
# trigger new rollout
- oc rollout latest "$SOURCE_NAME" -o json | jq -r '"Rollout started - " + (.status.latestVersion | @text)'
# follow up on latest rollout
- oc rollout status "dc/$SOURCE_NAME" --watch
这给我留下了一些剩余的已取消推广,但是从功能上来说,这是令人满意的。