Skip to content

Commit

Permalink
Runner docker volumes (#861)
Browse files Browse the repository at this point in the history
Co-authored-by: Helio Machado <[email protected]>
  • Loading branch information
DavidGOrtega and 0x2b3bfa0 authored Jan 21, 2022
1 parent e326f78 commit 471484a
Show file tree
Hide file tree
Showing 5 changed files with 330 additions and 233 deletions.
19 changes: 16 additions & 3 deletions bin/cml/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const runCloud = async (opts) => {
idleTimeout,
name,
single,
dockerVolumes,
cloud,
cloudRegion: region,
cloudType: type,
Expand Down Expand Up @@ -163,7 +164,8 @@ const runCloud = async (opts) => {
spotPrice,
startupScript,
awsSecurityGroup,
awsSubnet
awsSubnet,
dockerVolumes
});
}

Expand Down Expand Up @@ -215,14 +217,16 @@ const runCloud = async (opts) => {

const runLocal = async (opts) => {
winston.info(`Launching ${cml.driver} runner`);
const { workdir, name, labels, single, idleTimeout, noRetry } = opts;
const { workdir, name, labels, single, idleTimeout, noRetry, dockerVolumes } =
opts;

const proc = await cml.startRunner({
workdir,
name,
labels,
single,
idleTimeout
idleTimeout,
dockerVolumes
});

const dataHandler = async (data) => {
Expand Down Expand Up @@ -331,12 +335,16 @@ const run = async (opts) => {
labels,
name,
reuse,
dockerVolumes,
tfResource,
workdir
} = opts;

cml = new CML({ driver, repo, token });

if (dockerVolumes.length && cml.driver !== 'gitlab')
winston.warn('Parameters --docker-volumes is only supported in gitlab');

if (cloud || tfResource) await tf.checkMinVersion();

// prepare tf
Expand Down Expand Up @@ -412,6 +420,11 @@ exports.handler = async (opts) => {
exports.builder = (yargs) =>
yargs.env('CML_RUNNER').options(
kebabcaseKeys({
dockerVolumes: {
type: 'array',
default: [],
description: 'Docker volumes. This feature is only supported in GitLab'
},
labels: {
type: 'string',
default: 'cml',
Expand Down
3 changes: 3 additions & 0 deletions bin/cml/runner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ describe('CML e2e', () => {
--version Show version number [boolean]
--log Maximum log level
[string] [choices: \\"error\\", \\"warn\\", \\"info\\", \\"debug\\"] [default: \\"info\\"]
--docker-volumes Docker volumes. This feature is only
supported in GitLab
[array] [default: []]
--labels One or more user-defined labels for
this runner (delimited with commas)
[string] [default: \\"cml\\"]
Expand Down
21 changes: 17 additions & 4 deletions src/drivers/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@ class Gitlab {
}

async startRunner(opts) {
const { workdir, idleTimeout, single, labels, name } = opts;
const {
workdir,
idleTimeout,
single,
labels,
name,
dockerVolumes = []
} = opts;

let gpu = true;
try {
Expand All @@ -178,14 +185,19 @@ class Gitlab {
try {
const bin = resolve(workdir, 'gitlab-runner');
if (!(await fse.pathExists(bin))) {
const url =
'https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64';
const arch = process.platform === 'darwin' ? 'darwin' : 'linux';
const url = `https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-${arch}-amd64`;
await download({ url, path: bin });
await fs.chmod(bin, '777');
}

const { protocol, host } = new URL(this.repo);
const { token } = await this.registerRunner({ tags: labels, name });

let dockerVolumesTpl = '';
dockerVolumes.forEach((vol) => {
dockerVolumesTpl += `--docker-volumes ${vol} `;
});
const command = `${bin} --log-format="json" run-single \
--builds-dir "${workdir}" \
--cache-dir "${workdir}" \
Expand All @@ -195,7 +207,8 @@ class Gitlab {
--wait-timeout ${idleTimeout} \
--executor "${IN_DOCKER ? 'shell' : 'docker'}" \
--docker-image "iterativeai/cml:${gpu ? 'latest-gpu' : 'latest'}" \
--docker-runtime "${gpu ? 'nvidia' : ''}" \
${gpu ? '--docker-runtime nvidia' : ''} \
${dockerVolumesTpl} \
${single ? '--max-builds 1' : ''}`;

return spawn(command, { shell: true });
Expand Down
4 changes: 3 additions & 1 deletion src/terraform.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ const iterativeCmlRunnerTpl = (opts = {}) => {
spotPrice,
startupScript,
awsSecurityGroup,
awsSubnet
awsSubnet,
dockerVolumes
} = opts;

const template = `
Expand Down Expand Up @@ -117,6 +118,7 @@ resource "iterative_cml_runner" "runner" {
? `metadata = {\n ${mapCloudMetadata(metadata).join('\n ')}\n }`
: ''
}
${dockerVolumes ? `docker_volumes = ${JSON.stringify(dockerVolumes)}` : ''}
}
`;
return template;
Expand Down
Loading

1 comment on commit 471484a

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

Please sign in to comment.