Skip to content

Commit f491824

Browse files
authored
Merge pull request #71 from softprops/local-builds
working towards local builds and better test cov
2 parents a6d2643 + 5123379 commit f491824

37 files changed

+28831
-11029
lines changed

.eslintrc

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,104 @@ jobs:
1010
uses: actions/checkout@v1
1111
- name: Install
1212
run: npm ci
13+
- name: Lint
14+
run: npm run lint
1315
- name: Test
1416
run: npm test
15-
integration-test:
17+
local-builds:
18+
strategy:
19+
matrix:
20+
os: [ubuntu-latest, windows-latest, macos-latest]
21+
runs-on: ${{ matrix.os }}
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v1
25+
- name: Setup Rust
26+
uses: hecrj/setup-rust-action@v1
27+
with:
28+
rust-version: stable
29+
targets: x86_64-unknown-linux-musl
30+
- name: Install MUSL tools (linux)
31+
if: matrix.os == 'ubuntu-latest'
32+
run: sudo apt-get update && sudo apt-get install -y musl-tools
33+
- name: Install MUSL cross tools (osx)
34+
if: matrix.os == 'macos-latest'
35+
run: brew install filosottile/musl-cross/musl-cross
36+
- name: Build
37+
shell: bash
38+
run: |
39+
cd tests/integration/test-func
40+
npm ci -D ../../.. --silent
41+
npx serverless package
42+
- name: Upload artifact
43+
uses: actions/upload-artifact@v1
44+
with:
45+
name: ${{ matrix.os }}-lambda
46+
path: tests/integration/test-func/target/lambda/release/test-func.zip
47+
local-runs:
48+
needs: [local-builds]
1649
runs-on: ubuntu-latest
50+
steps:
51+
- name: Download lambdas
52+
uses: actions/download-artifact@v2
53+
with:
54+
path: lambdas
55+
- name: List Lambdas
56+
run: ls -alh lambdas/
57+
- name: Run macos-latest-lambda
58+
run: |
59+
echo "running macos-latest-lambda"
60+
ls -al lambdas/macos-latest-lambda
61+
unzip -o \
62+
lambdas/macos-latest-lambda/test-func.zip \
63+
-d /tmp/macos-latest-lambda
64+
docker run \
65+
-i --rm \
66+
-v /tmp/macos-latest-lambda:/var/task:ro,delegated \
67+
lambci/lambda:provided 'test-func' '{"some": "event"}'
68+
- name: Run windows-latest-lambda
69+
run: |
70+
echo "running windows-latest-lambda"
71+
ls -al lambdas/windows-latest-lambda
72+
unzip -o \
73+
lambdas/windows-latest-lambda/test-func.zip \
74+
-d /tmp/windows-latest-lambda
75+
docker run \
76+
-i --rm \
77+
-v /tmp/windows-latest-lambda:/var/task:ro,delegated \
78+
lambci/lambda:provided 'test-func' '{"some": "event"}'
79+
- name: Run ubuntu-latest-lambda
80+
run: |
81+
echo "running ubuntu-latest-lambda"
82+
ls -al lambdas/ubuntu-latest-lambda
83+
unzip -o \
84+
lambdas/ubuntu-latest-lambda/test-func.zip \
85+
-d /tmp/ubuntu-latest-lambda
86+
docker run \
87+
-i --rm \
88+
-v /tmp/ubuntu-latest-lambda:/var/task:ro,delegated \
89+
lambci/lambda:provided 'test-func' '{"some": "event"}'
90+
integration-test:
91+
strategy:
92+
matrix:
93+
# docker isn't available on macox-latest or windows-latest
94+
os: [ubuntu-latest]
95+
rust: [stable]
96+
runs-on: ${{ matrix.os }}
1797
steps:
1898
- name: Checkout
1999
uses: actions/checkout@v1
100+
- name: Setup Rust
101+
uses: hecrj/setup-rust-action@v1
102+
with:
103+
rust-version: stable
104+
targets: x86_64-unknown-linux-musl
105+
- name: Install MUSL tools
106+
if: matrix.os == 'ubuntu-latest'
107+
run: sudo apt-get update && sudo apt-get install -y musl-tools
20108
- name: Test
21-
run: tests/test.sh
109+
shell: bash
110+
run: npm run test:integration
22111
publish:
23112
needs: [unit-test, integration-test]
24113
runs-on: ubuntu-latest
@@ -32,4 +121,4 @@ jobs:
32121
npm publish
33122
env:
34123
CI: true
35-
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
124+
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

