-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: emissions example; cp sandbox setup from tryorama * fix: emit fake co2 measure every second * chore: split sandbox tools into separate package * chore: rm unused external deps * feat: expose composable sandbox setup functions * chore: tidy * chore: tidy * chore: tidy scripts
- Loading branch information
Showing
16 changed files
with
547 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# We use ubuntu as it's glibc version is compatible with the prebuilt binaries | ||
FROM ubuntu | ||
|
||
RUN apt-get update && apt-get install -y wget | ||
|
||
# Install node v20.12.2 | ||
ENV NVM_DIR /usr/local/nvm | ||
ENV NODE_VERSION v20.12.2 | ||
RUN mkdir -p $NVM_DIR && wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash | ||
RUN /bin/bash -c "source $NVM_DIR/nvm.sh && nvm install $NODE_VERSION && nvm use --delete-prefix $NODE_VERSION" | ||
ENV NODE_PATH $NVM_DIR/versions/node/$NODE_VERSION/bin | ||
ENV PATH $NODE_PATH:$PATH | ||
|
||
# Install prebuilt holochain binaries | ||
RUN wget -nv https://github.com/holochain/holochain/releases/download/holochain-0.4.0-dev.20/hc-x86_64-linux \ | ||
-O /usr/local/bin/hc | ||
RUN wget -nv https://github.com/holochain/holochain/releases/download/holochain-0.4.0-dev.20/holochain-x86_64-linux \ | ||
-O /usr/local/bin/holochain | ||
RUN wget -nv https://github.com/holochain/holochain/releases/download/holochain-0.4.0-dev.20/lair-keystore-x86_64-linux \ | ||
-O /usr/local/bin/lair-keystore | ||
RUN chmod 755 /usr/local/bin/hc /usr/local/bin/holochain /usr/local/bin/lair-keystore | ||
|
||
# Install tsx | ||
WORKDIR /home/node | ||
RUN /bin/bash -c "source $NVM_DIR/nvm.sh && npm i tsx" | ||
|
||
# Copy the actual server script | ||
COPY ./co2-sensor.ts ./co2-sensor.ts | ||
|
||
# So container runs with nvm loaded | ||
SHELL ["/bin/bash", "--login", "-c"] | ||
|
||
# The ./packages directory is mounted from the locally built npm workspace. We | ||
# npm install at launch to avoid the need for the package.json to know the | ||
# latest version or features of the workspace. | ||
CMD npm install ./packages/types ./packages/sandbox; npx tsx ./co2-sensor.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* A mock CO₂ sensor, that emits a random measure in grams roughly every 2 | ||
* seconds. The "measurements" are published by a sandboxed holochain agent | ||
* that serves no other role in the network. | ||
*/ | ||
|
||
import { ensureAndConnectToHapp } from "@holoom/sandbox"; | ||
import { UsernameRegistryCoordinator } from "@holoom/types"; | ||
|
||
async function main() { | ||
// Create a conductor sandbox (with holoom installed) at the specified | ||
// directory if it doesn't already exist, and connect to it. | ||
const { appWs } = await ensureAndConnectToHapp( | ||
"/sandbox", | ||
"/workdir/holoom.happ", | ||
"emissions-local-test-2024-09-04T12:59", | ||
{ | ||
bootstrapServerUrl: new URL("https://bootstrap-0.infra.holochain.org"), | ||
signalingServerUrl: new URL("wss://sbd-0.main.infra.holo.host"), | ||
password: "password", | ||
} | ||
); | ||
const usernameRegistryCoordinator = new UsernameRegistryCoordinator(appWs); | ||
|
||
setInterval(() => publishMeasurement(usernameRegistryCoordinator), 1_000); | ||
} | ||
|
||
async function publishMeasurement( | ||
usernameRegistryCoordinator: UsernameRegistryCoordinator | ||
) { | ||
const time = Math.floor(Date.now() / 1000); | ||
const name = `co2-sensor/time/${time}`; | ||
|
||
// A pretend measure of detected CO₂ | ||
const gramsCo2 = Math.floor(Math.random() * 1000); | ||
try { | ||
await usernameRegistryCoordinator.createOracleDocument({ | ||
name, | ||
json_data: JSON.stringify({ time, gramsCo2 }), | ||
}); | ||
console.log("Published", time, gramsCo2); | ||
} catch (err) { | ||
console.error("Failed to publish reading with error:", err); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
services: | ||
|
||
co2-sensor: | ||
build: ./co2-sensor | ||
volumes: | ||
- ../../packages:/home/node/packages | ||
- ../../workdir:/workdir |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["src", "rollup.node.config.ts", "rollup.browser.config.ts"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# @holoom/authority | ||
|
||
Helpers for creating and connecting to a holochain sandbox with holoom installed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"declarationDir": "dist/types" | ||
}, | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"name": "@holoom/sandbox", | ||
"version": "0.1.0-dev.13", | ||
"description": "Helpers for starting a holochain sandbox with holoom installed", | ||
"type": "module", | ||
"license": "MIT", | ||
"types": "dist/types/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/types/index.d.ts", | ||
"node": { | ||
"require": "./dist/index.node.cjs", | ||
"default": "./dist/index.node.js" | ||
} | ||
} | ||
}, | ||
"files": [ | ||
"dist/", | ||
"src/", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"repository": "https://github.com/holochain-open-dev/holoom", | ||
"homepage": "https://github.com/holochain-open-dev/holoom/tree/main/packages/sandbox", | ||
"bugs": { | ||
"url": "https://github.com/holochain-open-dev/holoom.git/issues" | ||
}, | ||
"scripts": { | ||
"build": "rimraf dist && npm run build:node", | ||
"build:node": "rollup -c rollup.node.config.ts --configPlugin typescript" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-alias": "^5.1.0", | ||
"@rollup/plugin-json": "^6.1.0", | ||
"@rollup/plugin-typescript": "^11.1.6", | ||
"@types/ws": "^8.5.10", | ||
"rimraf": "^5.0.5", | ||
"rollup": "^4.12.0", | ||
"rollup-plugin-cleanup": "^3.2.1" | ||
}, | ||
"dependencies": { | ||
"@holochain/client": "^0.18.0-dev", | ||
"yaml": "^2.5.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import json from "@rollup/plugin-json"; | ||
import typescript from "@rollup/plugin-typescript"; | ||
import * as fs from "fs"; | ||
import cleanup from "rollup-plugin-cleanup"; | ||
import { RollupOptions } from "rollup"; | ||
|
||
const pkg = JSON.parse(fs.readFileSync("./package.json", "utf-8")); | ||
const banner = `/** | ||
* @module ${pkg.name} | ||
* @version ${pkg.version} | ||
* @file ${pkg.description} | ||
* @license ${pkg.license} | ||
* @see [Github]{@link ${pkg.homepage}} | ||
*/`; | ||
|
||
const config: RollupOptions = { | ||
input: "src/index.ts", | ||
output: [ | ||
{ | ||
file: pkg.exports["."].node.require, | ||
format: "cjs", | ||
banner, | ||
exports: "auto", | ||
}, | ||
{ | ||
file: pkg.exports["."].node.default, | ||
format: "es", | ||
banner, | ||
}, | ||
], | ||
external: [ | ||
...Object.keys(pkg.dependencies), | ||
"node:fs/promises", | ||
"node:child_process", | ||
], | ||
plugins: [ | ||
typescript({ | ||
tsconfig: "./build.tsconfig.json", | ||
}), | ||
cleanup({ comments: "jsdoc" }), | ||
json(), | ||
], | ||
onwarn: (warning) => { | ||
throw new Error(warning.message); | ||
}, | ||
}; | ||
|
||
export default config; |
Oops, something went wrong.