Skip to content

Commit ec32e68

Browse files
authored
Merge pull request #9 from fahamutech/joshua
Joshua
2 parents 7cf9e8e + 382f8aa commit ec32e68

File tree

12 files changed

+328
-328
lines changed

12 files changed

+328
-328
lines changed

.dockerignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ node_modules
33
specs
44
.env
55
.gitignore
6-
Dockerfile
6+
.github
77
gulpfile.js
88
README.md
9-
src/function/myF
9+
src/function/myF
10+
/BFastFunctionExample.git
11+
BFastFunctionExample.git
12+
.npmrc
13+
src/function/myF

.idea/dictionaries/joshua.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 107 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ WORKDIR /faas
44

55
RUN apk update
66
RUN apk upgrade
7-
# RUN apk add unzip
87
RUN apk add curl
98
RUN apk add git
9+
RUN apk add bash
1010

11-
# RUN curl -L https://github.com/fahamutech/BFastFunction/archive/v1.4.10.zip > /tmp/app.zip && unzip /tmp/app.zip -d /faas
12-
13-
# RUN cp -r /faas/BFastFunction-1.4.10/* /faas
14-
# RUN rm -r /faas/BFastFunction-1.4.10
1511
COPY *.json ./
1612
RUN npm ci --only=production
17-
# RUN apk del unzip
18-
# RUN rm /tmp/app.zip
13+
14+
COPY ./docker-entrypoint.sh /usr/local/bin/
15+
RUN ln -s /usr/local/bin/docker-entrypoint.sh / # backwards compat
1916

2017
COPY . ./
2118

22-
CMD [ "npm","run","start" ]
19+
#RUN ls /usr/local/bin
20+
21+
RUN ["chmod", "+x", "/usr/local/bin/docker-entrypoint.sh"]
22+
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
23+
#CMD [ "npm run start" ]

docker-entrypoint.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
set -e
3+
4+
#if [ "$1" = 'npm run start' ]; then
5+
6+
rm -r /faas/src/function/myF || echo "continue..."
7+
# git clone "${GIT_CLONE_URL}" /faas/src/function/myF
8+
#
9+
# if [ -z "${GIT_TOKEN}" ]; then
10+
# git clone "${GIT_CLONE_URL}" /faas/src/function/myF
11+
# fi
12+
#
13+
# if [ -z "$(ls -A "$PGDATA")" ]; then
14+
# gosu postgres initdb
15+
# fi
16+
#
17+
# exec gosu postgres "$@"
18+
#fi
19+
20+
exec npm run start "$@"

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bfastfunction",
3-
"version": "1.7.2",
3+
"version": "1.8.0",
44
"private": true,
55
"scripts": {
66
"start": "node src/index.js",
@@ -19,8 +19,7 @@
1919
"express-http-proxy": "^1.6.0",
2020
"glob": "^7.1.4",
2121
"isomorphic-git": "^0.67.2",
22-
"morgan": "~1.9.1",
23-
"pm2": "^4.1.2"
22+
"morgan": "~1.9.1"
2423
},
2524
"devDependencies": {
2625
"chai": "^4.2.0",

src/controller/FaaSController.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const glob = require('glob');
44

5-
module.exports.FaaSController = class {
5+
class FaaSController {
66

77
/**
88
* get function from uploaded files. This function return an object which contain name of function as object property
@@ -16,24 +16,34 @@ module.exports.FaaSController = class {
1616
getFunctions() {
1717
return new Promise((resolve, reject) => {
1818
try {
19+
const bfastConfig = require('../function/myF/bfast.json');
20+
// console.log(bfastConfig);
21+
// console.log(bfastConfig && bfastConfig.ignore && Array.isArray(bfastConfig.ignore));
1922
glob(`${__dirname}/../function/**/*.js`, {
2023
// cwd: path.join(__dirname, `../function/`),
2124
absolute: true,
22-
ignore: ['**/node_modules/**', '**/specs/**', '**/*.specs.js']
25+
ignore: bfastConfig && bfastConfig.ignore && Array.isArray(bfastConfig.ignore) ?
26+
bfastConfig.ignore :
27+
['**/node_modules/**', '**/specs/**', '**/*.specs.js']
2328
}, (err, files) => {
2429
if (err) {
2530
reject({message: err});
2631
}
2732
let functions = {
28-
mambo: function (req, response) {
29-
response.json({message: 'Powa!'});
33+
mambo: {
34+
onRequest: function (req, response) {
35+
response.json({message: 'Powa!'});
36+
}
3037
}
3138
};
3239
files.forEach(file => {
3340
const fileModule = require(file);
3441
const functionNames = Object.keys(fileModule);
3542
functionNames.forEach(name => {
36-
functions[name] = fileModule[name];
43+
if (fileModule[name] && typeof fileModule[name] === "object"
44+
&& fileModule[name].onRequest) {
45+
functions[name] = fileModule[name];
46+
}
3747
});
3848
});
3949
resolve(functions);
@@ -52,9 +62,14 @@ module.exports.FaaSController = class {
5262
getNames() {
5363
return new Promise(((resolve, reject) => {
5464
try {
65+
const bfastConfig = require('../function/myF/bfast.json');
66+
// console.log(bfastConfig);
67+
// console.log(bfastConfig && bfastConfig.ignore && Array.isArray(bfastConfig.ignore));
5568
const names = [];
5669
glob(`${__dirname}/../function/**/*.js`, {
57-
ignore: ['**/node_modules/**', '**/specs/**', '**/*.specs.js']
70+
ignore: bfastConfig && bfastConfig.ignore && Array.isArray(bfastConfig.ignore) ?
71+
bfastConfig.ignore :
72+
['**/node_modules/**', '**/specs/**', '**/*.specs.js']
5873
}, (err, files) => {
5974
if (err) {
6075
reject({message: err});
@@ -63,7 +78,10 @@ module.exports.FaaSController = class {
6378
const fileModule = require(file);
6479
const functionNames = Object.keys(fileModule);
6580
functionNames.forEach(name => {
66-
names.push(name);
81+
if (fileModule[name] && typeof fileModule[name] === "object"
82+
&& fileModule[name].onRequest) {
83+
names.push(name);
84+
}
6785
});
6886
});
6987
resolve({names: names});
@@ -74,4 +92,6 @@ module.exports.FaaSController = class {
7492
}));
7593
}
7694

77-
};
95+
}
96+
97+
module.exports = FaaSController;

0 commit comments

Comments
 (0)