From e6587b5915de860e8b313f228d20d6da65f2777f Mon Sep 17 00:00:00 2001 From: Baihao Date: Mon, 18 Jul 2022 14:24:16 -0700 Subject: [PATCH] build(express): add label metadata to image When pushing docker images, `LABEL` was not included. As feature requested, release information such as created timestamps, version and git hash will be added. Ticket: BG-52008 --- Dockerfile | 6 ++++++ scripts/update-dockerfile.ts | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7b2f52e001..7cce2dd5bd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -153,6 +153,12 @@ RUN cd /var/bitgo-express && \ yarn link @bitgo/sdk-coin-zec #LINK_END +#LABEL_START +LABEL created="Mon, 18 Jul 2022 20:03:36 GMT" +LABEL version=9.12.0 +LABEL git_hash=973a8b01131f5958dd5b588a17dc4346b148acb3 +#LABEL_END + USER node ENV NODE_ENV production ENV BITGO_BIND 0.0.0.0 diff --git a/scripts/update-dockerfile.ts b/scripts/update-dockerfile.ts index e4f800c305..b905cf1b8e 100644 --- a/scripts/update-dockerfile.ts +++ b/scripts/update-dockerfile.ts @@ -10,11 +10,11 @@ type ManagedModule = { /** * Create a function which can run lerna commands - * @param lernaPath {string} path to lerna binary + * @param {String} lernaPath - path to lerna binary * @returns {function(string, string[], Object.): Promise} */ -function getLernaRunner(lernaPath) { - return async (command, args = [], options = {}) => { +function getLernaRunner(lernaPath: string) { + return async (command: string, args: string[] = [], options = {}) => { const { stdout } = await execa( lernaPath, [command, ...args], @@ -36,7 +36,7 @@ const walkDependencies = (packageName: string, setDeps: Set, grap /** * Get information on the modules in this repo that are managed by lerna. - * @param lerna {function} + * @param {Function} lerna * @returns {Promise<{path: *, name: *, deps: *, version: *}[]>} */ async function updateDockerFile(lerna) { @@ -56,10 +56,16 @@ async function updateDockerFile(lerna) { const linkers = Array.from(setDeps).map((dep) => ` yarn link ${dep.name}`).join(' && \\\n'); const linkContent = `RUN cd /var/bitgo-express && \\\n${linkers}\n`; + + // add metadata about the build to docker labels + let labelContent = `LABEL created="${new Date().toUTCString()}"\n`; // add created timestamp; + labelContent += `LABEL version=${require('../modules/express/package.json').version}\n`; // set current image version from express + labelContent += `LABEL git_hash=${require('child_process').execSync(`git rev-parse HEAD`).toString().trim()}\n`; // set to latest git HEAD hash + dockerContents = dockerContents .replace(/#COPY_START((.|\n)*)#COPY_END/, `#COPY_START\n${copyContent}#COPY_END`) - .replace(/#LINK_START((.|\n)*)#LINK_END/, `#LINK_START\n${linkContent}#LINK_END`); - + .replace(/#LINK_START((.|\n)*)#LINK_END/, `#LINK_START\n${linkContent}#LINK_END`) + .replace(/#LABEL_START((.|\n)*)#LABEL_END/, `#LABEL_START\n${labelContent}#LABEL_END`); fs.writeFileSync('Dockerfile', dockerContents); }