softprops / serverless-rust

⚡ 🦀 a serverless framework plugin for rustlang applications
https://www.npmjs.com/package/serverless-rust
MIT License
541 stars 81 forks source link

Build in static libraries & musl compilation #66

Closed jlricon closed 4 years ago

jlricon commented 4 years ago

💡 Feature description

At the moment it is not possible to use serverless-rust if one has a dependency on a library that is not present in the build docker environment (An example is libpq which is needed by Diesel). It is possible to build static binaries in Rust using https://github.com/emk/rust-musl-builder so I ended up bypassing serverless-rust altogether and using that for now, but it'd be nice if some of that could be included in the image you use.

💻 Basic example

It would probably just involve copying a few lines into your dockerfile

oorestisime commented 4 years ago

Hitting that as well with libpq. @jlricon would be nice if you could share how you bypassed this issue.

jlricon commented 4 years ago

I use the musl builder and manually package the lambda and upload it. It'd be nicer to just change the dockerfile of this project to use musl and static libs

oorestisime commented 4 years ago

hah, but how do you deploy this to AWS lambda then?

jlricon commented 4 years ago

From the command line using aws-cli

oorestisime commented 4 years ago

Ah ok i thought there was a way to pick your own docker image here this is why i was asking. makes sense. thanks!

softprops commented 4 years ago

possible to use serverless-rust if one has a dependency on a library that is not present in the build docker environment

You might want to take a look at https://github.com/softprops/lambda-rust#-using-hooks This was recently contributed by an external engineer. The engineer wanted a hook for installing extra application specific dependencies.

Making the image configurable should also be doable but the image itself does more than provide host dependencies, it provides the core workflow for building and packaging rust lambdas. I'd like the native lambda builder to stay the default.

From the command line using aws-cli

This is a bit out of scope of this project but I want to make clear that the goal if this repo is to make transparent and plain the existing serverless framework workflow. There are how ever many ways to deploy a lambda. This serverless framework plugin is but one.

oorestisime commented 4 years ago

So i added the install hook there and it gets picked up but the libpq still not found at runtime. do i need to package libpq.so as well?

oorestisime commented 4 years ago

Ok letting this here for anyone who might need it: Install hook:


#!/usr/bin/env bash

echo "install hook called"
yum install -y postgresql-devel

Package hook

#!/usr/bin/env bash

echo "package hook called"
zip -j "$1.zip" /usr/lib64/libpq.so.5
jlricon commented 4 years ago

I'm closing the issue as it has been addressed and/or flagged as out of scope.