From fdbe31e8aa9224e68e441e75bb003c9b27c43e0f Mon Sep 17 00:00:00 2001 From: Umut Date: Sat, 29 May 2021 18:53:47 +0300 Subject: [PATCH] Environment variables implemented --- README.md | 46 +++++++++++++++++++++++++++++--- bin/cdk-spring-pipeline.ts | 6 +---- gh_token.json | 1 - lib/cdk-spring-pipeline-stack.ts | 24 ++++++++--------- 4 files changed, 55 insertions(+), 22 deletions(-) delete mode 100644 gh_token.json diff --git a/README.md b/README.md index 036fefa..7d7f933 100644 --- a/README.md +++ b/README.md @@ -52,13 +52,10 @@ You can see the following file structure while you clone the project. - [ ] Use your own AWS CLI Credentials - [ ] Create Secret Manager with Github token - [ ] Add Environment variables -- [ ] AWS CDK Bootstrap & Sync +- [ ] AWS CDK Bootstrap, Sync & Suppose that you've already fork or clone the repository. Please find the main class `CDKSpringPipeline` and change the attributes and fill with your own credentials. - - - ### Github Credentials You need to create following @@ -83,5 +80,46 @@ aws secretsmanager create-secret --name pipeline/spring-boot-react \ --description "spring-boot-react" \ --secret-string file://gh_token.json ``` +### Environment Variables + + +```bash +export myIP='0.0.0.0/0' +export domainName='subdomain.example.com' +export certArn='arn:aws:acm:::certificate/' +export hostedZoneId='zone_id'; +export instanceIdentifier='spring-postgres' +export rdsSecretName='pipeline/rds' +export owner='repo_owner' +export repo='repo_name' +export branch='master' +export ghbSecretName='pipeline/secret' +export clusterName='spring-cluster' +export serviceName='spring-service' +``` +## Workflow +To run the project, use below scripts iteratively in your terminal. +```bash +export CDK_NEW_BOOTSTRAP=0 +export CDK_DEFAULT_ACCOUNT= +export CDK_DEFAULT_REGION= +cdk bootstrap --show-template > bootstrap-template.yaml +cdk bootstrap aws://$CDK_DEFAULT_ACCOUNT/$CDK_DEFAULT_REGION --cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess --template bootstrap-template.yaml +``` + +Install project specific dependencies. + +```bash +npm install @types/node +npm install +npm run build +``` +You can check diff of changes, synthesize your application stack and deploy. + +```bash +cdk diff +cdk synth +cdk deploy +``` \ No newline at end of file diff --git a/bin/cdk-spring-pipeline.ts b/bin/cdk-spring-pipeline.ts index 745b482..7284c6a 100644 --- a/bin/cdk-spring-pipeline.ts +++ b/bin/cdk-spring-pipeline.ts @@ -2,7 +2,6 @@ import 'source-map-support/register'; import cdk = require('@aws-cdk/core'); import { CDKSpringPipeline } from '../lib/cdk-spring-pipeline-stack'; -// import { RdsBastionStack } from '../lib/rds-postgres-stack'; const app = new cdk.App(); @@ -11,7 +10,4 @@ const env = { account: app.node.tryGetContext('account') || process.env.CDK_INTEG_ACCOUNT || process.env.CDK_DEFAULT_ACCOUNT }; -new CDKSpringPipeline(app, 'CDKSpringPipeline'); -// new RdsBastionStack(app, 'RdsBastionStack'); - - +new CDKSpringPipeline(app, 'CDKSpringPipeline'); \ No newline at end of file diff --git a/gh_token.json b/gh_token.json deleted file mode 100644 index 69c8592..0000000 --- a/gh_token.json +++ /dev/null @@ -1 +0,0 @@ -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 diff --git a/lib/cdk-spring-pipeline-stack.ts b/lib/cdk-spring-pipeline-stack.ts index 444f1e2..f2f430e 100644 --- a/lib/cdk-spring-pipeline-stack.ts +++ b/lib/cdk-spring-pipeline-stack.ts @@ -13,18 +13,18 @@ import elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2'); import acm = require('@aws-cdk/aws-certificatemanager'); import route53 = require('@aws-cdk/aws-route53'); -const myIP = '24.133.236.1/32'; -const domainName = 'spring.commencis-cloud.com'; -const certArn = 'arn:aws:acm:eu-west-1:461902953491:certificate/df046d09-1f1c-4979-b619-4be512876959'; -const hostedZoneId = 'Z05804773E1Y13CUEI66N'; -const instanceIdentifier = 'spring'; -const rdsSecretName = 'pipeline/rds'; -const owner = 'umutykaya'; -const repo = 'spring-boot-react'; -const branch = 'master'; -const ghbSecretName = 'pipeline/secret'; -const clusterName = 'spring-cluster'; -const serviceName = 'spring-service'; +const myIP = process.env.myIP || '0.0.0.0/0'; +const domainName = process.env.domainName || 'subdomain.example.com'; +const certArn = process.env.certArn || 'arn:aws:acm:::certificate/'; +const hostedZoneId = process.env.hostedZoneId || 'hosted_zone_id'; +const instanceIdentifier = process.env.instanceIdentifier || 'spring-postgres'; +const rdsSecretName = process.env.rdsSecretName || 'pipeline/rds'; +const owner = process.env.owner || 'umutykaya'; +const repo = process.env.repo || 'spring-boot-react'; +const branch = process.env.branch || 'master'; +const ghbSecretName = process.env.ghbSecretName || 'pipeline/secret'; +const clusterName = process.env.clusterName || 'spring-cluster'; +const serviceName = process.env.serviceName || 'spring-service'; export class CDKSpringPipeline extends cdk.Stack { projectName: string = 'cdk-spring-pipeline';