This repository has been archived by the owner on Jun 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
- Loading branch information
0 parents
commit 89e780a
Showing
8 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
./node_modules/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
FROM node:6.11.2-alpine | ||
|
||
RUN addgroup -S app && adduser -S -g app app | ||
|
||
# Alternatively use ADD https:// (which will not be cached by Docker builder) | ||
RUN apk --no-cache add curl \ | ||
&& echo "Pulling watchdog binary from Github." \ | ||
&& curl -sSLf https://github.com/openfaas-incubator/of-watchdog/releases/download/0.2.1/of-watchdog > /usr/bin/fwatchdog \ | ||
&& chmod +x /usr/bin/fwatchdog \ | ||
&& apk del curl --no-cache | ||
|
||
WORKDIR /root/ | ||
|
||
# Turn down the verbosity to default level. | ||
ENV NPM_CONFIG_LOGLEVEL warn | ||
|
||
RUN mkdir -p /home/app | ||
|
||
# Wrapper/boot-strapper | ||
WORKDIR /home/app | ||
COPY package.json ./ | ||
|
||
# This ordering means the npm installation is cached for the outer function handler. | ||
RUN npm i | ||
|
||
# Copy outer function handler | ||
COPY index.js ./ | ||
|
||
# COPY function node packages and install, adding this as a separate | ||
# entry allows caching of npm install | ||
WORKDIR /home/app/function | ||
COPY function/*.json ./ | ||
RUN npm i || : | ||
|
||
# COPY function files and folders | ||
COPY function/ ./ | ||
|
||
# Set correct permissions to use non root user | ||
WORKDIR /home/app/ | ||
|
||
# chmod for tmp is for a buildkit issue (@alexellis) | ||
RUN chown app:app -R /home/app \ | ||
&& chmod 777 /tmp | ||
|
||
USER app | ||
|
||
ENV cgi_headers="true" | ||
ENV fprocess="node index.js" | ||
ENV mode="http" | ||
ENV upstream_url="http://127.0.0.1:3000" | ||
|
||
HEALTHCHECK --interval=1s CMD [ -e /tmp/.lock ] || exit 1 | ||
|
||
CMD ["fwatchdog"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"use strict" | ||
|
||
module.exports = (context, callback) => { | ||
callback(undefined, {status: "You said: " + JSON.stringify(context)}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "function", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "handler.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) Alex Ellis 2017. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
"use strict" | ||
|
||
const express = require('express') | ||
const app = express() | ||
const handler = require('./function/handler'); | ||
const bodyParser = require('body-parser') | ||
|
||
// app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.raw()); | ||
app.use(bodyParser.text({ type : "text/*" })); | ||
|
||
var middleware = (req, res) => { | ||
handler(req.body, (err, functionResult) => { | ||
if (err) { | ||
return console.error(err); | ||
} | ||
if(isArray(functionResult) || isObject(functionResult)) { | ||
res.send(JSON.stringify(functionResult)); | ||
} else { | ||
res.send(functionResult); | ||
} | ||
}); | ||
}; | ||
|
||
app.post('/', middleware); | ||
app.get('/', middleware); | ||
|
||
app.listen(3000, () => { | ||
console.log('OpenFaaS Node.js listening on port: 3000') | ||
}); | ||
|
||
let isArray = (a) => { | ||
return (!!a) && (a.constructor === Array); | ||
}; | ||
|
||
let isObject = (a) => { | ||
return (!!a) && (a.constructor === Object); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "node8-express", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"body-parser": "^1.18.2", | ||
"express": "^4.16.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
language: node8-express | ||
fprocess: node index.js |