From 4711e0c55e60b4d095d96667bab85c7a110d19c6 Mon Sep 17 00:00:00 2001 From: Pedro Arantes Date: Thu, 13 May 2021 10:22:51 -0300 Subject: [PATCH] feat: add task environment --- cicd/.gitignore | 3 ++- cicd/carlin.ts | 10 ++++++++++ cicd/carlin.yml | 4 ---- packages/cli/.npmrc | 1 + packages/cli/package.json | 6 +++++- packages/cli/src/deploy/cicd/cicd.template.ts | 3 +++ packages/cli/src/deploy/cicd/command.ts | 17 +++++++++++++++++ packages/cli/src/deploy/cicd/deployCicd.ts | 3 +++ packages/cli/tsconfig.json | 3 ++- packages/website/carlin.yml | 6 ------ 10 files changed, 43 insertions(+), 13 deletions(-) create mode 100644 cicd/carlin.ts delete mode 100644 cicd/carlin.yml create mode 100644 packages/cli/.npmrc diff --git a/cicd/.gitignore b/cicd/.gitignore index f996e9f..222a276 100644 --- a/cicd/.gitignore +++ b/cicd/.gitignore @@ -1 +1,2 @@ -ssh-key* \ No newline at end of file +ssh-key* +npmtoken \ No newline at end of file diff --git a/cicd/carlin.ts b/cicd/carlin.ts new file mode 100644 index 0000000..0a14bdc --- /dev/null +++ b/cicd/carlin.ts @@ -0,0 +1,10 @@ +import * as fs from 'fs'; + +export default { + pipelines: ['tag'], + sshKey: './ssh-key', + sshUrl: 'git@github.com:ttoss/carlin.git', + taskEnvironment: [ + { Name: 'NPM_TOKEN', Value: fs.readFileSync('./npmtoken', 'utf-8') }, + ], +}; diff --git a/cicd/carlin.yml b/cicd/carlin.yml deleted file mode 100644 index 3db481d..0000000 --- a/cicd/carlin.yml +++ /dev/null @@ -1,4 +0,0 @@ -pipelines: - - tag -sshKey: './ssh-key' -sshUrl: git@github.com:ttoss/carlin.git diff --git a/packages/cli/.npmrc b/packages/cli/.npmrc new file mode 100644 index 0000000..ae64359 --- /dev/null +++ b/packages/cli/.npmrc @@ -0,0 +1 @@ +//registry.npmjs.org/:_authToken=${NPM_TOKEN} diff --git a/packages/cli/package.json b/packages/cli/package.json index 376177f..f6c2192 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -6,12 +6,16 @@ "scripts": { "test": "jest", "build": "tsc", - "prepare": "npm run test && rm -rf dist && npm run build" + "prepare": "npm run test && npm run build", + "deploy": "npm publish" }, "repository": { "type": "git", "url": "git+https://github.com/ttoss/carlin.git" }, + "publishConfig": { + "registry": "https://registry.npmjs.org/" + }, "keywords": [], "author": { "email": "arantespp@gmail.com", diff --git a/packages/cli/src/deploy/cicd/cicd.template.ts b/packages/cli/src/deploy/cicd/cicd.template.ts index 3c1b9d5..54832a2 100644 --- a/packages/cli/src/deploy/cicd/cicd.template.ts +++ b/packages/cli/src/deploy/cicd/cicd.template.ts @@ -72,6 +72,7 @@ export const getCicdTemplate = ({ cpu = ECS_TASK_DEFAULT_CPU, memory = ECS_TASK_DEFAULT_MEMORY, s3, + taskEnvironment = [], }: { pipelines: Pipeline[]; cpu?: string; @@ -81,6 +82,7 @@ export const getCicdTemplate = ({ key: string; versionId: string; }; + taskEnvironment?: Array<{ Name: string; Value: string }>; }): CloudFormationTemplate => { const resources: CloudFormationTemplate['Resources'] = {}; @@ -633,6 +635,7 @@ export const getCicdTemplate = ({ ContainerDefinitions: [ { Environment: [ + ...taskEnvironment, { /** * https://docs.aws.amazon.com/AmazonECS/latest/developerguide/container-metadata.html#enable-metadata diff --git a/packages/cli/src/deploy/cicd/command.ts b/packages/cli/src/deploy/cicd/command.ts index e7f4901..a912a79 100644 --- a/packages/cli/src/deploy/cicd/command.ts +++ b/packages/cli/src/deploy/cicd/command.ts @@ -45,6 +45,23 @@ export const options = { demandOption: true, type: 'string', }, + /** + * This option has the format: + * + * ```ts + * Array<{ + * Name: string, + * Value: string, + * }> + * ``` + */ + 'task-environment': { + alias: ['te'], + default: [], + describe: + 'A list of environment variables that will be passed to the ECS container task.', + type: 'array', + }, } as const; export const deployCicdCommand: CommandModule< diff --git a/packages/cli/src/deploy/cicd/deployCicd.ts b/packages/cli/src/deploy/cicd/deployCicd.ts index 72a6d8a..19a0ccd 100644 --- a/packages/cli/src/deploy/cicd/deployCicd.ts +++ b/packages/cli/src/deploy/cicd/deployCicd.ts @@ -89,6 +89,7 @@ export const deployCicd = async ({ repositoryUpdate, sshKey, sshUrl, + taskEnvironment, }: { cpu?: string; memory?: string; @@ -96,6 +97,7 @@ export const deployCicd = async ({ repositoryUpdate?: boolean; sshKey: string; sshUrl: string; + taskEnvironment: Array<{ Name: string; Value: string }>; }) => { try { const { stackName } = await handleDeployInitialization({ @@ -109,6 +111,7 @@ export const deployCicd = async ({ memory, pipelines, s3: await deployCicdLambdas({ stackName }), + taskEnvironment, }), params: { StackName: stackName, diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index a104f62..9855261 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -3,7 +3,8 @@ "compilerOptions": { "incremental": false, // Do not create tsconfig.tsbuildinfo "outDir": "dist", - "noEmit": false + "noEmit": false, + "declaration": false }, "include": ["src"], "exclude": ["**/*.spec.ts", "**/*.test.ts"] diff --git a/packages/website/carlin.yml b/packages/website/carlin.yml index b2fe2de..f503c41 100644 --- a/packages/website/carlin.yml +++ b/packages/website/carlin.yml @@ -1,10 +1,4 @@ environments: - Staging: - aliases: - - carlin.ttoss.dev - csp: - default-src: ["* 'unsafe-inline' 'unsafe-eval'", replace] - stackName: CarlinWebsite Production: aliases: - carlin.ttoss.dev