Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Conversation

LegNeato
Copy link
Collaborator

@LegNeato LegNeato commented Oct 2, 2018

Disclaimer: This is ugly code but figured I'd get feedback on the idea and direction before cleaning it up / making it work better

This PR creates a cargo binary (currently invoked with cargo lambda) that runs cargo commands in a docker container, essentially automating the manual lambda docker steps in the repo. Users of the tool can choose dynamic or static (musl) linking and the appropriate docker container with their current version of Rust is used.

Right now there are two commands:

  • cargo lambda build - Runs cargo build in a docker container.
  • cargo lambda raw - Runs a command verbatim in a docker container.

I'm not sure this is the implementation we want, but something like this would be good to have for the average / simple case. We could even eventually add commands like cargo lambda package to make that step easier as well.

There is an open question on how "magical" we want to be and what default assumptions the tool should make. For example, when invoked it will currently set --release unless --dev is already set on the command line. This may be unexpected and undesirable, though we might assume that the average case will be building for prod and should have that set.

Note that docker is an implementation detail and could be swapped out if something better comes up (like https://github.com/srijs/cargo-cross ?).

@LegNeato LegNeato added enhancement New feature or request question Further information is requested wip labels Oct 2, 2018
@dnagir
Copy link

dnagir commented Oct 2, 2018

Hey @LegNeato,
I just noticed this PR and thought I'd give you my $0.02.

I'm building Rust for alpine for my little project as per below.
Not sure if there are any additional things that need to be done for amazonlinux.
But it seems to work on amazonlinux fine.

Building with:

docker run -v $(PWD):/volume -t -v myproject-cargo-cache:/root/.cargo clux/muslrust cargo build --release 

Useful bit here is the use of volume mounted to /root/.cargo - allows caching the build and make them really fast.

The amount of work in this PR look pretty large, so I thought I could mention the above just in case.

While on this subject, how confident are you in the rust-aws-lambda for production?
I love your work here and I'm hoping this won't go unnoticed and will become very popular tool 👍

@LegNeato
Copy link
Collaborator Author

LegNeato commented Oct 2, 2018

@dnagir Yep, the static linking option is basically doing just that:

https://github.com/srijs/rust-aws-lambda/pull/29/files#diff-e34ff64a397ad8eb15ca4f52b56433ddR1

It also does some caching in <crate root>/target/cached_data:

https://github.com/srijs/rust-aws-lambda/pull/29/files#diff-8e3195c9df1ea45af6cdac370d7542eeR125

It would be good to do the cargo cache as well. I'll put it on my list.

There is nothing really special in this tool...everything it does can be done by running Docker directly. The idea would be rather than have a README with all the Docker commands and tradeoffs and gotchas, in the simple case we can just say to install Docker and:

cargo install cargo-lambda; cargo lambda build;

And then if we see a lot of people are filing tasks about deployment and the best options there maybe we also have something like:

cargo lambda package; cargo lambda deploy;

Basically, I want a high-level interface to the low-level build and packaging stuff required to move from building for local to building for lambda.

I have not yet personally used rust-aws-lambda in production but I would not hesitate to do so at this point. In fact, I am planning on using it in production in the next month or so.

@srijs
Copy link
Owner

srijs commented Oct 18, 2018

Nice one!

It'll be a while until my cargo-cross will be usable, if that ever happens (too many things going on at the moment), so using docker for this is probably the right bet (it's also what https://github.com/rust-embedded/cross does, but that's linux-only for the moment).

I'm hoping to have some time on the weekend to go through the code and provide feedback on other parts of the approach!

@LegNeato
Copy link
Collaborator Author

@srijs Don't waste your time with the code, I think I am pretty much going to throw it out and start fresh 😄

@LegNeato LegNeato closed this Dec 11, 2018
@LegNeato
Copy link
Collaborator Author

AWS folks are probably going to tie this into sam.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request question Further information is requested wip

3 participants