Skip to content

Commit

Permalink
chore(docker): update configuration and optimize build process
Browse files Browse the repository at this point in the history
  • Loading branch information
fedosov committed Jul 9, 2024
1 parent 70205fc commit 16ae6b3
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
data/
target/
.git/
node_modules/

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# md book build directory
book
/db/
data/

# MacOS thing
**/.DS_Store
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.override.yml.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.9"

services:
node:
environment:
Expand Down
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.9"

services:
miner:
container_name: "miner"
Expand All @@ -15,7 +13,7 @@ services:
context: .
dockerfile: docker/node.Dockerfile
volumes:
- /var/chain
- ./data/chain:/var/chain
ports:
- "0.0.0.0:9944:9944"
- "0.0.0.0:9933:9933"
Expand Down
5 changes: 3 additions & 2 deletions docker/miner.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ FROM node:latest

WORKDIR /app

COPY ./miner-libs/ .
COPY ./package.json .
COPY ./pnpm-lock.yaml .
COPY ./miner.js .

RUN corepack enable && \
corepack prepare pnpm@latest --activate && \
pnpm install

COPY ./miner-libs/ ./miner-libs/
COPY ./miner.js .

CMD ["pnpm", "miner", "--host", "node"]
5 changes: 3 additions & 2 deletions docker/node.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FROM rust:1.60 as builder
FROM rust:1.71 AS builder
WORKDIR /app
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libclang-dev cmake
RUN rustup update nightly && \
rustup target add wasm32-unknown-unknown --toolchain nightly
rustup default nightly-2023-05-05 && \
rustup target add wasm32-unknown-unknown --toolchain nightly-2023-05-05
ADD . ./
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
Expand Down
6 changes: 4 additions & 2 deletions docker/node.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash
./p3d import-mining-key "$MEMO_SEED" --base-path /var/chain --chain mainnetSpecRaw.json
./p3d --unsafe-ws-external --unsafe-rpc-external --rpc-cors=all --no-mdns \
--validator --base-path /var/chain --author "$ADDRESS"
GRANDPA_KEY="$(./p3d key inspect --scheme Ed25519 "$MEMO_SEED" | sed -n 's/.*Secret seed://p')"
./p3d key insert --base-path /var/chain --chain mainnetSpecRaw.json --scheme Ed25519 --key-type gran --suri $GRANDPA_KEY
./p3d --chain mainnetSpecRaw.json --unsafe-ws-external --unsafe-rpc-external --rpc-cors=all --no-mdns \
--threads 8 --validator --base-path /var/chain --author "$ADDRESS" --name MyNodeName --telemetry-url "wss://submit.telemetry.3dpscan.io/submit 0"
18 changes: 16 additions & 2 deletions miner.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const do_save = argv.save || false;
const apiUrl = `http://${host}:${port}`;
const filename = "rock.obj";

let interval = 3000;
const MIN_INTERVAL = 100;
const MAX_INTERVAL = 10000;
const ADJUSTMENT_PERCENT = 10;

let exporterModule;
let exporter;

Expand Down Expand Up @@ -45,8 +50,17 @@ async function mining(do_save) {
.catch((e) => {
console.log(e.toString());
})
.then(() => {
mining();
.then((res) => {
// example result: { jsonrpc: '2.0', result: 0, id: 1 }
// Adjust interval based on result
if (res && res.result === 0) {
interval = Math.max(MIN_INTERVAL, Math.round(interval * (1 - ADJUSTMENT_PERCENT / 100)));
console.log(`Decreased interval to ${interval}ms`);
} else if (res && res.result === 1) {
interval = Math.min(MAX_INTERVAL, Math.round(interval * (1 + ADJUSTMENT_PERCENT / 100)));
console.log(`Increased interval to ${interval}ms`);
}
setTimeout(() => mining(), interval);
});
}

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"repository": "https://github.com/3Dpass/pass3d",
"license": "MIT",
"type": "commonjs",
"scripts": {
"miner": "node miner.js"
},
"devDependencies": {
"prettier": "2.8.8"
},
Expand Down

0 comments on commit 16ae6b3

Please sign in to comment.