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
This commit is contained in:
rapitable
2017-10-04 19:05:43 -07:00
committed by Soam Vasani
parent fd1461cc98
commit 5c47073518
6 changed files with 90 additions and 24 deletions
+5 -5
View File
@@ -24,7 +24,7 @@ Language-neutral components:
Language-specific components: Language-specific components:
* Environment container * Environment container(s)
Controller Controller
@@ -112,13 +112,13 @@ Environment Container
--------------------- ---------------------
Environment containers run user-defined functions. Environment Environment containers run user-defined functions. Environment
containers are language specific. They must contain an HTTP server containers are language specific. Each environment container must
and a loader for functions. contain an HTTP server and a loader for functions.
Poolmgr deploys the environment container into a pod with fetcher 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 (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 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 When poolmgr needs to create a service for a function, it calls
fetcher to fetch the function. Fetcher downloads the function into a 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) ![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 2. Pool manager makes a HTTP POST to logger helper, once helper receives
the request it creates a symlink to container log for fluentd. the request it creates a symlink to container log for fluentd.
3. Fluentd reads log from symlink and pipes to influxdb 3. Fluentd reads log from symlink and pipes to influxdb
+18 -2
View File
@@ -45,8 +45,24 @@ A _function_ is a piece of code that follows the fission function
interface. interface.
An _environment_ contains the language- and runtime-specific parts of An _environment_ contains the language- and runtime-specific parts of
running a function. Fission comes with NodeJS and Python running a function.
environments; you can also extend environments or create entirely new
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 ones if you want. (An environment is essentially just a container
with a webserver and dynamic loader.) with a webserver and dynamic loader.)
+13 -2
View File
@@ -1,7 +1,18 @@
# A docker image for the func container. # 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
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 EXPOSE 8888
+18
View File
@@ -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
+7
View File
@@ -2,12 +2,19 @@
This directory contains several examples to get you started using Node.js with Fission. 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: Before running any of these functions, make sure you have created a `nodejs` Fission environment:
``` ```
$ fission env create --name nodejs --image fission/node-env $ 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 ## Function signature
Every Node.js function has the same basic form: Every Node.js function has the same basic form:
+26 -12
View File
@@ -96,16 +96,28 @@ push_fetcher_image() {
build_and_push_env_image() { build_and_push_env_image() {
version=$1 version=$1
envdir=$2 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 pushd $DIR/environments/$envdir
if [ -f build.sh ] if [ -f build.sh ]
then then
./build.sh ./build.sh
fi fi
docker build -t fission/$imgname:$version . docker build -t fission/$imgname:$version -f $dockerfile .
docker tag fission/$imgname:$version fission/$imgname:latest docker tag fission/$imgname:$version fission/$imgname:latest
docker push fission/$imgname:$version docker push fission/$imgname:$version
docker push fission/$imgname:latest docker push fission/$imgname:latest
@@ -115,15 +127,17 @@ build_and_push_env_image() {
build_and_push_all_envs() { build_and_push_all_envs() {
version=$1 version=$1
build_and_push_env_image $version nodejs node-env # call with version, env dir, image name base, image name variant
build_and_push_env_image $version binary binary-env build_and_push_env_image "$version" "nodejs" "node-env" ""
build_and_push_env_image $version dotnet dotnet-env build_and_push_env_image "$version" "nodejs" "node-env" "debian"
build_and_push_env_image $version dotnet20 dotnet20-env build_and_push_env_image "$version" "binary" "binary-env" ""
build_and_push_env_image $version go go-env build_and_push_env_image "$version" "dotnet" "dotnet-env" ""
build_and_push_env_image $version perl perl-env build_and_push_env_image "$version" "dotnet20" "dotnet20-env" ""
build_and_push_env_image $version php7 php-env build_and_push_env_image "$version" "go" "go-env" ""
build_and_push_env_image $version python3 python-env build_and_push_env_image "$version" "perl" "perl-env" ""
build_and_push_env_image $version ruby ruby-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() { build_charts() {