Skip to content

Commit

Permalink
chore: tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
8e8b2c committed Sep 6, 2024
1 parent f65474a commit 817ebed
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 24 deletions.
18 changes: 14 additions & 4 deletions examples/emissions/co2-sensor/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# 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 /usr/local/nvm && apt-get update && echo "y" | apt-get install curl
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
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 \
Expand All @@ -18,9 +20,17 @@ RUN wget -nv https://github.com/holochain/holochain/releases/download/holochain-
-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
COPY ./package.json ./package.json
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"]
CMD npm install ./packages/types ./packages/sandbox; npm start

# 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
13 changes: 0 additions & 13 deletions examples/emissions/co2-sensor/package.json

This file was deleted.

11 changes: 7 additions & 4 deletions packages/authority/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
"description": "Helpers for interacting with a holoom network authority agent",
"type": "module",
"license": "MIT",
"main": "dist/index.browser.js",
"types": "dist/types/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"node": {
"require": "./dist/index.node.cjs",
"default": "./dist/index.node.js"
}
},
"browser": "./dist/index.browser.js",
"default": "./dist/index.browser.js"
}
},
"files": [
Expand All @@ -26,7 +29,8 @@
"url": "https://github.com/holochain-open-dev/holoom.git/issues"
},
"scripts": {
"build": "rimraf dist && npm run build:node",
"build": "rimraf dist && npm run build:browser && npm run build:node",
"build:browser": "rollup -c rollup.browser.config.ts --configPlugin typescript",
"build:node": "rollup -c rollup.node.config.ts --configPlugin typescript"
},
"publishConfig": {
Expand All @@ -51,7 +55,6 @@
"bs58": "^4.0.1",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"viem": "^2.8.13",
"yaml": "^2.5.1"
"viem": "^2.8.13"
}
}
38 changes: 38 additions & 0 deletions packages/authority/rollup.browser.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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["."].browser,
format: "es",
banner,
},
],
external: [...Object.keys(pkg.dependencies), "viem/accounts"],
plugins: [
typescript({
tsconfig: "./build.tsconfig.json",
}),
cleanup({ comments: "jsdoc" }),
json(),
],
onwarn: (warning) => {
throw new Error(warning.message);
},
};

export default config;
2 changes: 1 addition & 1 deletion packages/authority/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["src", "rollup.node.config.ts"]
"include": ["src", "rollup.node.config.ts", "rollup.browser.config.ts"]
}
28 changes: 26 additions & 2 deletions packages/sandbox/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ export interface SandboxOptions {
password: string;
}

/**
* Creates a sandbox by invoking `hc sandbox create` at the specified directory
* if the directory doesn't already exist.
*
* @param path The directory of the conductor sandbox
* @param options Configuration for the sandbox
*/
export async function ensureSandbox(path: string, options: SandboxOptions) {
const exists = await fs
.stat(path)
Expand All @@ -18,6 +25,13 @@ export async function ensureSandbox(path: string, options: SandboxOptions) {
}
}

/**
* Creates a sandbox by invoking `hc sandbox create` at the specified
* directory.
*
* @param path The directory of the conductor sandbox
* @param options Configuration for the sandbox
*/
export async function createSandbox(path: string, options: SandboxOptions) {
const pathComps = path.split("/");
const sandboxDirName = pathComps.pop();
Expand Down Expand Up @@ -81,6 +95,14 @@ export async function createSandbox(path: string, options: SandboxOptions) {
await fs.writeFile(conductorConfigPath, yaml.stringify(conductorConfig));
}

/**
* Starts the sandbox's conductor
*
* @param path The path to the sandbox
* @param password The password on the sandbox
* @returns A handle on the conductor process and the conductor's admin API
* websocket url
*/
export async function startSandbox(
path: string,
password: string
Expand Down Expand Up @@ -124,11 +146,13 @@ export async function startSandbox(
return { process, adminApiUrl: new URL(`http://localhost:${adminPort}`) };
}

/**
* Shuts down the given conductor process.
* @param process The conductor process
*/
export async function endSandboxProcess(
process: ChildProcessWithoutNullStreams
) {
console.debug("closing admin and app web sockets\n");

console.debug("shutting down conductor\n");
const conductorShutDown = new Promise<number | null>((resolve) => {
process.on("exit", (code) => {
Expand Down

0 comments on commit 817ebed

Please sign in to comment.