-
Notifications
You must be signed in to change notification settings - Fork 7
/
docker-image.ts
33 lines (28 loc) · 1.16 KB
/
docker-image.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import fs from "fs";
import path from "path";
import os from "os";
import {randomUUID} from "crypto";
import {aws_lambda} from "aws-cdk-lib";
export class DockerImage {
public static generate(version?: string): aws_lambda.DockerImageCode {
const dockerTempDir = fs.mkdtempSync(path.join(os.tmpdir(), "databricks-cdk-lambda-"));
const dockerFile = path.join(dockerTempDir, "Dockerfile");
const lambdaVersion = version || DockerImage.version();
fs.writeFileSync(dockerFile, `FROM godatadriven/databricks-cdk-lambda:${lambdaVersion}`);
// Random hash will trigger a rebuild always, only need if dev is used
const randomHash = (lambdaVersion == "dev") ? randomUUID() : "";
return aws_lambda.DockerImageCode.fromImageAsset(
dockerTempDir, {
file: "Dockerfile",
buildArgs: {
version: lambdaVersion,
randomHash: randomHash,
}
}
);
}
public static version() {
const pj = require("../package.json"); // eslint-disable-line @typescript-eslint/no-var-requires
return pj.version;
}
}