rust-serverless / lambda-rust

🐳 🦀 a dockerized lambda build env for rust applications
MIT License
34 stars 8 forks source link

Building in a jenkins pipeline with docker. #46

Open theherk opened 2 years ago

theherk commented 2 years ago

I am struggling to sort two things out. I am attempting to build inside a declarative jenkins pipeline. Like this:

def container = docker.image("rustserverless/lambda-rust").run(
    '-i ' +
    '--env CARGO_FLAGS=--arm64 ' +
    '-u "$(id -u)":"$(id -g)" ' +
    '-v ${PWD}:/code '
)

This fails with:

error: Found argument '--arm64' which wasn't expected, or isn't valid in this context

    If you tried to supply `--arm64` as a value rather than a flag, use `-- --arm64`

Fair enough, that was based on a custom argument for cargo lambda. I'm not sure how to correctly target arm64 in this context.


Even if I remove this, though, I get:

Caused by:
  failed to create directory `/cargo/registry/index/github.com-1ecc6299db9ec823`

Caused by:
  Permission denied (os error 13)

But, I don't understand as I haven't mounted a volume for the registry so it seems these should be within the container. Seems this container should have all the permissions required to create a directory within the container, and I thought mounting these were optional for improved builds. Any help would be appreciated.


Maybe the right thing to do is just install cargo-lambda within the container. I'm not really sure what the correct workflow is here.


Actually, I can't run this locally either. Running with podman on mac, presents the same error.

✗ podman run --rm \
    -u "$(id -u)":"$(id -g)" \
    -v ${PWD}:/code \
    rustserverless/lambda-rust
error: failed to get `aws-config` as a dependency of package `mft-rotator v0.1.0 (/code)`

Caused by:
  failed to create directory `/cargo/registry/index/github.com-1ecc6299db9ec823`

Caused by:
  Permission denied (os error 13)

And even if I try to mount a volume with which it can do anything it wants:

✗ podman run --rm \
    -u "$(id -u)":"$(id -g)" \
    -v ${PWD}:/code \
    -v ~/tmpcargo:/cargo \
    rustserverless/lambda-rust

/usr/local/bin/build.sh: line 38: /cargo/env: No such file or directory

or:

✗ podman run --rm \
    -u "$(id -u)":"$(id -g)" \
    -v ${PWD}:/code \
    -v ${HOME}/tmpcargo/registry:/cargo/registry \
    -v ${HOME}/tmpcargo/git:/cargo/git \
    rustserverless/lambda-rust

error: failed to get `aws-config` as a dependency of package `mft-rotator v0.1.0 (/code)`

Caused by:
  failed to create directory `/cargo/registry/index/github.com-1ecc6299db9ec823`

Caused by:
  Permission denied (os error 13)

I'm not sure how to use this in any case.