Skip to content

Commit

Permalink
feat(interop): add js-libp2p v0.44
Browse files Browse the repository at this point in the history
Copy of `multidim-interop/impl/js/v0.42` plus version adjustments + reenable
WebRTC (see libp2p#160).
  • Loading branch information
mxinden committed Apr 25, 2023
1 parent d17c40e commit 5a638ff
Show file tree
Hide file tree
Showing 12 changed files with 42,919 additions and 0 deletions.
82 changes: 82 additions & 0 deletions multidim-interop/impl/js/v0.44/.aegir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { createClient } from 'redis'
import http from "http"

const redis_addr = process.env.redis_addr || 'redis:6379'

/** @type {import('aegir/types').PartialOptions} */
export default {
test: {
browser: {
config: {
// Ignore self signed certificates
browserContextOptions: { ignoreHTTPSErrors: true }
}
},
async before() {
const redisClient = createClient({
url: `redis://${redis_addr}`
})
redisClient.on('error', (err) => console.error(`Redis Client Error: ${err}`))
await redisClient.connect()

const requestListener = async function (req, res) {
const requestJSON = await new Promise(resolve => {
let body = ""
req.on('data', function (data) {
body += data;
});

req.on('end', function () {
resolve(JSON.parse(body))
});
})

try {
const redisRes = await redisClient.sendCommand(requestJSON)
if (redisRes === null) {
throw new Error("redis sent back null")
}

res.writeHead(200, {
'Access-Control-Allow-Origin': '*'
})
res.end(JSON.stringify(redisRes))
} catch (err) {
console.error("Error in redis command:", err)
res.writeHead(500, {
'Access-Control-Allow-Origin': '*'
})
res.end(err.toString())
return
}


};

const proxyServer = http.createServer(requestListener);
await new Promise(resolve => { proxyServer.listen(0, "localhost", () => { resolve() }); })

return {
redisClient,
proxyServer: proxyServer,
env: {
...process.env,
proxyPort: proxyServer.address().port
}
}
},
async after(_, { proxyServer, redisClient }) {
await new Promise(resolve => {
proxyServer.close(() => resolve());
})

try {
// We don't care if this fails
await redisClient.disconnect()
} catch { }
}
},
build: {
bundlesizeMax: '18kB'
}
}
1 change: 1 addition & 0 deletions multidim-interop/impl/js/v0.44/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
3 changes: 3 additions & 0 deletions multidim-interop/impl/js/v0.44/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
node-image.json
chromium-image.json
6 changes: 6 additions & 0 deletions multidim-interop/impl/js/v0.44/ChromiumDockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# syntax=docker/dockerfile:1

ARG BASE_IMAGE
FROM $BASE_IMAGE

ENTRYPOINT [ "npm", "test", "--", "--build", "false", "--types", "false", "-t", "browser" ]
21 changes: 21 additions & 0 deletions multidim-interop/impl/js/v0.44/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# syntax=docker/dockerfile:1
# Using playwright so that we have the same base across NodeJS + Browser tests
FROM mcr.microsoft.com/playwright

WORKDIR /app

COPY package*.json ./

RUN npm ci

# Install browsers, Needed for the browser tests, but we do it here so we have the same base
RUN ./node_modules/.bin/playwright install

COPY tsconfig.json .
COPY .aegir.js .
COPY test ./test
COPY src ./src

RUN npm run build

ENTRYPOINT [ "npm", "test", "--", "--build", "false", "--types", "false", "-t", "node" ]
23 changes: 23 additions & 0 deletions multidim-interop/impl/js/v0.44/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
image_name := js-v0.42
TEST_SOURCES := $(wildcard test/*.ts)

all: chromium-image.json node-image.json

chromium-image.json: node-image.json
docker build -t chromium-${image_name} -f ChromiumDockerfile --build-arg="BASE_IMAGE=node-${image_name}" .
docker image inspect chromium-${image_name} -f "{{.Id}}" | \
xargs -I {} echo "{\"imageID\": \"{}\"}" > $@

node-image.json: image.json
docker image tag $$(cat image.json | jq -r '.imageID') node-${image_name}
cp image.json node-image.json

image.json: Dockerfile $(TEST_SOURCES) package.json package-lock.json .aegir.js
IMAGE_NAME=node-${image_name} ../../../dockerBuildWrapper.sh -f Dockerfile .
docker image inspect node-${image_name} -f "{{.Id}}" | \
xargs -I {} echo "{\"imageID\": \"{}\"}" > $@

.PHONY: clean

clean:
rm *image.json
Loading

0 comments on commit 5a638ff

Please sign in to comment.