Skip to content

Commit

Permalink
Merge pull request #71 from softprops/local-builds
Browse files Browse the repository at this point in the history
working towards local builds and better test cov
  • Loading branch information
softprops authored Jun 3, 2020
2 parents a6d2643 + 5123379 commit f491824
Show file tree
Hide file tree
Showing 37 changed files with 28,831 additions and 11,029 deletions.
11 changes: 0 additions & 11 deletions .eslintrc

This file was deleted.

95 changes: 92 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,104 @@ jobs:
uses: actions/checkout@v1
- name: Install
run: npm ci
- name: Lint
run: npm run lint
- name: Test
run: npm test
integration-test:
local-builds:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup Rust
uses: hecrj/setup-rust-action@v1
with:
rust-version: stable
targets: x86_64-unknown-linux-musl
- name: Install MUSL tools (linux)
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Install MUSL cross tools (osx)
if: matrix.os == 'macos-latest'
run: brew install filosottile/musl-cross/musl-cross
- name: Build
shell: bash
run: |
cd tests/integration/test-func
npm ci -D ../../.. --silent
npx serverless package
- name: Upload artifact
uses: actions/upload-artifact@v1
with:
name: ${{ matrix.os }}-lambda
path: tests/integration/test-func/target/lambda/release/test-func.zip
local-runs:
needs: [local-builds]
runs-on: ubuntu-latest
steps:
- name: Download lambdas
uses: actions/download-artifact@v2
with:
path: lambdas
- name: List Lambdas
run: ls -alh lambdas/
- name: Run macos-latest-lambda
run: |
echo "running macos-latest-lambda"
ls -al lambdas/macos-latest-lambda
unzip -o \
lambdas/macos-latest-lambda/test-func.zip \
-d /tmp/macos-latest-lambda
docker run \
-i --rm \
-v /tmp/macos-latest-lambda:/var/task:ro,delegated \
lambci/lambda:provided 'test-func' '{"some": "event"}'
- name: Run windows-latest-lambda
run: |
echo "running windows-latest-lambda"
ls -al lambdas/windows-latest-lambda
unzip -o \
lambdas/windows-latest-lambda/test-func.zip \
-d /tmp/windows-latest-lambda
docker run \
-i --rm \
-v /tmp/windows-latest-lambda:/var/task:ro,delegated \
lambci/lambda:provided 'test-func' '{"some": "event"}'
- name: Run ubuntu-latest-lambda
run: |
echo "running ubuntu-latest-lambda"
ls -al lambdas/ubuntu-latest-lambda
unzip -o \
lambdas/ubuntu-latest-lambda/test-func.zip \
-d /tmp/ubuntu-latest-lambda
docker run \
-i --rm \
-v /tmp/ubuntu-latest-lambda:/var/task:ro,delegated \
lambci/lambda:provided 'test-func' '{"some": "event"}'
integration-test:
strategy:
matrix:
# docker isn't available on macox-latest or windows-latest
os: [ubuntu-latest]
rust: [stable]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup Rust
uses: hecrj/setup-rust-action@v1
with:
rust-version: stable
targets: x86_64-unknown-linux-musl
- name: Install MUSL tools
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Test
run: tests/test.sh
shell: bash
run: npm run test:integration
publish:
needs: [unit-test, integration-test]
runs-on: ubuntu-latest
Expand All @@ -32,4 +121,4 @@ jobs:
npm publish
env:
CI: true
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
node_modules
target
tests/test-func/test-out.log
tests/test-func-dev/test-out.log
tests/test-func/local-out.log
tests/test-func-dev/local-out.log
.serverless
tests/integration/test-func/test-out.log
tests/integration/test-func-dev/test-out.log
tests/integration/test-func/local-out.log
tests/integration/test-func-dev/local-out.log
.serverless
coverage
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ services:

script:
- npm test
- tests/test.sh
- npm run test:integration
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# ⚡ 0.4.0 (unreleased)

