Skip to content

Commit

Permalink
Bumped to newer infrastructure client
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewpatto committed Sep 5, 2023
1 parent fff4f3d commit 507d8f8
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 138 deletions.
5 changes: 3 additions & 2 deletions dev/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const descriptionWithTag = (tag?: string) =>

// bring this out to the top as it is the type of thing we might want to change during dev
// to point to other PR branches etc
const DEV_DEPLOYED_IMAGE_TAG = "0.4.0";
const DEV_DEPLOYED_IMAGE_TAG = "pr-468";

/**
* Stack for dev
Expand All @@ -50,6 +50,7 @@ new ElsaDataStack(
{
infrastructureStackName: "ElsaDataDevInfrastructureStack",
infrastructureDatabaseInstanceName: "elsa_data_serverless_database",
isDevelopment: true,
urlPrefix: "elsa-data",
// this image gets inserted as the base of the new image being built via buildLocal
imageBaseName: `ghcr.io/elsa-data/elsa-data:${DEV_DEPLOYED_IMAGE_TAG}`,
Expand All @@ -67,6 +68,6 @@ new ElsaDataStack(
},
enableAccessPoints: true,
},
databaseName: "elsa040",
databaseName: "elsa_data",
}
);
19 changes: 14 additions & 5 deletions packages/aws-application/elsa-data-application-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
* The user settable settings for the Elsa Data application cloudMapService.
*/
export interface ElsaDataApplicationSettings {
/**
* If present and true, declares this installation of the application to be development
* level, and therefore removes some guard rails and checks. That is, certain
* destructive operations like wiping the database can be performed without checks
* if isDevelopment is true.
*/
readonly isDevelopment?: boolean;

/**
* The URL prefix (name before first dot in hostname).
* This is something that is expected to be different per deployment (e.g. "elsa", "elsa-demo").
Expand All @@ -27,6 +35,12 @@ export interface ElsaDataApplicationSettings {
*/
readonly imageBaseName: string;

/**
* The name of the database in our database instance - defaults to
* something sensible if not present.
*/
readonly databaseName?: string;

/**
* For the above Docker images - we can add configuration files/folders
* to the image. This allows us to extend the list of folder locations
Expand Down Expand Up @@ -67,11 +81,6 @@ export interface ElsaDataApplicationSettings {
* If present, an alternative CloudMap cloudMapService name for the application - defaults to Application
*/
readonly serviceName?: string;

/**
* If present, an alternative edgedb database name for the application - defaults to something sensible
*/
readonly databaseName?: string;
}

