Skip to content

Commit 0367279

Browse files
committed
fix: ok
1 parent c807c7f commit 0367279

6 files changed

Lines changed: 38 additions & 10 deletions

File tree

src/api/FaableApi.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ export interface FaableAppRegistry {
1313
password: string;
1414
}
1515

16+
export interface Secret {
17+
id: string;
18+
related: string;
19+
name: string;
20+
value: string;
21+
}
22+
1623
function handleError(message?: string) {
1724
return function (
1825
target: any,
@@ -43,7 +50,7 @@ function handleError(message?: string) {
4350

4451
type Page<Q> = { results: Q[] };
4552

46-
const paginate = async <T, Q extends Promise<Page<T>>>(
53+
const firstPage = async <T, Q extends Promise<Page<T>>>(
4754
res: Q
4855
): Promise<Awaited<Q>["results"]> => {
4956
const items = (await res).results;
@@ -72,7 +79,7 @@ export class FaableApi<T = any> {
7279

7380
@handleError()
7481
async list() {
75-
return paginate(data(this.client.get<Page<FaableApp>>(`/app`)));
82+
return firstPage(data(this.client.get<Page<FaableApp>>(`/app`)));
7683
}
7784

7885
@handleError()
@@ -93,4 +100,8 @@ export class FaableApi<T = any> {
93100
}) {
94101
return data(this.client.post<{ id: string }>(`/deployment`, params));
95102
}
103+
@handleError()
104+
async getAppSecrets(app_id: string) {
105+
return firstPage(data(this.client.get<Page<Secret>>(`/secret/${app_id}`)));
106+
}
96107
}

src/commands/deploy/deploy_command.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,19 @@ export const deploy_command = async (args: DeployCommandArgs) => {
3232
await check_environment();
3333

3434
log.info(
35-
`🚀 Deploying ${app.name} (${app.id}) runtime=${runtime.name}-${runtime.version} `
35+
`🚀 Deploying ${app.name} (${app.id}) runtime=${runtime.name}-${runtime.version}`
3636
);
3737

38+
// get environment variables
39+
const env_vars = await api.getAppSecrets(app.id);
40+
3841
let type;
3942

4043
if (runtime.name == "node") {
4144
const node_result = await build_node(app, {
4245
workdir,
4346
runtime,
47+
env_vars,
4448
});
4549
type = node_result.type;
4650
} else if (runtime.name == "docker") {

src/commands/deploy/node-pipeline/bundle_docker.ts renamed to src/commands/deploy/node-pipeline/build_docker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ interface BuildConfig {
3636
};
3737
}
3838

39-
export const bundle_docker = async (props: BuildConfig) => {
39+
export const build_docker = async (props: BuildConfig) => {
4040
const { app, workdir, template_context } = props;
4141

4242
const entrypoint_custom = entrypoint_template(template_context);

src/commands/deploy/node-pipeline/build_project.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FaableApp } from "../../../api/FaableApi";
1+
import { FaableApp, Secret } from "../../../api/FaableApi";
22
import { log } from "../../../log";
33
import { cmd } from "../../../lib/cmd";
44
import { Configuration } from "../../../lib/Configuration";
@@ -9,6 +9,7 @@ interface BuildProjectArgs {
99
/**build script*/
1010
build_script?: string;
1111
cwd?: string;
12+
env?: Record<string, string>;
1213
}
1314

1415
export const build_project = async (args: BuildProjectArgs) => {

src/commands/deploy/node-pipeline/index.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
1-
import { FaableApp } from "../../../api/FaableApi";
2-
import { bundle_docker } from "./bundle_docker";
1+
import { FaableApp, Secret } from "../../../api/FaableApi";
2+
import { build_docker } from "./build_docker";
33
import { analyze_package } from "./analyze_package";
44
import { build_project } from "./build_project";
55
import { Runtime } from "../runtime-detect/RuntimeStrategy";
6+
import * as R from "ramda";
7+
import { log } from "../../../log";
68

79
interface BuildNodeOptions {
810
workdir: string;
911
runtime: Runtime;
12+
env_vars?: Secret[];
1013
}
1114

1215
export const build_node = async (app: FaableApp, options: BuildNodeOptions) => {
1316
// log.info(`🚀 Build Toolchain ${app.name} [${app.id}]`);
14-
const { workdir, runtime } = options;
17+
const { workdir, runtime, env_vars } = options;
1518

1619
if (!runtime.version) {
1720
throw new Error("Runtime version not specified for node");
1821
}
1922
// Analyze package.json to check if build is needed
2023
const { build_script, type } = await analyze_package({ workdir });
21-
await build_project({ app, build_script });
24+
25+
// Environment variables
26+
27+
const env = R.fromPairs(env_vars.map((e) => [e.name, e.value]));
28+
log.info(`Building with env variables ${Object.keys(env).join(",")}`);
29+
30+
// Do build
31+
await build_project({ app, build_script, env });
2232

2333
// Bundle project inside a docker image
24-
await bundle_docker({
34+
await build_docker({
2535
app,
2636
workdir,
2737
template_context: {

src/lib/cmd.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ interface CmdConfig {
77
timeout: number;
88
/** Sets workdir */
99
cwd: string;
10+
env?: Record<string, string>;
1011
}
1112

1213
export const cmd = async (cmd: string, config?: Partial<CmdConfig>) => {
@@ -20,6 +21,7 @@ export const cmd = async (cmd: string, config?: Partial<CmdConfig>) => {
2021
stdio: enableOutput ? "inherit" : "pipe",
2122
timeout,
2223
cwd,
24+
env: config.env,
2325
});
2426
const out_data: Buffer[] = [];
2527
child.stderr?.on("data", (data) => {

0 commit comments

Comments
 (0)