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

Commit ae651b0

Browse files
authored
Merge pull request #50 from triggermesh/readme-update
"Run in Docker" readme section added
2 parents 9a74ce1 + 56eb38b commit ae651b0

File tree

1 file changed

+69
-2
lines changed

1 file changed

+69
-2
lines changed

README.md

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ To override, set `--registry-secret` according to [tm docs](https://github.com/t
2020

2121
### Concurrency
2222

23-
Concurrency in KLR represented by two components: parallel running [bootstrap](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html) processes per container and Knative [container concurrency](https://github.com/knative/serving/blob/master/docs/spec/spec.md#revision) model. By default [AWS runtime interface](https://github.com/triggermesh/aws-custom-runtime) fires up 8 bootstrap processes (functions, in other words) and allows multiple concurrent requests (`containerConcurrency: 0`) to be handled by each container. Default concurrency configuration can be changed on function deployment or update using `tm deploy service` command parameters:
23+
Concurrency in KLR represented by two components: parallel running [bootstrap](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html) processes per container and Knative [container concurrency](https://github.com/knative/serving/blob/master/docs/spec/spec.md#revision) model. By default [AWS runtime interface](https://github.com/triggermesh/aws-custom-runtime) fires up 4 bootstrap processes (functions, in other words) and allows multiple concurrent requests (`containerConcurrency: 0`) to be handled by each container. Default concurrency configuration can be changed on function deployment or update using `tm deploy service` command parameters:
2424

2525
`--concurrency <N>` - sets Knative service `containerConcurrency` value to `N`
2626

2727
`--build-argument INVOKER_COUNT=<N>` - passes number of parallel running functions to AWS lambda runtime
2828

2929
Values for these two parameters should be calculated individually for each function and depends on operation characteristics. Knative [autoscaling](https://github.com/knative/docs/blob/master/docs/serving/samples/autoscale-go/README.md) is another important factor that affects service performance, but right now KLR uses default autoscaling configuration.
3030

31-
3231
### Examples
3332

3433
NOTE: all examples below work with [Local Registry](https://github.com/triggermesh/knative-local-registry). If you don't have local registry in knative cluster, you can use external registry as discribed in CLI [documentation](https://github.com/triggermesh/tm#docker-registry)
@@ -259,6 +258,74 @@ curl http://aws-java-sample-java-function.default.dev.triggermesh.io -d '{"event
259258
{"message":"Hello, the current time is Tue Apr 07 13:59:17 GMT 2020"}
260259
```
261260

261+
### Run in Docker
262+
263+
For cases in which the use of additional components (tm CLI, Tekton, Knative, k8s) is undesirable, it is possible to build a KLR function as a standalone Docker container and run it in any environment. To do this, you should extract the Dockerfile from the runtime you are interested in, put it in the directory with your function, update the handler variable, and build the container. Here are Dockerfile definitions for all runtimes:
264+
265+
- [go](https://github.com/triggermesh/knative-lambda-runtime/blob/9a74ce1ac03d56d233cfc7a46d84f2c5e5f2685a/go-1.x/runtime.yaml#L44-L68)
266+
- [java](https://github.com/triggermesh/knative-lambda-runtime/blob/9a74ce1ac03d56d233cfc7a46d84f2c5e5f2685a/java8/runtime.yaml#L43-L53)
267+
- [node-10](https://github.com/triggermesh/knative-lambda-runtime/blob/9a74ce1ac03d56d233cfc7a46d84f2c5e5f2685a/node-10.x/runtime.yaml#L43-L48)
268+
- [node-4](https://github.com/triggermesh/knative-lambda-runtime/blob/9a74ce1ac03d56d233cfc7a46d84f2c5e5f2685a/node-4.x/runtime.yaml#L43-L48)
269+
- [python-2](https://github.com/triggermesh/knative-lambda-runtime/blob/9a74ce1ac03d56d233cfc7a46d84f2c5e5f2685a/python-2.7/runtime.yaml#L43-L50)
270+
- [python-3](https://github.com/triggermesh/knative-lambda-runtime/blob/9a74ce1ac03d56d233cfc7a46d84f2c5e5f2685a/python-3.7/runtime.yaml#L43-L50)
271+
- [ruby-2](https://github.com/triggermesh/knative-lambda-runtime/blob/9a74ce1ac03d56d233cfc7a46d84f2c5e5f2685a/ruby-2.5/runtime.yaml#L43-L47)
272+
273+
274+
Let's build a Python 3.7 function as an example:
275+
276+
1. Create directory and save your function code there:
277+
278+
```
279+
mkdir python
280+
cd python
281+
cat > handler.py <<EOF
282+
import json
283+
import datetime
284+
def endpoint(event, context):
285+
current_time = datetime.datetime.now().time()
286+
body = {
287+
"message": "Hello, the current time is " + str(current_time)
288+
}
289+
response = {
290+
"statusCode": 200,
291+
"body": json.dumps(body)
292+
}
293+
return response
294+
EOF
295+
```
296+
297+
2. Extract the runtime's [Dockerfile](https://github.com/triggermesh/knative-lambda-runtime/blob/9a74ce1ac03d56d233cfc7a46d84f2c5e5f2685a/python-3.7/runtime.yaml#L43-L50), store it in the same directory, and update the `_HANDLER` variable:
298+
299+
```
300+
cat > Dockerfile <<EOF
301+
FROM gcr.io/triggermesh/knative-lambda-python37
302+
ENV _HANDLER handler.endpoint
303+
COPY . .
304+
RUN if [ -f requirements.txt ]; then pip3.7 install -r requirements.txt ;fi
305+
ENTRYPOINT ["/opt/aws-custom-runtime"]
306+
EOF
307+
```
308+
309+
The `_HANDLER` variable in most cases consists of the filename without the file extension, and the function name.
310+
311+
3. Build, run, test:
312+
313+
```
314+
docker build -t python-klr-image .
315+
docker run -d --rm --name python-klr-container python-klr-image
316+
# following command will work if you use Docker bridge network and you have jq tool
317+
# otherwise, you should get the container address manually
318+
curl $(docker inspect python-klr-container | jq .[].NetworkSettings.Networks.bridge.IPAddress -r):8080
319+
```
320+
321+
The response will contain a JSON document with the current time.
322+
323+
4. Cleanup:
324+
325+
```
326+
docker stop python-klr-container
327+
```
328+
262329
### Support
263330

264331
We would love your feedback on this tool so don't hesitate to let us know what is wrong and how we could improve it, just file an [issue](https://github.com/triggermesh/knative-lambda-runtime/issues/new)

0 commit comments

Comments
 (0)