Skip to content

Commit 35fed38

Browse files
authored
Merge pull request #18 from umccr/feat/add-build-environment
feat: add build environment
2 parents 76801af + 820d1f0 commit 35fed38

File tree

7 files changed

+241
-214
lines changed

7 files changed

+241
-214
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ repos:
2020
- id: prettier
2121
exclude: pnpm-lock.yaml
2222
- repo: https://github.com/pre-commit/mirrors-eslint
23-
rev: v9.27.0
23+
rev: v9.28.0
2424
hooks:
2525
- id: eslint
2626
files: \.(m|c)?[jt]sx?$

docs/CONFIG.md

Lines changed: 33 additions & 32 deletions
Large diffs are not rendered by default.

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import tseslint from "typescript-eslint";
44
export default tseslint.config(
55
eslint.configs.recommended,
66
tseslint.configs.strictTypeChecked,
7+
tseslint.configs.stylisticTypeChecked,
78
{
89
languageOptions: {
910
parserOptions: {

lib/config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ export interface HtsgetLambdaProps {
107107
* @defaultValue undefined
108108
*/
109109
role?: IRole;
110+
111+
/**
112+
* Override the environment variables used to build htsget. Note that this only adds environment variables that
113+
* get used to build htsget-rs with `cargo`. It has no effect on the environment variables that htsget-rs has when
114+
* the Lambda function is deployed. In general, leave this undefined unless there is a specific reason to override
115+
* the build environment.
116+
*
117+
* @defaultValue undefined
118+
*/
119+
buildEnvironment?: Record<string, string>;
110120
}
111121

112122
/**

lib/htsget-lambda.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,9 @@ export class HtsgetLambda extends Construct {
6767
constructor(scope: Construct, id: string, props: HtsgetLambdaProps) {
6868
super(scope, id);
6969

70-
if (props.htsgetConfig == undefined) {
71-
props.htsgetConfig = {
72-
locations: [],
73-
};
74-
}
70+
props.htsgetConfig ??= {
71+
locations: [],
72+
};
7573

7674
let httpApi: IHttpApi;
7775
if (props.httpApi !== undefined) {
@@ -95,6 +93,8 @@ export class HtsgetLambda extends Construct {
9593
lambdaRole = this.createRole(id);
9694
}
9795

96+
props.buildEnvironment ??= {};
97+
9898
const htsgetLambda = new RustFunction(this, "Function", {
9999
gitRemote: "https://github.com/umccr/htsget-rs",
100100
gitForceClone: props.gitForceClone,
@@ -105,6 +105,7 @@ export class HtsgetLambda extends Construct {
105105
RUSTFLAGS: "-C target-cpu=neoverse-n1",
106106
CARGO_PROFILE_RELEASE_LTO: "true",
107107
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: "1",
108+
...props.buildEnvironment,
108109
},
109110
cargoLambdaFlags: props.cargoLambdaFlags ?? [
110111
this.resolveFeatures(props.htsgetConfig, props.copyTestData ?? false),
@@ -214,7 +215,7 @@ export class HtsgetLambda extends Construct {
214215
const latestCommit = exec("git", [
215216
"ls-remote",
216217
gitRemote,
217-
gitReference || "HEAD",
218+
gitReference ?? "HEAD",
218219
])
219220
.stdout.toString()
220221
.split(/(\s+)/)[0];
@@ -425,14 +426,14 @@ export class HtsgetLambda extends Construct {
425426
bucket?: Bucket,
426427
privateKey?: Secret,
427428
publicKey?: Secret,
428-
): { [key: string]: string } {
429+
): Record<string, string> {
429430
const toHtsgetEnv = (value: unknown) => {
430431
return JSON.stringify(value)
431432
.replaceAll(new RegExp(/"( )*:( )*/g), "=")
432433
.replaceAll('"', "");
433434
};
434435

435-
const out: { [key: string]: string | undefined } = {};
436+
const out: Record<string, string | undefined> = {};
436437
const locations = config.locations ?? [];
437438

438439
if (bucket !== undefined) {
@@ -463,25 +464,25 @@ export class HtsgetLambda extends Construct {
463464
if (
464465
locationsEnv == "[]" &&
465466
(config.environment_override === undefined ||
466-
config.environment_override["HTSGET_LOCATIONS"] === undefined)
467+
config.environment_override.HTSGET_LOCATIONS === undefined)
467468
) {
468469
throw new Error(
469470
"no locations configured, htsget-rs wouldn't be able to access any files!",
470471
);
471472
}
472473

473-
out["HTSGET_LOCATIONS"] = locationsEnv;
474-
out["HTSGET_TICKET_SERVER_CORS_ALLOW_CREDENTIALS"] =
474+
out.HTSGET_LOCATIONS = locationsEnv;
475+
out.HTSGET_TICKET_SERVER_CORS_ALLOW_CREDENTIALS =
475476
corsConfig?.allowCredentials?.toString();
476-
out["HTSGET_TICKET_SERVER_CORS_ALLOW_HEADERS"] =
477-
`[${corsConfig?.allowHeaders?.join(",") as string}]`;
478-
out["HTSGET_TICKET_SERVER_CORS_ALLOW_METHODS"] =
479-
`[${corsConfig?.allowMethods?.join(",") as string}]`;
480-
out["HTSGET_TICKET_SERVER_CORS_ALLOW_ORIGINS"] =
481-
`[${corsConfig?.allowOrigins?.join(",") as string}]`;
482-
out["HTSGET_TICKET_SERVER_CORS_EXPOSE_HEADERS"] =
483-
`[${corsConfig?.exposeHeaders?.join(",") as string}]`;
484-
out["HTSGET_TICKET_SERVER_CORS_MAX_AGE"] = corsConfig?.maxAge
477+
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
478+
out.HTSGET_TICKET_SERVER_CORS_ALLOW_HEADERS = `[${corsConfig?.allowHeaders?.join(",") as string}]`;
479+
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
480+
out.HTSGET_TICKET_SERVER_CORS_ALLOW_METHODS = `[${corsConfig?.allowMethods?.join(",") as string}]`;
481+
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
482+
out.HTSGET_TICKET_SERVER_CORS_ALLOW_ORIGINS = `[${corsConfig?.allowOrigins?.join(",") as string}]`;
483+
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
484+
out.HTSGET_TICKET_SERVER_CORS_EXPOSE_HEADERS = `[${corsConfig?.exposeHeaders?.join(",") as string}]`;
485+
out.HTSGET_TICKET_SERVER_CORS_MAX_AGE = corsConfig?.maxAge
485486
?.toSeconds()
486487
.toString();
487488

@@ -499,6 +500,6 @@ export class HtsgetLambda extends Construct {
499500
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
500501
(out[key] == `[undefined]` || out[key] == "[]") && delete out[key],
501502
);
502-
return out as { [key: string]: string };
503+
return out as Record<string, string>;
503504
}
504505
}

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@
66
"cargo-lambda-cdk": "^0.0.33"
77
},
88
"devDependencies": {
9-
"@eslint/js": "^9.27.0",
10-
"@types/node": "22.15.19",
9+
"@eslint/js": "^9.28.0",
10+
"@types/node": "22.15.29",
1111
"aws-cdk": "2.112.0",
1212
"aws-cdk-lib": "2.112.0",
1313
"constructs": "10.4.2",
14-
"eslint": "^9.27.0",
14+
"eslint": "^9.28.0",
1515
"prettier": "^3.5.3",
16-
"typedoc": "^0.28.4",
17-
"typedoc-plugin-markdown": "^4.6.3",
16+
"typedoc": "^0.28.5",
17+
"typedoc-plugin-markdown": "^4.6.4",
1818
"typescript": "5.8.3",
19-
"typescript-eslint": "^8.32.1"
19+
"typescript-eslint": "^8.33.0"
2020
},
2121
"files": [
2222
"./**/*.d.ts",
2323
"./**/*.js"
2424
],
2525
"license": "MIT",
2626
"name": "htsget-lambda",
27-
"packageManager": "pnpm@9.14.0",
27+
"packageManager": "pnpm@10.11.0",
2828
"peerDependencies": {
2929
"aws-cdk-lib": "^2.112.0"
3030
},
@@ -34,7 +34,7 @@
3434
"prettier": "prettier",
3535
"run": "cdk deploy",
3636
"watch": "tsc -w",
37-
"typedoc": "typedoc"
37+
"typedoc": "typedoc --gitRevision main --plugin typedoc-plugin-markdown"
3838
},
39-
"version": "0.9.0"
39+
"version": "0.9.1"
4040
}

0 commit comments

Comments
 (0)