2017-05-11 66 views
1

对于码头编排,我们正在使用mesos和chronos来安排作业运行。如何在DC操作系统中强制执行docker镜像?

现在,我们放下了chronos并尝试通过DCO设置它,使用mesos和节拍器。

在克罗诺斯,我能激活力通过其阳明配置拉着泊坞窗图像:现在

container: 
    type: docker 
    image: registry.example.com:5001/the-app:production 
    forcePullImage: true 

,使用节拍器和mesos在DC/OS,我也希望它迫使它总是拉起来来自注册表的最新映像,而不是依赖于其缓存版本。

然而,对于泊坞窗json的配置似乎有限:

"docker": { 
    "image": "registry.example.com:5001/the-app:production" 
}, 

如果我推到production标签的新形象,旧的图像被用于在mesos作业运行。

只是为了它的缘故,我尝试添加的标志:在PUT请求

"docker": { 
    "image": "registry.example.com:5001/my-app:staging", 
    "forcePullImage": true 
}, 

然而,我得到一个错误:

http PUT example.com/service/metronome/v1/jobs/the-app < app-config.json 

HTTP/1.1 422 Unprocessable Entity 
Connection: keep-alive 
Content-Length: 147 
Content-Type: application/json 
Date: Fri, 12 May 2017 09:57:55 GMT 
Server: openresty/1.9.15.1 

{ 
    "details": [ 
     { 
      "errors": [ 
       "Additional properties are not allowed but found 'forcePullImage'." 
      ], 
      "path": "/run/docker" 
     } 
    ], 
    "message": "Object is not valid" 
} 

我怎样才能做到这一点的DC OS总是拉取最新的图像?还是必须始终通过独特的图像标签更新作业定义?

+0

我在DCOS问题跟踪器上打开了一个关于此问题的文档(https://jira.mesosphere.com/browse/MARATHON-7346)。 – k0pernikus

回答

0

由于这是目前不可能的,我创建了一个feature request要求此功能。


在此期间,我创建了解决方法,以便能够更新图像标签使用打字稿和要求,承诺库注册的所有作业。

基本上我从metronome api中获取所有的工作,按id从我的应用名称开始过滤,然后更改docker镜像,并为每个更改的工作发出一个PUT请求给节拍器api以更新配置。

这里是我的解决方案:

const targetTag = 'stage-build-1501'; // currently hardcoded, should be set via jenkins run 
const app = 'my-app'; 
const dockerImage = `registry.example.com:5001/${app}:${targetTag}`; 

interface JobConfig { 
    id: string; 
    description: string; 
    labels: object; 
    run: { 
     cpus: number, 
     mem: number, 
     disk: number, 
     cmd: string, 
     env: any, 
     placement: any, 
     artifacts: any[]; 
     maxLaunchDelay: 3600; 
     docker: { image: string }; 
     volumes: any[]; 
     restart: any; 
    }; 
} 

const rp = require('request-promise'); 

const BASE_URL = 'http://example.com'; 
const METRONOME_URL = '/service/metronome/v1/jobs'; 
const JOBS_URL = BASE_URL + METRONOME_URL; 

const jobsOptions = { 
    uri: JOBS_URL, 
    headers: { 
     'User-Agent': 'Request-Promise', 
    }, 
    json: true, 
}; 

const createJobUpdateOptions = (jobConfig: JobConfig) => { 
    return { 
     method: 'PUT', 
     body: jobConfig, 
     uri: `${JOBS_URL}/${jobConfig.id}`, 
     headers: { 
      'User-Agent': 'Request-Promise', 
     }, 
     json: true, 
    }; 
}; 

rp(jobsOptions).then((jobs: JobConfig[]) => { 
    const filteredJobs = jobs.filter((job: any) => { 
     return job.id.includes('job-prefix.'); // I don't want to change the image of all jobs, only for the same application 
    }); 

    filteredJobs.map((job: JobConfig) => { 
     job.run.docker.image = dockerImage; 
    }); 

    filteredJobs.map((updateJob: JobConfig) => { 
     console.log(`${updateJob.id} to be updated!`); 
     const requestOption = createJobUpdateOptions(updateJob); 
     rp(requestOption).then((response: any) => { 
      console.log(`Updated schedule for ${updateJob.id}`); 
     }); 
    }); 

}); 
0

我在我的图像回购被验证过类似的问题,我无法提供必要的身份验证使用节拍器语法的信息。我通过指定2个命令而不是直接引用图像来解决这个问题。

docker --config /etc/.docker pull 
docker --config /etc/.docker run 
相关问题