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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user