首页 > 解决方案 > 使用 API 部署/更新 Marathon Docker 映像

问题描述

我正在编写代码以自动更新马拉松上部署的图像。我使用马拉松 API 参考http://mesosphere.github.io/marathon/api-console/index.html中列出的 REST 补丁方法

    url = 'https://<my-hostname>:<my-port>/v2/apps'
    h = {'Content-type': 'application/json', 'Accept': 'application/json'}
    data = {'app': { "id": app,
                'container': {
                    'docker': {
                        'image': image}}}}
    print ('requests.patch(%s, %s)' % (url + app, json.dumps(data)))
    r = requests.patch(url + app, headers = h, auth = auth, data = json.dumps(data))
    if r.status_code == 200:
        print('Deployed %s' % app)

代码运行成功,我得到了一个部署 ID,但 UI 没有任何变化。没有新的部署发生。如果我将补丁请求更改为没有数据的获取请求,我会取回我之前使用上面的代码更新的图像。

根据这个类似的 API 参考https://docs.mesosphere.com/1.11/deploying-services/marathon-api/#/apps/V2AppsByAppId1

它说“此操作将创建部署”,但什么也没发生。在 Marathon GUI 中,我根本看不到配置发生变化。如果我重新启动,则重新启动相同的旧部署。我是否错误地解释了 API 参考?

标签: pythonrestdockermarathon

解决方案


如果我正确阅读 API 参考指南,正文应该是:

{ "id": app,
  "container": {
       "docker": {
          "image": image
        }
   }
}

用马拉松 1.4.11 对此进行了测试,并且有效。不知道为什么你会得到一个部署ID,如果我按照你的方式做(使用额外的 {"app":} 层),我会收到一个 500 错误。顺便说一句,我不确定这对单引号和双引号有多敏感。


推荐阅读