Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Feat: add copyFiles for container python functions #1134

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions platform/src/components/aws/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1433,10 +1433,14 @@ export class Function extends Component implements Link.Linkable {
const buildResult = all([args, isContainer, linkData]).apply(
async ([args, isContainer, linkData]) => {
if (isContainer) {
const result = await buildPythonContainer(name, {
...args,
links: linkData,
});
const result = await buildPythonContainer(
name,
{
...args,
links: linkData,
},
args.copyFiles
);
if (result.type === "error") {
throw new VisibleError(
`Failed to build function "${args.handler}": ` +
Expand Down Expand Up @@ -2072,4 +2076,4 @@ export class Function extends Component implements Link.Linkable {

const __pulumiType = "sst:aws:Function";
// @ts-expect-error
Function.__pulumiType = __pulumiType;
Function.__pulumiType = __pulumiType;
18 changes: 15 additions & 3 deletions platform/src/runtime/python.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import path from "path";
import fs from "fs/promises";
import { exec } from "child_process";
import pulumi from "@pulumi/pulumi";
import pulumi, { Input, UnwrappedArray } from "@pulumi/pulumi";
import fsSync from "fs";
import { Semaphore } from "../util/semaphore.js";
import { FunctionArgs } from "../components/aws/function.js";
import { findAbove } from "../util/fs.js";
import os from "os";

const limiter = new Semaphore(
parseInt(process.env.SST_BUILD_CONCURRENCY || "4"),
Expand All @@ -20,6 +19,7 @@ export async function buildPythonContainer(
properties: any;
}[];
},
copyFiles?: UnwrappedArray<{ from: Input<string>; to?: Input<string> }>,
): Promise<
| {
type: "success";
Expand Down Expand Up @@ -97,6 +97,18 @@ export async function buildPythonContainer(
);
}

// add copyFiles to the output directory
if (copyFiles) {
// Copy files to the output directory and make directories if they don't exist
copyFiles.forEach(async (file) => {
const from = path.join($cli.paths.root, file.from);
const to = path.join(out, file.to || file.from);
await fs.mkdir(path.dirname(to), { recursive: true });
// copy file or directory
await fs.cp(from, to, { recursive: true });
});
}

return {
type: "success",
out,
Expand Down Expand Up @@ -229,4 +241,4 @@ export async function buildPython(
} finally {
limiter.release();
}
}
}