From 59eb49bc7ed6768a16ef96e30c3de2f51a26fa47 Mon Sep 17 00:00:00 2001 From: Kevin Grandon Date: Thu, 11 Jan 2018 15:24:17 -0800 Subject: [PATCH] Add repomod for changing docker base image (#17) --- repomods/docker-base-image.js | 59 +++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 repomods/docker-base-image.js diff --git a/repomods/docker-base-image.js b/repomods/docker-base-image.js new file mode 100644 index 0000000..0597506 --- /dev/null +++ b/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); +});