Skip to content

Commit f76d0d0

Browse files
committed
chore: use absolute paths for mounts
1 parent f7d37c0 commit f76d0d0

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

src/bundling.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class Bundling {
154154
runtime: props.runtime.name,
155155
architecture: props.architecture ?? Architecture.ARM_64,
156156
buildArgs: props.buildArgs,
157-
rootDir: props.rootDir,
157+
rootDir: path.resolve(props.rootDir),
158158
};
159159

160160
this.containerBuilderKey = `uv-bundling-${hash(hashableProperties)}`;
@@ -167,6 +167,7 @@ export class Bundling {
167167
private ensureBuilderReady(cdkOutDir: string) {
168168
const buildImage = this.createDockerImage();
169169
const hostUvBuildDir = path.join(cdkOutDir, this.containerBuilderKey);
170+
const hostRootDir = path.resolve(this.props.rootDir);
170171

171172
mkdirSync(hostUvBuildDir, { recursive: true });
172173

@@ -182,7 +183,7 @@ export class Bundling {
182183
'-v',
183184
`${hostUvBuildDir}:/uvbuild`,
184185
'-v',
185-
`${this.props.rootDir}:/src:ro`,
186+
`${hostRootDir}:/src:ro`,
186187
buildImage.image,
187188
];
188189

@@ -289,7 +290,7 @@ function getCdkOutDir() {
289290
if (!cdkOutDir) {
290291
throw new Error('CDK_OUTDIR must be set before bundling Lambda assets');
291292
}
292-
return cdkOutDir;
293+
return path.resolve(cdkOutDir);
293294
}
294295

295296
function sanitizeOutputComponent(value: string) {

test/function.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,41 @@ test(
183183
TEST_TIMEOUT,
184184
);
185185

186+
test(
187+
'Create a function when rootDir and CDK_OUTDIR are relative paths',
188+
async () => {
189+
const relativeRootDir = path.relative(
190+
process.cwd(),
191+
path.join(resourcesPath, 'basic_app'),
192+
);
193+
const relativeOutDir = path.relative(
194+
process.cwd(),
195+
process.env.CDK_OUTDIR as string,
196+
);
197+
198+
process.env.CDK_OUTDIR = relativeOutDir;
199+
const { app, stack } = await createStack('relative-paths');
200+
201+
new PythonFunction(stack, 'basic_app_relative', {
202+
rootDir: relativeRootDir,
203+
index: 'handler.py',
204+
handler: 'lambda_handler',
205+
runtime: Runtime.PYTHON_3_12,
206+
architecture: await getDockerHostArch(),
207+
});
208+
209+
const template = Template.fromStack(stack);
210+
const functions = Object.values(
211+
template.findResources('AWS::Lambda::Function'),
212+
);
213+
214+
expect(functions).toHaveLength(1);
215+
const contents = await getFunctionAssetContents(functions[0], app);
216+
expect(contents).toContain('handler.py');
217+
},
218+
TEST_TIMEOUT,
219+
);
220+
186221
test('Reuse one builder container for compatible functions', async () => {
187222
const { stack } = await createStack('shared');
188223
const architecture = await getDockerHostArch();

0 commit comments

Comments
 (0)