Skip to content

Commit 4775caa

Browse files
authored
docs(docker): Document Docker options to mount volumes. (#70)
1 parent 4202ea4 commit 4775caa

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ new RustFunction(this, 'Rust function', {
176176

177177
To force bundling in a docker container even if `Cargo Lambda` is available in your environment, set the `forcedDockerBundling` prop to `true`. This is useful if you want to make sure that your function is built in a consistent Lambda compatible environment.
178178

179-
By default, these constructs use `ghcr.io/cargo-lambda/cargo-lambda` as the image to build with. Use the `bundling.dockerImage` prop to use a custom bundling image:
179+
By default, these constructs use [ghcr.io/cargo-lambda/cargo-lambda](https://github.com/cargo-lambda/cargo-lambda/pkgs/container/cargo-lambda) as the image to build with. Use the `bundling.dockerImage` prop to use a custom bundling image:
180180

181181
```ts
182182
import { RustFunction } from 'cargo-lambda-cdk';
@@ -207,6 +207,45 @@ new RustFunction(this, 'Rust function', {
207207

208208
This property mirrors values from the `cdk.BundlingOptions` and is passed into `Code.fromAsset`.
209209

210+
If you want to use a custom Docker image, you can use the `bundling.dockerImage` prop:
211+
212+
```ts
213+
import { RustFunction } from 'cargo-lambda-cdk';
214+
215+
new RustFunction(this, 'Rust function', {
216+
manifestPath: 'path/to/package/directory/with/Cargo.toml',
217+
bundling: {
218+
dockerImage: DockerImage.fromRegistry('your_docker_image'),
219+
},
220+
});
221+
```
222+
223+
If you want to mount additional volumes to the Docker container, you can use the `dockerOptions.volumes` prop. This is useful if you want to mount Cargo's cache directory to speed up the build process. The `CARGO_HOME` in the default image is `/usr/local/cargo`.
224+
225+
```ts
226+
import { RustFunction } from 'cargo-lambda-cdk';
227+
import { homedir } from 'os';
228+
import { join } from 'path';
229+
230+
const cargoHome = process.env.CARGO_HOME || join(homedir(), '.cargo');
231+
232+
new RustFunction(this, 'Rust function', {
233+
manifestPath: 'path/to/package/directory/with/Cargo.toml',
234+
bundling: {
235+
dockerOptions: {
236+
volumes: [{
237+
hostPath: join(cargoHome, 'registry'),
238+
containerPath: '/usr/local/cargo/registry',
239+
},
240+
{
241+
hostPath: join(cargoHome, 'git'),
242+
containerPath: '/usr/local/cargo/git',
243+
}],
244+
},
245+
},
246+
});
247+
```
248+
210249
### Command hooks
211250

212251
It is possible to run additional commands by specifying the `commandHooks` prop:

0 commit comments

Comments
 (0)