* bump [lambda-rust](https://hub.docker.com/r/softprops/lambda-rust/) docker version to `0.2.6-rust-1.43.0`
* experimental dockerless mode! To enable local builds add the following to your `serverless.yml` file

```yml
custom:
rust:
dockerless: true
```
This comes with some new expectations about your local environment. Please see the readme section on local builds for more information.
* bump [lambda-rust](https://hub.docker.com/r/softprops/lambda-rust/) docker version to `0.2.7-rust-1.43.1`
* The docker image used to build artifacts is now configurable though the `custom.rust.dockerImage` `serverless.yml` config setting. The default remains `softprops/lambda-rust` [#65](https://github.com/softprops/serverless-rust/pull/65)
* The docker cli is now configurable via `SLS_DOCKER_CLI` environment variable. The default is the first `docker` that resolves on your operating system's path. [#61](https://github.com/softprops/serverless-rust/pull/61)

Expand Down
53 changes: 51 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# serverless rust [![Build Status](https://github.com/softprops/serverless-rust/workflows/Main/badge.svg)](https://github.com/softprops/serverless-rust/actions) [![npm](https://img.shields.io/npm/v/serverless-rust.svg)](https://www.npmjs.com/package/serverless-rust)


> A ⚡ [Serverless framework](https://www.serverless.com/) ⚡ plugin for [Rustlang](https://www.rust-lang.org/en-US/) applications 🦀
> A ⚡ [Serverless framework](https://www.serverless.com/framework/docs/) ⚡ plugin for [Rustlang](https://www.rust-lang.org/) applications 🦀
## 📦 Install

Expand Down Expand Up @@ -39,7 +39,7 @@ functions:
method: GET
```
> 💡 The Rust Lambda runtime requires a binary named `bootstrap`. This plugin renames the binary cargo builds to `bootstrap` for you before packaging. You do **not** need to do this manually in your Cargo configuration.
> 💡 The Rust Lambda runtime requires a binary named `bootstrap`. This plugin renames the binary cargo builds to `bootstrap` for you before packaging. You do **not** need to do this manually in your Cargo.toml configuration file.

## 🖍️ customize

Expand All @@ -55,8 +55,57 @@ custom:
cargoFlags: '--features enable-awesome'
# custom docker tag
dockerTag: 'some-custom-tag'
# custom docker image
dockerImage: 'dockerUser/dockerRepo'
```

### 🥼 (experimental) local builds

While it's useful to have a build environment match your deployment
environment, dockerized builds do come with some notable tradeoffs.

The external dependency on docker itself often causes friction as an added dependency to your build. Depending on the docker image limited which versions of rust you could deploy with. The docker image tracked stable rust. Some users might wish to try unstable versions early. Local builds enable that.

If you wish to build lambda's locally, this plugin also supports an experimental `dockerless` mode.

```diff
custom:
# this section allows for customization of the default
# serverless-rust plugin settings
rust:
# flags passed to cargo
cargoFlags: '--features enable-awesome'
# experimental! when set to true, artifacts are built locally outside of docker
+ dockerless: true
```

This will build and link your lambda as a static binary that can be deployed in to the lambda execution environment as a static binary using [MUSL](https://doc.rust-lang.org/edition-guide/rust-2018/platform-and-target-support/musl-support-for-fully-static-binaries.html).

In order to use this mode its expected that you install the `x86_64-unknown-linux-musl` target on all platforms locally with

```sh
$ rustup target add x86_64-unknown-linux-musl
```

On linux platforms, you will need to install musl-tools

```sh
$ sudo apt-get update && sudo apt-get install -y musl-tools
```

On Mac OSX, you will need to install a MUSL cross compilation toolchain

```sh
$ brew install filosottile/musl-cross/musl-cross
```

Using MUSL comes with some other notable tradeoffs. One of which is complications that arise when depending on dynamically linked dependencies.

* With OpenSSL bindings which you can safely replace is with [rustls](https://github.com/ctz/rustls) or [vendor it](https://docs.rs/openssl/0.10.29/openssl/#vendored)
* Other limitations are noted [here](https://github.com/KodrAus/rust-cross-compile#limitations).

If you find other MUSL specific issues, please reported them by [opening an issue](https://github.com/softprops/serverless-rust/issues/new?template=bug_report.md).

### 🎨 Per function customization

If your serverless project contains multiple functions, you may sometimes
Expand Down
Loading

0 comments on commit f491824

Please sign in to comment.