.gitignore

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
node_modules
22
target
3-
tests/test-func/test-out.log
4-
tests/test-func-dev/test-out.log
5-
tests/test-func/local-out.log
6-
tests/test-func-dev/local-out.log
7-
.serverless
3+
tests/integration/test-func/test-out.log
4+
tests/integration/test-func-dev/test-out.log
5+
tests/integration/test-func/local-out.log
6+
tests/integration/test-func-dev/local-out.log
7+
.serverless
8+
coverage

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ services:
1515

1616
script:
1717
- npm test
18-
- tests/test.sh
18+
- npm run test:integration

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# ⚡ 0.4.0 (unreleased)
22

3-
* bump [lambda-rust](https://hub.docker.com/r/softprops/lambda-rust/) docker version to `0.2.6-rust-1.43.0`
3+
* experimental dockerless mode! To enable local builds add the following to your `serverless.yml` file
4+
5+
```yml
6+
custom:
7+
rust:
8+
dockerless: true
9+
```
10+
11+
This comes with some new expectations about your local environment. Please see the readme section on local builds for more information.
12+
13+
* bump [lambda-rust](https://hub.docker.com/r/softprops/lambda-rust/) docker version to `0.2.7-rust-1.43.1`
414
* 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)
515
* 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)
616

README.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# 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)
22

33

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

@@ -39,7 +39,7 @@ functions:
3939
method: GET
4040
```
4141
42-
> 💡 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.
42+
> 💡 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.
4343

4444
## 🖍️ customize
4545

@@ -55,8 +55,57 @@ custom:
5555
cargoFlags: '--features enable-awesome'
5656
# custom docker tag
5757
dockerTag: 'some-custom-tag'
58+
# custom docker image
59+
dockerImage: 'dockerUser/dockerRepo'
5860
```
5961

62+
### 🥼 (experimental) local builds
63+
64+
While it's useful to have a build environment match your deployment
65+
environment, dockerized builds do come with some notable tradeoffs.
66+
67+
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.
68+
69+
If you wish to build lambda's locally, this plugin also supports an experimental `dockerless` mode.
70+
71+
```diff
72+
custom:
73+
# this section allows for customization of the default
74+
# serverless-rust plugin settings
75+
rust:
76+
# flags passed to cargo
77+
cargoFlags: '--features enable-awesome'
78+
# experimental! when set to true, artifacts are built locally outside of docker
79+
+ dockerless: true
80+
```
81+
82+
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).
83+
84+
In order to use this mode its expected that you install the `x86_64-unknown-linux-musl` target on all platforms locally with
85+
86+
```sh
87+
$ rustup target add x86_64-unknown-linux-musl
88+
```
89+
90+
On linux platforms, you will need to install musl-tools
91+
92+
```sh
93+
$ sudo apt-get update && sudo apt-get install -y musl-tools
94+
```
95+
96+
On Mac OSX, you will need to install a MUSL cross compilation toolchain
97+
98+
```sh
99+
$ brew install filosottile/musl-cross/musl-cross
100+
```
101+
102+
Using MUSL comes with some other notable tradeoffs. One of which is complications that arise when depending on dynamically linked dependencies.
103+
104+
* 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)
105+
* Other limitations are noted [here](https://github.com/KodrAus/rust-cross-compile#limitations).
106+
107+
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).
108+
60109
### 🎨 Per function customization
61110

62111
If your serverless project contains multiple functions, you may sometimes

0 commit comments

Comments
 (0)