export interface ElsaDataApplicationBuildLocal {
Expand Down
91 changes: 23 additions & 68 deletions packages/aws-application/elsa-data-stack.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import {
ArnComponents,
aws_ecs as ecs,
CfnOutput,
Stack,
StackProps,
} from "aws-cdk-lib";
import { aws_ecs as ecs, CfnOutput, Stack, StackProps } from "aws-cdk-lib";
import { Construct } from "constructs";
import { ElsaDataApplicationConstruct } from "./app/elsa-data-application-construct";
import { ElsaDataStackSettings } from "./elsa-data-stack-settings";
import { StringParameter } from "aws-cdk-lib/aws-ssm";
import { Secret } from "aws-cdk-lib/aws-secretsmanager";
import { Bucket } from "aws-cdk-lib/aws-s3";
import { InfrastructureClient } from "@elsa-data/aws-infrastructure-client";
import { ElsaDataApplicationCommandConstruct } from "./app-command/elsa-data-application-command-construct";
import { ClusterConstruct } from "./construct/cluster-construct";
Expand Down Expand Up @@ -39,35 +30,8 @@ export class ElsaDataStack extends Stack {
) {
super(scope, id, props);

/**
* Workaround for a problem with CDK that on initial pass the values of a valueFromLookup
* are not valid ARNS - which then causes other code to fail - even though eventually the
* value *will* be a real ARN.
*
* See https://github.com/josephedward/aws-cdk/commit/33030e0c2bb46fa909540bff6ae0153d48abc9c2
*
* @param parameterName
* @param dummyComponents
*/
const delayedArnLookupHelper = (
parameterName: string,
dummyComponents: ArnComponents
): string => {
// attempt to get the value from CDK - this might be a dummy value however
const lookupValue = StringParameter.valueFromLookup(this, parameterName);

let returnLookupValue: string;
if (lookupValue.includes("dummy-value")) {
// if dummy value - need to return a plausible ARN
returnLookupValue = this.formatArn(dummyComponents);
} else {
// else eventually return the real value
returnLookupValue = lookupValue;
}

return returnLookupValue;
};

// our client unlocks the ability to fetch/create CDK objects that match our
// installed infrastructure stack (by infrastructure stack name)
const infraClient = new InfrastructureClient(
applicationProps.infrastructureStackName
);
Expand All @@ -83,35 +47,19 @@ export class ElsaDataStack extends Stack {
applicationProps.infrastructureDatabaseInstanceName
);

const edgeDbDnsNoPassword = StringParameter.valueFromLookup(
this,
`/${applicationProps.infrastructureStackName}/Database/${applicationProps.infrastructureDatabaseInstanceName}/EdgeDb/dsnNoPasswordOrDatabase`
);
const edgeDbDsnNoPasswordOrDatabase =
infraClient.getEdgeDbDsnNoPasswordOrDatabaseFromLookup(
this,
applicationProps.infrastructureDatabaseInstanceName
);

const edgeDbAdminPasswordSecret = Secret.fromSecretCompleteArn(
this,
"AdminSecret",
delayedArnLookupHelper(
`/${applicationProps.infrastructureStackName}/Database/${applicationProps.infrastructureDatabaseInstanceName}/EdgeDb/adminPasswordSecretArn`,
{
service: "secretsmanager",
resource: "secret",
resourceName: "adminPasswordSecretThoughThisIsNotReal",
}
)
);
const edgeDbAdminPasswordSecret =
infraClient.getEdgeDbAdminPasswordSecretFromLookup(
this,
applicationProps.infrastructureDatabaseInstanceName
);

const tempBucket = Bucket.fromBucketArn(
this,
"TempBucket",
delayedArnLookupHelper(
`/${applicationProps.infrastructureStackName}/TempPrivateBucket/bucketArn`,
{
service: "s3",
resource: "a-bucket-name-though-this-is-not-real",
}
)
);
const tempBucket = infraClient.getTempBucketFromLookup(this);

// the Elsa Data container is a shared bundling up of the Elsa Data image
const container = new ContainerConstruct(this, "Container", {
Expand All @@ -135,11 +83,18 @@ export class ElsaDataStack extends Stack {

const deployedUrl = `https://${applicationProps.urlPrefix}.${hostedZone.zoneName}`;

if (applicationProps.databaseName === "edgedb")
throw new Error(
"Database name cannot be 'edgedb' as that is reserved for other uses"
);

const makeEnvironment = (): { [p: string]: string } => ({
// deploy as development only if indicated
NODE_ENV: applicationProps.isDevelopment ? "development" : "production",
// we have a DSN that has no password or database name
EDGEDB_DSN: edgeDbDnsNoPassword,
EDGEDB_DSN: edgeDbDsnNoPasswordOrDatabase,
// we can choose the database name ourselves or default it to something sensible
EDGEDB_DATABASE: applicationProps.databaseName ?? "edgedb",
EDGEDB_DATABASE: applicationProps.databaseName ?? "elsa_data",
// we don't do EdgeDb certs (our EdgeDb has made self-signed certs) so we must set this
EDGEDB_CLIENT_TLS_SECURITY: "insecure",
// environment variables set to set up the meta system for Elsa configuration
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-application/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"types": "elsa-data-stack.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/umccr/elsa-data-aws-application"
"url": "https://github.com/elsa-data/aws-application"
},
"license": "MIT",
"scripts": {
Expand All @@ -27,7 +27,7 @@
"targets": {}
},
"dependencies": {
"@elsa-data/aws-infrastructure-client": "^1.2.3"
"@elsa-data/aws-infrastructure-client": "1.2.4"
},
"peerDependencies": {
"aws-cdk-lib": "^2.93.0",
Expand Down
Loading

0 comments on commit 507d8f8

Please sign in to comment.