This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BEC-269 | Implement deploy-all script (#22)
* Implement deploy-all script
- Loading branch information
1 parent
5d7b011
commit 84b5c60
Showing
6 changed files
with
150 additions
and
4 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
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
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,68 @@ | ||
import { join } from 'path'; | ||
import { PromptObject } from 'prompts'; | ||
import { OperationsRepository } from './types'; | ||
import { cliPrint, runAndHandleErrors, runShellCommand } from './utils/cli'; | ||
import { promptQuestions } from './utils/prompts'; | ||
import { readOperationsRepository } from './utils/read-operations'; | ||
|
||
const questions = (operationsRepository: OperationsRepository): PromptObject[] => { | ||
return [ | ||
{ | ||
type: 'autocomplete', | ||
name: 'name', | ||
message: 'Which API Integration do you want to deploy?', | ||
choices: Object.keys(operationsRepository.apis).map((api) => ({ title: api, value: api })), | ||
}, | ||
{ | ||
type: 'autocomplete', | ||
name: 'deployment', | ||
message: (prev) => `Which deployment of ${prev} do you want to deploy?`, | ||
choices: (prev) => | ||
Object.keys(operationsRepository.apis[prev].deployments).map((deployment) => ({ | ||
title: deployment, | ||
value: deployment, | ||
})), | ||
}, | ||
]; | ||
}; | ||
|
||
const main = async () => { | ||
const airkeeperVersion = require('@api3/airkeeper/package.json').version; | ||
const operationsRepository = readOperationsRepository(); | ||
const response = await promptQuestions(questions(operationsRepository)); | ||
|
||
const deploymentDirectory = join(__dirname, '..', 'data', 'apis', response.name, 'deployments', response.deployment); | ||
const awsSecretsFilePath = join(deploymentDirectory, 'aws.env'); | ||
|
||
const config = operationsRepository.apis[response.name].deployments[response.deployment].config; | ||
const stage = config.nodeSettings.stage; | ||
const cloudProvider = config.nodeSettings.cloudProvider.type; | ||
if (cloudProvider === 'local') return cliPrint.error('🛑 Cloud provider is local. Please deploy to AWS/GCP.'); | ||
|
||
const region = config.nodeSettings.cloudProvider.region; | ||
if (!region) return cliPrint.error('🛑 Cloud provider region is not set.'); | ||
|
||
const airkeeperDeployCommand = [ | ||
`docker run -it --rm`, | ||
`--env-file ${awsSecretsFilePath}`, | ||
`-v ${deploymentDirectory}:/app/config`, | ||
`api3/airkeeper:${airkeeperVersion} deploy --stage ${stage} --region ${region}`, | ||
].join(' '); | ||
|
||
console.log(`⏳ - Deploying Airkeeper`); | ||
|
||
const deployment = runShellCommand(airkeeperDeployCommand); | ||
|
||
if (deployment.status !== 0) return cliPrint.error('🛑 Airkeeper deployment failed.'); | ||
|
||
console.log( | ||
[ | ||
`🗽 - Airkeeper has been deployed`, | ||
`⏩ - if you also deployed Airnode, please forward the "receipt.json" to the API3 team.`, | ||
`The "receipt.json" contains sensitive information and should not be shared or made public.`, | ||
], | ||
join('\n') | ||
); | ||
}; | ||
|
||
runAndHandleErrors(main); |
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,64 @@ | ||
import { existsSync } from 'fs'; | ||
import { join } from 'path'; | ||
import { PromptObject } from 'prompts'; | ||
import { OperationsRepository } from './types'; | ||
import { cliPrint, runAndHandleErrors, runShellCommand } from './utils/cli'; | ||
import { promptQuestions } from './utils/prompts'; | ||
import { readOperationsRepository } from './utils/read-operations'; | ||
|
||
const questions = (operationsRepository: OperationsRepository): PromptObject[] => { | ||
return [ | ||
{ | ||
type: 'autocomplete', | ||
name: 'name', | ||
message: 'Which API Integration do you want to deploy?', | ||
choices: Object.keys(operationsRepository.apis).map((api) => ({ title: api, value: api })), | ||
}, | ||
{ | ||
type: 'autocomplete', | ||
name: 'deployment', | ||
message: (prev) => `Which deployment of ${prev} do you want to deploy?`, | ||
choices: (prev) => | ||
Object.keys(operationsRepository.apis[prev].deployments).map((deployment) => ({ | ||
title: deployment, | ||
value: deployment, | ||
})), | ||
}, | ||
]; | ||
}; | ||
|
||
const main = async () => { | ||
const nodeVersion = require('@api3/airnode-node/package.json').version; | ||
const operationsRepository = readOperationsRepository(); | ||
const response = await promptQuestions(questions(operationsRepository)); | ||
|
||
const deploymentDirectory = join(__dirname, '..', 'data', 'apis', response.name, 'deployments', response.deployment); | ||
const awsSecretsFilePath = join(deploymentDirectory, 'aws.env'); | ||
const receiptPath = join(deploymentDirectory, 'receipt.json'); | ||
|
||
const airnodeDeployCommand = [ | ||
`docker run -it --rm`, | ||
`-e USER_ID=$(id -u) -e GROUP_ID=$(id -g)`, | ||
`--env-file ${awsSecretsFilePath}`, | ||
`-v ${deploymentDirectory}:/app/config`, | ||
`-v ${deploymentDirectory}:/app/output`, | ||
`api3/airnode-deployer:${nodeVersion} deploy`, | ||
].join(' '); | ||
|
||
console.log(`⏳ - Deploying Airnode...`); | ||
|
||
const deployment = runShellCommand(airnodeDeployCommand); | ||
|
||
if (deployment.status !== 0 || !existsSync(receiptPath)) return cliPrint.error('🛑 Airnode deployment failed.'); | ||
|
||
console.log( | ||
[ | ||
`☁ - Airnode has been deployed`, | ||
`⏩ - Please forward the "receipt.json" in the deployments folder to the API3 team.`, | ||
`The "receipt.json" contains sensitive information and should not be shared or made public.`, | ||
], | ||
join('\n') | ||
); | ||
}; | ||
|
||
runAndHandleErrors(main); |
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
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