This repository has been archived by the owner on May 14, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add repomod for changing docker base image (#17)
- Loading branch information
1 parent
ceac354
commit 59eb49b
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |