Skip to content

Commit

Permalink
Merge pull request #1414 from MAIF/wasm
Browse files Browse the repository at this point in the history
Add support for wasm plugins in a route
  • Loading branch information
mathieuancelin committed Feb 16, 2023
2 parents 979c3bc + 41d0e1e commit bbfa369
Show file tree
Hide file tree
Showing 82 changed files with 37,410 additions and 84 deletions.
2 changes: 2 additions & 0 deletions demos/wasm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This folder is used by the Otoroshi tutorials

3 changes: 3 additions & 0 deletions experiments/otoroshi-wasm-manager/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ui/node_modules
**/node_modules
server/node_modules
5 changes: 5 additions & 0 deletions experiments/otoroshi-wasm-manager/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
yarn.lock
server/node_modules
ui/node_modules
server/.env
42 changes: 42 additions & 0 deletions experiments/otoroshi-wasm-manager/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from ubuntu:20.04

WORKDIR /code

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update -y
RUN apt-get install -y build-essential git curl
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash
RUN apt-get install -y nodejs && apt-get install -y --no-install-recommends tzdata && apt-get install -y python3.9-distutils python3.9 python3.9-dev
RUN apt-get install python3.9-distutils

# RUN python3.9 -m pip install --upgrade pip
RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python3.9 get-pip.py
RUN echo 'export PATH=~/.local/bin/:$PATH' >> ~/.bashrc

RUN pip3 install poetry git+https://github.com/extism/cli
RUN extism install latest

# Get rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

ENV PATH="/root/.cargo/bin:${PATH}"
# Add wasm-unknown-unknown target
RUN rustup target add wasm32-unknown-unknown

ADD ui $HOME/ui
ADD server $HOME/server

# install ui
WORKDIR $HOME/ui
RUN npm install
RUN npm run build
RUN rm -rf node_modules

WORKDIR $HOME/server
RUN npm install

EXPOSE 5001
CMD ["node", "index.js"]


36 changes: 36 additions & 0 deletions experiments/otoroshi-wasm-manager/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

LOCATION=`pwd`

cleanup () {
rm -rf ./node_modules
}

build () {
docker build --no-cache -t otoroshi-wasm-manager .
docker tag otoroshi-wasm-manager "maif/otoroshi-wasm-manager:$1"
docker tag otoroshi-wasm-manager "maif/otoroshi-wasm-manager:latest"
}

echo "Docker images for otoroshi-wasm-manager version $2"

case "${1}" in
cleanup)
cleanup
;;
build)
cleanup
build $2
;;
push-all)
cleanup
build $2
docker push "maif/otoroshi-wasm-manager:$2"
docker push "maif/otoroshi-wasm-manager:latest"
;;
*)
echo "Build otoroshi-wasm-manager docker images"
;;
esac

exit ${?}
Empty file.
62 changes: 62 additions & 0 deletions experiments/otoroshi-wasm-manager/server/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require('dotenv').config();

const express = require('express');
const http = require('http');
const compression = require('compression');
const bodyParser = require('body-parser');
const path = require('path');
const { S3 } = require('./s3');
const swaggerUi = require('swagger-ui-express');

const swaggerDocument = require('./swagger.json');
swaggerDocument.servers = (process.env.MANAGER_EXPOSED_DOMAINS || []).split(',').map(url => ({ url }))

const pluginsRouter = require('./routers/plugins');
const templatesRouter = require('./routers/templates');
const publicRouter = require('./routers/public');
const wasmRouter = require('./routers/wasm');
const { WebSocket } = require('./services/websocket');

const manager = require('./logger');
const log = manager.createLogger('wasm-manager');

const { Security } = require('./security/middlewares');
const { BuildingJob } = require('./services/building-job');

S3.initializeS3Connection()
.then(() => {
BuildingJob.start();

S3.createBucketIfMissing();
// S3.cleanBucket()
// S3.listObjects()

const app = express();
app.use(express.static(path.join(__dirname, '..', 'ui/build')));
app.use(compression());
app.use(bodyParser.raw({
type: 'application/octet-stream',
limit: '10mb'
}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.text());

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));

app.use('/', Security.extractUserFromQuery);
app.use('/api/plugins', pluginsRouter);
app.use('/api/templates', templatesRouter);
app.use('/api/wasm', wasmRouter);

app.use('/', publicRouter);
app.get('/', (_, res) => res.sendFile(path.join(__dirname, '..', 'ui/build', '/index.html')));

const server = http.createServer(app);

WebSocket.createLogsWebSocket(server);

const PORT = process.env.MANAGER_PORT || 5001;

server.listen(PORT, () => log.info(`listening on ${PORT}`));
})
4 changes: 4 additions & 0 deletions experiments/otoroshi-wasm-manager/server/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const manager = require('simple-node-logger')
.createLogManager();

module.exports = manager;
Empty file.

0 comments on commit bbfa369

Please sign in to comment.