From 220bdfb7baed67e9273a913a160c47a654dfe2fa Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Tue, 3 Sep 2024 15:28:37 +0100 Subject: [PATCH] Remove node14 template and update watchdogs The newer of-watchdog will stop the "JWT Auth: false" message from appearing when functions start up. The node14 template is available in older commits if you need it for some reason. Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- README.md | 1 - template/bun/Dockerfile | 2 +- template/dockerfile/function/Dockerfile | 2 +- template/java11-vert-x/Dockerfile | 2 +- template/java11/Dockerfile | 2 +- template/node14/.dockerignore | 1 - template/node14/Dockerfile | 62 ---------- template/node14/function/handler.js | 12 -- template/node14/function/package.json | 12 -- template/node14/index.js | 144 ------------------------ template/node14/package.json | 16 --- template/node14/template.yml | 12 -- template/node16/Dockerfile | 2 +- template/node17/Dockerfile | 2 +- template/node18/Dockerfile | 2 +- template/node20/Dockerfile | 2 +- 16 files changed, 8 insertions(+), 268 deletions(-) delete mode 100644 template/node14/.dockerignore delete mode 100644 template/node14/Dockerfile delete mode 100644 template/node14/function/handler.js delete mode 100644 template/node14/function/package.json delete mode 100644 template/node14/index.js delete mode 100644 template/node14/package.json delete mode 100644 template/node14/template.yml diff --git a/README.md b/README.md index dabc6d7e..0f0f6bbf 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,6 @@ See: `faas-cli template store list` to see which templates are both: recommended |:-----|:---------|:--------|:-----------|:---------|:---- | dockerfile | Dockerfile | N/A | Alpine Linux | classic | [Dockerfile template](https://github.com/openfaas/templates/tree/master/template/dockerfile) | go | Go | 1.22 | Alpine Linux | classic | [Legacy Go template (deprecated)](https://github.com/openfaas/templates/tree/master/template/go) -| node14 | NodeJS | 14 | Alpine Linux | of-watchdog | [NodeJS template (deprecated)](https://github.com/openfaas/templates/tree/master/template/node14) | node16 | NodeJS | 16 | Alpine Linux | of-watchdog | [NodeJS template (deprecated)](https://github.com/openfaas/templates/tree/master/template/node16) | node17 | NodeJS | 17 | Alpine Linux | of-watchdog | [NodeJS template (deprecated)](https://github.com/openfaas/templates/tree/master/template/node17) | node18 | NodeJS | 18 | Alpine Linux | of-watchdog | [NodeJS template (deprecated)](https://github.com/openfaas/templates/tree/master/template/node18) diff --git a/template/bun/Dockerfile b/template/bun/Dockerfile index 33b4048f..4de99230 100644 --- a/template/bun/Dockerfile +++ b/template/bun/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/of-watchdog:0.10.5 AS watchdog +FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/of-watchdog:0.10.6 AS watchdog FROM --platform=${TARGETPLATFORM:-linux/amd64} oven/bun:1.0-alpine AS ship ARG TARGETPLATFORM diff --git a/template/dockerfile/function/Dockerfile b/template/dockerfile/function/Dockerfile index 069b77d2..3502e62e 100644 --- a/template/dockerfile/function/Dockerfile +++ b/template/dockerfile/function/Dockerfile @@ -1,6 +1,6 @@ FROM ghcr.io/openfaas/classic-watchdog:0.3.1 AS watchdog -FROM alpine:3.18 +FROM alpine:3.20.2 RUN mkdir -p /home/app diff --git a/template/java11-vert-x/Dockerfile b/template/java11-vert-x/Dockerfile index 75529c46..ee19f4e2 100644 --- a/template/java11-vert-x/Dockerfile +++ b/template/java11-vert-x/Dockerfile @@ -27,7 +27,7 @@ COPY . /home/app/ RUN gradle build -FROM ghcr.io/openfaas/of-watchdog:0.10.5 AS watchdog +FROM ghcr.io/openfaas/of-watchdog:0.10.6 AS watchdog FROM openjdk:11-jre-slim AS ship COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog diff --git a/template/java11/Dockerfile b/template/java11/Dockerfile index 69244d07..e656745a 100644 --- a/template/java11/Dockerfile +++ b/template/java11/Dockerfile @@ -28,7 +28,7 @@ COPY . /home/app/ RUN gradle build RUN find . -FROM ghcr.io/openfaas/of-watchdog:0.10.5 AS watchdog +FROM ghcr.io/openfaas/of-watchdog:0.10.6 AS watchdog FROM openjdk:11-jre-slim AS ship RUN apt-get update -qqy \ diff --git a/template/node14/.dockerignore b/template/node14/.dockerignore deleted file mode 100644 index e84c3fba..00000000 --- a/template/node14/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -*/node_modules diff --git a/template/node14/Dockerfile b/template/node14/Dockerfile deleted file mode 100644 index abe8a985..00000000 --- a/template/node14/Dockerfile +++ /dev/null @@ -1,62 +0,0 @@ -FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/of-watchdog:0.10.5 AS watchdog -FROM --platform=${TARGETPLATFORM:-linux/amd64} node:14-alpine AS ship - -ARG TARGETPLATFORM -ARG BUILDPLATFORM - -COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog -RUN chmod +x /usr/bin/fwatchdog - -RUN apk --no-cache add curl ca-certificates \ - && addgroup -S app && adduser -S -g app app - -# Turn down the verbosity to default level. -ENV NPM_CONFIG_LOGLEVEL warn - -RUN chmod 777 /tmp - -USER app - -RUN mkdir -p /home/app/function - -# 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/ ./ - -# Run any tests that may be available -RUN npm test - -# Set correct permissions to use non root user -WORKDIR /home/app/ - -ENV cgi_headers="true" -ENV fprocess="node index.js" -ENV mode="http" -ENV upstream_url="http://127.0.0.1:3000" - -ENV exec_timeout="10s" -ENV write_timeout="15s" -ENV read_timeout="15s" - -ENV prefix_logs="false" - -HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1 - -CMD ["fwatchdog"] diff --git a/template/node14/function/handler.js b/template/node14/function/handler.js deleted file mode 100644 index 18f543d4..00000000 --- a/template/node14/function/handler.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict' - -module.exports = async (event, context) => { - const result = { - 'body': JSON.stringify(event.body), - 'content-type': event.headers["content-type"] - } - - return context - .status(200) - .succeed(result) -} diff --git a/template/node14/function/package.json b/template/node14/function/package.json deleted file mode 100644 index a3c013b0..00000000 --- a/template/node14/function/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "openfaas-function", - "version": "1.0.0", - "description": "OpenFaaS Function", - "main": "handler.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 0" - }, - "keywords": [], - "author": "OpenFaaS Ltd", - "license": "MIT" -} diff --git a/template/node14/index.js b/template/node14/index.js deleted file mode 100644 index b67e5ede..00000000 --- a/template/node14/index.js +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright (c) Alex Ellis 2021. All rights reserved. -// Copyright (c) OpenFaaS Author(s) 2021. 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') - -const defaultMaxSize = '100kb' // body-parser default - -app.disable('x-powered-by'); - -const rawLimit = process.env.MAX_RAW_SIZE || defaultMaxSize -const jsonLimit = process.env.MAX_JSON_SIZE || defaultMaxSize - -app.use(function addDefaultContentType(req, res, next) { - // When no content-type is given, the body element is set to - // nil, and has been a source of contention for new users. - - if(!req.headers['content-type']) { - req.headers['content-type'] = "text/plain" - } - next() -}) - -if (process.env.RAW_BODY === 'true') { - app.use(bodyParser.raw({ type: '*/*' , limit: rawLimit })) -} else { - app.use(bodyParser.text({ type : "text/*" })); - app.use(bodyParser.json({ limit: jsonLimit})); - app.use(bodyParser.urlencoded({ extended: true })); -} - -const isArray = (a) => { - return (!!a) && (a.constructor === Array); -}; - -const isObject = (a) => { - return (!!a) && (a.constructor === Object); -}; - -class FunctionEvent { - constructor(req) { - this.body = req.body; - this.headers = req.headers; - this.method = req.method; - this.query = req.query; - this.path = req.path; - } -} - -class FunctionContext { - constructor(cb) { - this.statusCode = 200; - this.cb = cb; - this.headerValues = {}; - this.cbCalled = 0; - } - - status(statusCode) { - if(!statusCode) { - return this.statusCode; - } - - this.statusCode = statusCode; - return this; - } - - headers(value) { - if(!value) { - return this.headerValues; - } - - this.headerValues = value; - return this; - } - - succeed(value) { - let err; - this.cbCalled++; - this.cb(err, value); - } - - fail(value) { - let message; - if(this.status() == "200") { - this.status(500) - } - - this.cbCalled++; - this.cb(value, message); - } -} - -const middleware = async (req, res) => { - const cb = (err, functionResult) => { - if (err) { - console.error(err); - - return res.status(fnContext.status()) - .send(err.toString ? err.toString() : err); - } - - if(isArray(functionResult) || isObject(functionResult)) { - res.set(fnContext.headers()) - .status(fnContext.status()).send(JSON.stringify(functionResult)); - } else { - res.set(fnContext.headers()) - .status(fnContext.status()) - .send(functionResult); - } - }; - - const fnEvent = new FunctionEvent(req); - const fnContext = new FunctionContext(cb); - - Promise.resolve(handler(fnEvent, fnContext, cb)) - .then(res => { - if(!fnContext.cbCalled) { - fnContext.succeed(res); - } - }) - .catch(e => { - cb(e); - }); -}; - -app.post('/*', middleware); -app.get('/*', middleware); -app.patch('/*', middleware); -app.put('/*', middleware); -app.delete('/*', middleware); -app.options('/*', middleware); - -const port = process.env.http_port || 3000; - -app.listen(port, () => { - console.log(`node14 listening on port: ${port}`) -}); - - diff --git a/template/node14/package.json b/template/node14/package.json deleted file mode 100644 index b6a45c5e..00000000 --- a/template/node14/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "openfaas-node12", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no tests specified\" && exit 0" - }, - "keywords": [], - "author": "OpenFaaS Ltd", - "license": "MIT", - "dependencies": { - "body-parser": "^1.18.2", - "express": "^4.16.2" - } -} diff --git a/template/node14/template.yml b/template/node14/template.yml deleted file mode 100644 index 5e679016..00000000 --- a/template/node14/template.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: node14 -fprocess: node index.js -welcome_message: | - You have created a new function which uses Node.js 14 and the OpenFaaS - of-watchdog which gives greater control over HTTP responses. - - npm i --save can be used to add third-party packages like request or cheerio - npm documentation: https://docs.npmjs.com/ - - Unit tests are run at build time via "npm run", edit package.json to specify - how you want to execute them. - diff --git a/template/node16/Dockerfile b/template/node16/Dockerfile index 7e367e0b..c6025350 100644 --- a/template/node16/Dockerfile +++ b/template/node16/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/of-watchdog:0.10.5 AS watchdog +FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/of-watchdog:0.10.6 AS watchdog FROM --platform=${TARGETPLATFORM:-linux/amd64} node:16-alpine AS ship ARG TARGETPLATFORM diff --git a/template/node17/Dockerfile b/template/node17/Dockerfile index 4130c690..c21a853d 100644 --- a/template/node17/Dockerfile +++ b/template/node17/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/of-watchdog:0.10.5 AS watchdog +FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/of-watchdog:0.10.6 AS watchdog FROM --platform=${TARGETPLATFORM:-linux/amd64} node:17-alpine AS ship ARG TARGETPLATFORM diff --git a/template/node18/Dockerfile b/template/node18/Dockerfile index 84b98ede..a0b9e27c 100644 --- a/template/node18/Dockerfile +++ b/template/node18/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/of-watchdog:0.10.5 AS watchdog +FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/of-watchdog:0.10.6 AS watchdog FROM --platform=${TARGETPLATFORM:-linux/amd64} node:18-alpine AS ship ARG TARGETPLATFORM diff --git a/template/node20/Dockerfile b/template/node20/Dockerfile index 9de736bd..7e5cfa94 100644 --- a/template/node20/Dockerfile +++ b/template/node20/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/of-watchdog:0.10.5 AS watchdog +FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/of-watchdog:0.10.6 AS watchdog FROM --platform=${TARGETPLATFORM:-linux/amd64} node:20-alpine AS ship ARG TARGETPLATFORM