diff --git a/.github/workflows/test-and-release.yaml b/.github/workflows/test-and-release.yaml index 7fe55db0..ccd2c68e 100644 --- a/.github/workflows/test-and-release.yaml +++ b/.github/workflows/test-and-release.yaml @@ -66,7 +66,7 @@ jobs: - name: Generate Stack ID run: | RANDOM_STRING=`node -e "const crypto = require('crypto'); process.stdout.write(crypto.randomBytes(Math.ceil(8 * 0.5)).toString('hex').slice(0, 8));"` - echo "::set-env name=STACK_ID::bifravst-${{ runner.OS }}-${RANDOM_STRING}" + echo "::set-env name=STACK_NAME::bifravst-${{ runner.OS }}-${RANDOM_STRING}" - name: Set up stack for End-to-End tests run: | npx cdk -a 'node --unhandled-rejections=strict dist/cdk/cloudformation-sourcecode.js' deploy @@ -90,7 +90,7 @@ jobs: node cli purge-buckets npx cdk -a 'node --unhandled-rejections=strict dist/cdk/cloudformation-test.js' destroy -f '*' # Delete sourcecode bucket - SOURCE_CODE_BUCKET=`aws cloudformation describe-stacks --stack-name $STACK_ID-sourcecode | jq -r '.Stacks[0].Outputs[] | select(.OutputKey == "bucketName") | .OutputValue'` + SOURCE_CODE_BUCKET=`aws cloudformation describe-stacks --stack-name $STACK_NAME-sourcecode | jq -r '.Stacks[0].Outputs[] | select(.OutputKey == "bucketName") | .OutputValue'` aws s3 rb s3://$SOURCE_CODE_BUCKET --force # Delete the sourceode stack npx cdk -a 'node --unhandled-rejections=strict dist/cdk/cloudformation-sourcecode.js' destroy -f '*' diff --git a/cdk/helper/getLambdaSourceCodeBucketName.ts b/cdk/helper/getLambdaSourceCodeBucketName.ts index 7087253e..1b8fd597 100644 --- a/cdk/helper/getLambdaSourceCodeBucketName.ts +++ b/cdk/helper/getLambdaSourceCodeBucketName.ts @@ -1,5 +1,5 @@ import { CloudFormation } from 'aws-sdk' -import { SOURCECODE_STACK_NAME } from '../stacks/stackId' +import { SOURCECODE_STACK_NAME } from '../stacks/stackName' const cf = new CloudFormation({ region: process.env.AWS_DEFAULT_REGION, diff --git a/cdk/resources/WebAppCD.ts b/cdk/resources/WebAppCD.ts index fa03a381..10d675bc 100644 --- a/cdk/resources/WebAppCD.ts +++ b/cdk/resources/WebAppCD.ts @@ -4,7 +4,7 @@ import * as CodeBuild from '@aws-cdk/aws-codebuild' import * as CodePipeline from '@aws-cdk/aws-codepipeline' import * as S3 from '@aws-cdk/aws-s3' import * as SSM from '@aws-cdk/aws-ssm' -import { CORE_STACK_NAME } from '../stacks/stackId' +import { CORE_STACK_NAME } from '../stacks/stackName' export const BuildActionCodeBuild = { category: 'Build', @@ -75,7 +75,7 @@ export class WebAppCD extends CloudFormation.Construct { image: 'aws/codebuild/standard:3.0', environmentVariables: [ { - name: 'STACK_ID', + name: 'STACK_NAME', value: CORE_STACK_NAME, }, { diff --git a/cdk/stacks/Bifravst.ts b/cdk/stacks/Bifravst.ts index 95a350ea..6f722c4c 100644 --- a/cdk/stacks/Bifravst.ts +++ b/cdk/stacks/Bifravst.ts @@ -17,7 +17,7 @@ import { CellGeolocation } from '../resources/CellGeolocation' import { CellGeolocationApi } from '../resources/CellGeolocationApi' import { ThingGroupLambda } from '../resources/ThingGroupLambda' import { ThingGroup } from '../resources/ThingGroup' -import { CORE_STACK_NAME } from './stackId' +import { CORE_STACK_NAME } from './stackName' import { LambdasWithLayer } from '../resources/LambdasWithLayer' import { lambdasOnS3 } from '../resources/lambdasOnS3' diff --git a/cdk/stacks/ContinuousDeployment.ts b/cdk/stacks/ContinuousDeployment.ts index a9932b2a..8c3a3342 100644 --- a/cdk/stacks/ContinuousDeployment.ts +++ b/cdk/stacks/ContinuousDeployment.ts @@ -5,7 +5,7 @@ import * as CodePipeline from '@aws-cdk/aws-codepipeline' import * as SSM from '@aws-cdk/aws-ssm' import * as S3 from '@aws-cdk/aws-s3' import { BuildActionCodeBuild, WebAppCD } from '../resources/WebAppCD' -import { CONTINUOUS_DEPLOYMENT_STACK_NAME } from './stackId' +import { CONTINUOUS_DEPLOYMENT_STACK_NAME } from './stackName' /** * This is the CloudFormation stack sets up the continuous deployment of the project. diff --git a/cdk/stacks/FirmwareCI.ts b/cdk/stacks/FirmwareCI.ts index b5c41de2..0a209235 100644 --- a/cdk/stacks/FirmwareCI.ts +++ b/cdk/stacks/FirmwareCI.ts @@ -4,7 +4,7 @@ import * as S3 from '@aws-cdk/aws-s3' import { FirmwareCI } from '../resources/FirmwareCI' import { ThingGroupLambda } from '../resources/ThingGroupLambda' import { CDKLambdas, PackedLambdas } from '../prepare-resources' -import { FIRMWARE_CI_STACK_NAME } from './stackId' +import { FIRMWARE_CI_STACK_NAME } from './stackName' import { lambdasOnS3 } from '../resources/lambdasOnS3' export class FirmwareCIStack extends CloudFormation.Stack { diff --git a/cdk/stacks/LambdaSourceCodeStorage.ts b/cdk/stacks/LambdaSourceCodeStorage.ts index ca7d6b9b..5928a59a 100644 --- a/cdk/stacks/LambdaSourceCodeStorage.ts +++ b/cdk/stacks/LambdaSourceCodeStorage.ts @@ -1,6 +1,6 @@ import { App, CfnOutput, RemovalPolicy, Stack } from '@aws-cdk/core' import { Bucket } from '@aws-cdk/aws-s3' -import { SOURCECODE_STACK_NAME } from './stackId' +import { SOURCECODE_STACK_NAME } from './stackName' /** * This stack provides a bucket to store the source code for the lambda functions diff --git a/cdk/stacks/WebApps.ts b/cdk/stacks/WebApps.ts index 7e74efce..6f945b53 100644 --- a/cdk/stacks/WebApps.ts +++ b/cdk/stacks/WebApps.ts @@ -1,6 +1,6 @@ import * as CloudFormation from '@aws-cdk/core' import { WebAppHosting } from '../resources/WebAppHosting' -import { WEBAPPS_STACK_NAME } from './stackId' +import { WEBAPPS_STACK_NAME } from './stackName' export class WebAppsStack extends CloudFormation.Stack { public constructor(parent: CloudFormation.App) { diff --git a/cdk/stacks/stackId.ts b/cdk/stacks/stackId.ts deleted file mode 100644 index eda6e50a..00000000 --- a/cdk/stacks/stackId.ts +++ /dev/null @@ -1,6 +0,0 @@ -const STACK_ID = process.env.STACK_ID ?? 'bifravst' -export const CORE_STACK_NAME = STACK_ID -export const WEBAPPS_STACK_NAME = `${STACK_ID}-webapps` -export const SOURCECODE_STACK_NAME = `${STACK_ID}-sourcecode` -export const CONTINUOUS_DEPLOYMENT_STACK_NAME = `${STACK_ID}-continuous-deployment` -export const FIRMWARE_CI_STACK_NAME = `${STACK_ID}-firmware-ci` diff --git a/cdk/stacks/stackName.ts b/cdk/stacks/stackName.ts new file mode 100644 index 00000000..2606e284 --- /dev/null +++ b/cdk/stacks/stackName.ts @@ -0,0 +1,6 @@ +const STACK_NAME = process.env.STACK_NAME ?? 'bifravst' +export const CORE_STACK_NAME = STACK_NAME +export const WEBAPPS_STACK_NAME = `${STACK_NAME}-webapps` +export const SOURCECODE_STACK_NAME = `${STACK_NAME}-sourcecode` +export const CONTINUOUS_DEPLOYMENT_STACK_NAME = `${STACK_NAME}-continuous-deployment` +export const FIRMWARE_CI_STACK_NAME = `${STACK_NAME}-firmware-ci` diff --git a/cli/commands/connect.ts b/cli/commands/connect.ts index 4b329bf2..78f3ef94 100644 --- a/cli/commands/connect.ts +++ b/cli/commands/connect.ts @@ -6,7 +6,7 @@ import { stackOutput } from '@bifravst/cloudformation-helpers' import { CloudFormation } from 'aws-sdk' import { region } from '../../cdk/regions' import * as chalk from 'chalk' -import { WEBAPPS_STACK_NAME } from '../../cdk/stacks/stackId' +import { WEBAPPS_STACK_NAME } from '../../cdk/stacks/stackName' export const connectCommand = ({ endpoint, diff --git a/cli/commands/firmware-ci.ts b/cli/commands/firmware-ci.ts index 837a69c9..8e02bba6 100644 --- a/cli/commands/firmware-ci.ts +++ b/cli/commands/firmware-ci.ts @@ -3,7 +3,7 @@ import { CommandDefinition } from './CommandDefinition' import * as chalk from 'chalk' import { region } from '../../cdk/regions' import { StackOutputs as FirmwareCIStackOutputs } from '../../cdk/stacks/FirmwareCI' -import { FIRMWARE_CI_STACK_NAME } from '../../cdk/stacks/stackId' +import { FIRMWARE_CI_STACK_NAME } from '../../cdk/stacks/stackName' import { stackOutput } from '@bifravst/cloudformation-helpers' import { createDevice } from '../firmware-ci/createDevice' import { deviceFileLocations } from '../jitp/deviceFileLocations' diff --git a/cli/commands/historical-data.ts b/cli/commands/historical-data.ts index 8cbb65ae..afa10633 100644 --- a/cli/commands/historical-data.ts +++ b/cli/commands/historical-data.ts @@ -12,7 +12,7 @@ import { deviceMessagesFields } from '../../historicalData/deviceMessages' import { region } from '../../cdk/regions' import { stackOutput } from '@bifravst/cloudformation-helpers' import { StackOutputs } from '../../cdk/stacks/Bifravst' -import { CORE_STACK_NAME } from '../../cdk/stacks/stackId' +import { CORE_STACK_NAME } from '../../cdk/stacks/stackName' export const historicalDataCommand = (): CommandDefinition => ({ command: 'historical-data', diff --git a/cli/commands/info.ts b/cli/commands/info.ts index 7e7e5063..775efde4 100644 --- a/cli/commands/info.ts +++ b/cli/commands/info.ts @@ -3,7 +3,7 @@ import { stackOutput } from '@bifravst/cloudformation-helpers' import * as chalk from 'chalk' import { CloudFormation } from 'aws-sdk' import { region } from '../../cdk/regions' -import { CORE_STACK_NAME } from '../../cdk/stacks/stackId' +import { CORE_STACK_NAME } from '../../cdk/stacks/stackName' export const infoCommand = (): CommandDefinition => ({ command: 'info', diff --git a/cli/commands/logs.ts b/cli/commands/logs.ts index 9360fd9a..a5e7214b 100644 --- a/cli/commands/logs.ts +++ b/cli/commands/logs.ts @@ -2,7 +2,7 @@ import { CloudFormation, CloudWatchLogs } from 'aws-sdk' import { CommandDefinition } from './CommandDefinition' import * as chalk from 'chalk' import { region } from '../../cdk/regions' -import { CORE_STACK_NAME } from '../../cdk/stacks/stackId' +import { CORE_STACK_NAME } from '../../cdk/stacks/stackName' export const logsCommand = (): CommandDefinition => ({ command: 'logs', diff --git a/cli/commands/purge-buckets.ts b/cli/commands/purge-buckets.ts index 8adfc073..29f9825a 100644 --- a/cli/commands/purge-buckets.ts +++ b/cli/commands/purge-buckets.ts @@ -4,7 +4,7 @@ import { S3, CloudFormation } from 'aws-sdk' import * as chalk from 'chalk' import { retry } from './retry' import { region } from '../../cdk/regions' -import { CORE_STACK_NAME } from '../../cdk/stacks/stackId' +import { CORE_STACK_NAME } from '../../cdk/stacks/stackName' export const purgeBucketsCommand = (): CommandDefinition => ({ command: 'purge-buckets', diff --git a/cli/commands/purge-cas.ts b/cli/commands/purge-cas.ts index 9b24ab4b..bb045aa8 100644 --- a/cli/commands/purge-cas.ts +++ b/cli/commands/purge-cas.ts @@ -3,7 +3,7 @@ import { Iot, CloudFormation } from 'aws-sdk' import { paginate } from '../../util/paginate' import { stackOutput } from '@bifravst/cloudformation-helpers' import { region } from '../../cdk/regions' -import { CORE_STACK_NAME } from '../../cdk/stacks/stackId' +import { CORE_STACK_NAME } from '../../cdk/stacks/stackName' const purgeCACertificate = ({ iot, diff --git a/cli/commands/purge-iot-user-policy-principals.ts b/cli/commands/purge-iot-user-policy-principals.ts index 0acbae8e..233482fe 100644 --- a/cli/commands/purge-iot-user-policy-principals.ts +++ b/cli/commands/purge-iot-user-policy-principals.ts @@ -3,7 +3,7 @@ import { stackOutput } from '@bifravst/cloudformation-helpers' import { Iot, CloudFormation } from 'aws-sdk' import { paginate } from '../../util/paginate' import { region } from '../../cdk/regions' -import { CORE_STACK_NAME } from '../../cdk/stacks/stackId' +import { CORE_STACK_NAME } from '../../cdk/stacks/stackName' export const purgeIotUserPolicyPrincipals = (): CommandDefinition => ({ command: 'purge-iot-user-policy-principals', diff --git a/cli/commands/react-config.ts b/cli/commands/react-config.ts index 3f1875b5..f2d988b1 100644 --- a/cli/commands/react-config.ts +++ b/cli/commands/react-config.ts @@ -6,7 +6,7 @@ import { } from '../../historicalData/settings' import { stackOutput, objectToEnv } from '@bifravst/cloudformation-helpers' import { CloudFormation } from 'aws-sdk' -import { CORE_STACK_NAME, WEBAPPS_STACK_NAME } from '../../cdk/stacks/stackId' +import { CORE_STACK_NAME, WEBAPPS_STACK_NAME } from '../../cdk/stacks/stackName' import { region } from '../../cdk/regions' export const reactConfigCommand = (): CommandDefinition => ({ diff --git a/cli/jitp/createCA.ts b/cli/jitp/createCA.ts index 4e637cfe..f924488a 100644 --- a/cli/jitp/createCA.ts +++ b/cli/jitp/createCA.ts @@ -4,7 +4,7 @@ import { caFileLocations } from './caFileLocations' import { run } from '../process/run' import { toObject } from '@bifravst/cloudformation-helpers' import { region } from '../../cdk/regions' -import { CORE_STACK_NAME } from '../../cdk/stacks/stackId' +import { CORE_STACK_NAME } from '../../cdk/stacks/stackName' /** * Creates a CA certificate and registers it for Just-in-time provisioning diff --git a/feature-runner/run-features.ts b/feature-runner/run-features.ts index 15d069c7..edee7833 100644 --- a/feature-runner/run-features.ts +++ b/feature-runner/run-features.ts @@ -23,7 +23,10 @@ import { uuidHelper } from './steps/uuidHelper' import { STS, CloudFormation } from 'aws-sdk' import { v4 } from 'uuid' import { region } from '../cdk/regions' -import { CORE_STACK_NAME, FIRMWARE_CI_STACK_NAME } from '../cdk/stacks/stackId' +import { + CORE_STACK_NAME, + FIRMWARE_CI_STACK_NAME, +} from '../cdk/stacks/stackName' import { promises as fs } from 'fs' import * as path from 'path' import { firmwareCIStepRunners } from './steps/firmwareCI' diff --git a/historicalData/settings.ts b/historicalData/settings.ts index 6e95be60..9cdb01d3 100644 --- a/historicalData/settings.ts +++ b/historicalData/settings.ts @@ -1,4 +1,4 @@ -import { CORE_STACK_NAME } from '../cdk/stacks/stackId' +import { CORE_STACK_NAME } from '../cdk/stacks/stackName' export const DataBaseName = (): string => `${CORE_STACK_NAME.replace(/-/g, '_')}_historicaldata`