From 46ff8fc584041023fe1d403b050009c29c284782 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Sat, 6 Jul 2024 21:21:02 -0300 Subject: [PATCH] Express runtime working --- TODO.md | 13 +++++++------ runtimes/express/Dockerfile.j2 | 20 ++++++++++++++++++++ runtimes/express/template/funko.js | 15 +++++++++++++++ runtimes/express/template/funko.yml.j2 | 2 ++ runtimes/express/template/package.json.j2 | 11 +++++++++++ 5 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 runtimes/express/Dockerfile.j2 create mode 100644 runtimes/express/template/funko.js create mode 100644 runtimes/express/template/funko.yml.j2 create mode 100644 runtimes/express/template/package.json.j2 diff --git a/TODO.md b/TODO.md index 93e9033..7c61355 100644 --- a/TODO.md +++ b/TODO.md @@ -8,22 +8,23 @@ * Polish frontend UI **A LOT** * Version checks for consistency between client/server * Have 3 runtimes: - * Crystal + Kemal ✅ - * Python + Flask [WIP] - * Nodejs + Express + * ✅ Crystal + Kemal + * ✅ Python + Flask + * ✅ Nodejs + Express * Document * How to create a runtime * How to create a funko * How to setup the proxy * APIs * Sanitize all inputs -* Streaming responses in slow operations like scaling down +* ✅ Streaming responses in slow operations like scaling down or building * Make more things configurable / remove hardcoded stuff * CD for binaries and images for at least arm64/x86 * Multi-container docker logs [faaso logs -f FUNKO] -* Direct error and above to stderr, others to stdout, while keeping - logging level configurable +* Direct error and above to stderr, others to stdout, while + keeping logging level configurable +* Fix proxy reload / Make it reload on file changes # Things to do but not before release diff --git a/runtimes/express/Dockerfile.j2 b/runtimes/express/Dockerfile.j2 new file mode 100644 index 0000000..b38bf54 --- /dev/null +++ b/runtimes/express/Dockerfile.j2 @@ -0,0 +1,20 @@ +FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine as build + +RUN apk update && apk upgrade && apk add nodejs npm {{ ship_packages | join(" ") }} {{ devel_packages | join(" ") }} && apk cache clean + +WORKDIR /home/app + +COPY ./ ./ +RUN npm i + +FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine as ship +RUN apk update && apk upgrade && apk add nodejs curl {{ ship_packages | join " " }} && apk cache clean +RUN addgroup -S app && adduser app -S -G app + +WORKDIR /home/app +USER app + +COPY --from=build /home/app/ . + +CMD ["node", "funko.js"] +HEALTHCHECK {{ healthcheck_options }} CMD {{ healthcheck_command }} \ No newline at end of file diff --git a/runtimes/express/template/funko.js b/runtimes/express/template/funko.js new file mode 100644 index 0000000..2ec5a86 --- /dev/null +++ b/runtimes/express/template/funko.js @@ -0,0 +1,15 @@ +const express = require('express') +const app = express() +const port = 3000 + +app.get('/', (req, res) => { + res.send('Hello World!') +}) + +app.get('/ping', (req, res) => { + res.send('OK') +}) + +app.listen(port, () => { + console.log(`Example funko listening on port ${port}`) +}) \ No newline at end of file diff --git a/runtimes/express/template/funko.yml.j2 b/runtimes/express/template/funko.yml.j2 new file mode 100644 index 0000000..0ab03ef --- /dev/null +++ b/runtimes/express/template/funko.yml.j2 @@ -0,0 +1,2 @@ +name: {{ name }} +runtime: {{ runtime }} diff --git a/runtimes/express/template/package.json.j2 b/runtimes/express/template/package.json.j2 new file mode 100644 index 0000000..993f60e --- /dev/null +++ b/runtimes/express/template/package.json.j2 @@ -0,0 +1,11 @@ +{ + "name": "{{name}}", + "version": "1.0.0", + "main": "funko.js", + "author": "", + "license": "MIT", + "description": "Example Funko", + "dependencies": { + "express": "^4.19.2" + } +}