1
0
mirror of synced 2025-12-21 19:06:49 -05:00

Docker image deploy: set config vars (#21365)

* Add Hydro secrets as env vars

* Set app config-vars

* Add config vars previously used via app.json
This commit is contained in:
Robert Sese
2021-09-10 16:58:49 -05:00
committed by GitHub
parent 0dfab8f3df
commit 6c37f45d61
2 changed files with 30 additions and 1 deletions

View File

@@ -7,7 +7,10 @@ export default async function createApp(pullRequest) {
const {
number: pullNumber,
base: {
repo: { name: repo },
repo: {
name: repo,
owner: { login: owner },
},
},
head: { ref: branch },
user: author,
@@ -15,6 +18,20 @@ export default async function createApp(pullRequest) {
const appName = createAppName({ prefix: 'ghd', repo, pullNumber, branch })
// Put together application configuration variables
const isPrivateRepo = owner === 'github' && repo === 'docs-internal'
const { HYDRO_ENDPOINT, HYDRO_SECRET } = process.env
const appConfigVars = {
// These values are usually set in app.json but we need to set them
// ourselves for Docker image deployment.
NODE_ENV: 'production',
ENABLED_LANGUAGES: 'en',
WEB_CONCURRENCY: '1',
// IMPORTANT: These secrets should only be set in the private repo!
// These are required for Hydro event tracking
...(isPrivateRepo && HYDRO_ENDPOINT && HYDRO_SECRET && { HYDRO_ENDPOINT, HYDRO_SECRET }),
}
// Check if there's already a Heroku App for this PR, if not create one
let appExists = true
const heroku = new Heroku({ token: process.env.HEROKU_API_TOKEN })
@@ -58,5 +75,15 @@ export default async function createApp(pullRequest) {
console.log(`Heroku App ${appName} already exists.`)
}
// Set/reconfigure environment variables
// https://devcenter.heroku.com/articles/platform-api-reference#config-vars-update
try {
await heroku.patch(`/apps/${appName}/config-vars`, {
body: appConfigVars,
})
} catch (error) {
throw new Error(`Failed to update Heroku app configuration variables. Error: ${error}`)
}
return appName
}