From fa9313a6067fc41ab10fb0f146cda83696b78e72 Mon Sep 17 00:00:00 2001 From: Matt Oakes Date: Sat, 13 Mar 2021 08:46:30 +0000 Subject: [PATCH] Set the CAPROVER_GIT_COMMIT_SHA env var automatically when building When we are able to and the environment variable isn't already in use, we set the CAPROVER_GIT_COMMIT_SHA env var to the git has that is being deployed. This allows it to be used when building the image and can be copied into the image to use a runtime as well. Fixes #922 --- src/user/ServiceManager.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/user/ServiceManager.ts b/src/user/ServiceManager.ts index b595149..9c86239 100644 --- a/src/user/ServiceManager.ts +++ b/src/user/ServiceManager.ts @@ -166,12 +166,29 @@ class ServiceManager { .getAppsDataStore() .getAppDefinition(appName) .then(function (app) { + const envVars = app.envVars + + const includesGitCommitEnvVar = envVars.find( + (envVar) => envVar.key === 'CAPROVER_GIT_COMMIT_SHA' + ) + const gitHash = + source.captainDefinitionContentSource?.gitHash || + source.uploadedTarPathSource?.gitHash + if (gitHash && !includesGitCommitEnvVar) { + if (gitHash) { + envVars.push({ + key: 'CAPROVER_GIT_COMMIT_SHA', + value: gitHash, + }) + } + } + return self.imageMaker.ensureImage( source, appName, app.captainDefinitionRelativeFilePath, appVersion, - app.envVars + envVars ) }) })