Skip to content
This repository has been archived by the owner on May 14, 2019. It is now read-only.

Commit

Permalink
Add repomod for changing docker base image (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinGrandon committed Jan 11, 2018
1 parent ceac354 commit 59eb49b
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions repomods/docker-base-image.js
@@ -0,0 +1,59 @@
const fs = require('fs');
const shelljs = require('shelljs');

const checkoutBranch = require('./../src/utils/branch/checkoutBranch.js');
const fastForwardBranch = require('./../src/utils/branch/fastForwardBranch.js');
const validateBranchWithUpstream = require('./../src/utils/branch/validateBranchWithUpstream');
const deleteBranch = require('./../src/utils/branch/deleteBranch.js');
const makeBranch = require('./../src/utils/branch/makeBranch.js');
const makePullRequest = require('./../src/utils/makePullRequest.js');
const pause = require('./../src/utils/pause.js');
const withEachRepo = require('./../src/utils/withEachRepo.js');

const BASE_IMAGE = 'FROM uber/web-base-image:1.0.0';

const repoParentFolder = process.cwd() + '/../';
const originBranch = 'orchestrate-docker-base-image';
const commitTitle = `Use web base docker image`;

withEachRepo(async (api, repo) => {
checkoutBranch(repo, 'master');
fastForwardBranch(repo, 'master');
validateBranchWithUpstream(repo, 'master');
deleteBranch(api, repo, originBranch);
makeBranch(repo, originBranch);

const repoFolder = `${repoParentFolder}${repo.name}`;

// Remove unused XVFB files
try {
fs.unlinkSync(`${repoFolder}/.buildkite/xvfb_daemon_run`);
fs.unlinkSync(`${repoFolder}/.buildkite/xvfb_init`);
} catch (e) {
console.log(e);
}

// Get Docker content
let dockerContent = fs.readFileSync(`${repoFolder}/Dockerfile`, 'utf8');

// Update base image
dockerContent = dockerContent.replace(/FROM\s+node.*/, BASE_IMAGE);

// Write pipeline yml
fs.writeFileSync(`${repoFolder}/Dockerfile`, dockerContent, 'utf8');

// Commit changes & push
shelljs.exec(`
cd ${repoFolder} &&
git commit -a -m "${commitTitle}" &&
git push origin ${originBranch}
`);

// Open pull request
await makePullRequest(api, repo, {
title: commitTitle,
originBranch,
});

await pause(200);
});

0 comments on commit 59eb49b

Please sign in to comment.