From 5c470735185b980c1f7987921db360e91c65573b Mon Sep 17 00:00:00 2001 From: rapitable Date: Thu, 5 Oct 2017 03:05:43 +0100 Subject: [PATCH] Make default node-env use alpine. List envs in documentation. (#354) closes #319 * Make default node-env use alpine, and support separate debian env. List envs in documentation. * Copy ONBUILD base image commands into node Dockerfiles * Copy more commands from onbuild image * Tidy dockerfiles --- Documentation/Architecture.md | 10 +++---- README.md | 20 +++++++++++-- environments/nodejs/Dockerfile | 17 +++++++++-- environments/nodejs/Dockerfile-debian | 18 ++++++++++++ examples/nodejs/README.md | 7 +++++ hack/release.sh | 42 ++++++++++++++++++--------- 6 files changed, 90 insertions(+), 24 deletions(-) create mode 100644 environments/nodejs/Dockerfile-debian diff --git a/Documentation/Architecture.md b/Documentation/Architecture.md index aec937b6..8fe98f9f 100644 --- a/Documentation/Architecture.md +++ b/Documentation/Architecture.md @@ -24,7 +24,7 @@ Language-neutral components: Language-specific components: - * Environment container + * Environment container(s) Controller @@ -112,13 +112,13 @@ Environment Container --------------------- Environment containers run user-defined functions. Environment -containers are language specific. They must contain an HTTP server -and a loader for functions. +containers are language specific. Each environment container must +contain an HTTP server and a loader for functions. Poolmgr deploys the environment container into a pod with fetcher (fetcher is a simple utility that can fetch an HTTP url to a file at a configured location). This pod forms a "generic pod", because it can -be loaded with any function. +be loaded with any function in that language. When poolmgr needs to create a service for a function, it calls fetcher to fetch the function. Fetcher downloads the function into a @@ -134,7 +134,7 @@ Following is a diagram describe how log service works: ![Logger Diagram](https://cloud.githubusercontent.com/assets/202578/23100399/b0e3ea00-f6ba-11e6-8f2f-6588cfef2e84.png) -1. Pool manager choose a pod from pool to execute user function +1. Pool manager chooses a pod from the pool to execute user function 2. Pool manager makes a HTTP POST to logger helper, once helper receives the request it creates a symlink to container log for fluentd. 3. Fluentd reads log from symlink and pipes to influxdb diff --git a/README.md b/README.md index e3a70936..d72aafd4 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,24 @@ A _function_ is a piece of code that follows the fission function interface. An _environment_ contains the language- and runtime-specific parts of -running a function. Fission comes with NodeJS and Python -environments; you can also extend environments or create entirely new +running a function. + +The following environments are currently available: + + | Environment | Image | + | ------------------------------------ | ------------------------- | + | Binary (for executables or scripts) | `fission/binary-env` | + | Go | `fission/go-env` | + | .NET | `fission/dotnet-env` | + | .NET 2.0 | `fission/dotnet20-env` | + | NodeJS (Alpine) | `fission/node-env` | + | NodeJS (Debian) | `fission/node-env-debian` | + | Perl | `fission/perl-env` | + | PHP 7 | `fission/php-env` | + | Python 3 | `fission/python-env` | + | Ruby | `fission/ruby-env` | + +You can also extend environments or create entirely new ones if you want. (An environment is essentially just a container with a webserver and dynamic loader.) diff --git a/environments/nodejs/Dockerfile b/environments/nodejs/Dockerfile index 8b6a80e0..f21526cb 100644 --- a/environments/nodejs/Dockerfile +++ b/environments/nodejs/Dockerfile @@ -1,7 +1,18 @@ # A docker image for the func container. -FROM node:8-onbuild +# default variant is the official alpine node image (much smaller than the standard image) +FROM node:8-alpine -ADD server.js /usr/src/app/server.js +ARG NODE_ENV +ENV NODE_ENV $NODE_ENV -EXPOSE 8888 +RUN mkdir -p /usr/src/app +WORKDIR /usr/src/app + +COPY package.json /usr/src/app/ +RUN npm install && npm cache clean --force +COPY server.js /usr/src/app/server.js + +CMD [ "npm", "start" ] + +EXPOSE 8888 \ No newline at end of file diff --git a/environments/nodejs/Dockerfile-debian b/environments/nodejs/Dockerfile-debian new file mode 100644 index 00000000..76d5db33 --- /dev/null +++ b/environments/nodejs/Dockerfile-debian @@ -0,0 +1,18 @@ +# A docker image for the func container. + +# debian variant is the official standard node image (larger than the alpine image) +FROM node:8 + +ARG NODE_ENV +ENV NODE_ENV $NODE_ENV + +RUN mkdir -p /usr/src/app +WORKDIR /usr/src/app + +COPY package.json /usr/src/app/ +RUN npm install && npm cache clean --force +COPY server.js /usr/src/app/server.js + +CMD [ "npm", "start" ] + +EXPOSE 8888 \ No newline at end of file diff --git a/examples/nodejs/README.md b/examples/nodejs/README.md index 9c603cd9..37298861 100644 --- a/examples/nodejs/README.md +++ b/examples/nodejs/README.md @@ -2,12 +2,19 @@ This directory contains several examples to get you started using Node.js with Fission. +## Environment + Before running any of these functions, make sure you have created a `nodejs` Fission environment: ``` $ fission env create --name nodejs --image fission/node-env ``` +Note: The default `fission/node-env` image is based on Alpine, which is much smaller than the main Debian Node image (65MB vs 680MB) while still being suitable for most use cases. +If you need to use the full Debian image use the `fission/node-env-debian` image instead. +See the [official Node docker hub repo](https://hub.docker.com/_/node/) for considerations +relating to this choice. + ## Function signature Every Node.js function has the same basic form: diff --git a/hack/release.sh b/hack/release.sh index c0ba5f51..1bd17166 100755 --- a/hack/release.sh +++ b/hack/release.sh @@ -96,17 +96,29 @@ push_fetcher_image() { build_and_push_env_image() { version=$1 envdir=$2 - imgname=$3 + imgnamebase=$3 + imgvariant=$4 - echo "Building $envdir -> $imgname:$version" + if [ -z "$imgvariant" ] + then + # no variant specified, just use the base name + imgname=$imgnamebase + dockerfile="Dockerfile" + else + # variant specified - append variant to image name and assume dockerfile + # exists with same suffix (e.g. image node-env-debian built from Dockerfile-debian) + imgname="$imgname-$imgvariant" + dockerfile="Dockerfile-$imgvariant" + fi + echo "Building $envdir -> $imgname:$version using $dockerfile" pushd $DIR/environments/$envdir if [ -f build.sh ] then ./build.sh - fi - docker build -t fission/$imgname:$version . - docker tag fission/$imgname:$version fission/$imgname:latest + fi + docker build -t fission/$imgname:$version -f $dockerfile . + docker tag fission/$imgname:$version fission/$imgname:latest docker push fission/$imgname:$version docker push fission/$imgname:latest popd @@ -115,15 +127,17 @@ build_and_push_env_image() { build_and_push_all_envs() { version=$1 - build_and_push_env_image $version nodejs node-env - build_and_push_env_image $version binary binary-env - build_and_push_env_image $version dotnet dotnet-env - build_and_push_env_image $version dotnet20 dotnet20-env - build_and_push_env_image $version go go-env - build_and_push_env_image $version perl perl-env - build_and_push_env_image $version php7 php-env - build_and_push_env_image $version python3 python-env - build_and_push_env_image $version ruby ruby-env + # call with version, env dir, image name base, image name variant + build_and_push_env_image "$version" "nodejs" "node-env" "" + build_and_push_env_image "$version" "nodejs" "node-env" "debian" + build_and_push_env_image "$version" "binary" "binary-env" "" + build_and_push_env_image "$version" "dotnet" "dotnet-env" "" + build_and_push_env_image "$version" "dotnet20" "dotnet20-env" "" + build_and_push_env_image "$version" "go" "go-env" "" + build_and_push_env_image "$version" "perl" "perl-env" "" + build_and_push_env_image "$version" "php7" "php-env" "" + build_and_push_env_image "$version" "python3" "python-env" "" + build_and_push_env_image "$version" "ruby" "ruby-env" "" } build_charts() {