@le-space/rootfs 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/contract.ts
2
+ import { existsSync } from "fs";
2
3
  import { readFile } from "fs/promises";
3
4
  import { fileURLToPath } from "url";
4
5
  function asObject(value) {
@@ -132,14 +133,27 @@ function contractShellEnv(contract, contractPath = "") {
132
133
  ROOTFS_CONTRACT_PORT_FORWARDS_JSON: JSON.stringify(contract.ports)
133
134
  };
134
135
  }
136
+ function resolveReferencePath(profile, suffix = "") {
137
+ const candidates = [
138
+ new URL(`../reference/${profile}/${suffix}`, import.meta.url),
139
+ new URL(`./reference/${profile}/${suffix}`, import.meta.url)
140
+ ];
141
+ for (const candidate of candidates) {
142
+ const resolved = fileURLToPath(candidate);
143
+ if (existsSync(resolved)) {
144
+ return resolved;
145
+ }
146
+ }
147
+ return fileURLToPath(candidates[0]);
148
+ }
135
149
  function referenceProfileRoot(profile) {
136
- return fileURLToPath(new URL(`../reference/${profile}/`, import.meta.url));
150
+ return resolveReferencePath(profile);
137
151
  }
138
152
  function referenceProfileContractPath(profile) {
139
- return fileURLToPath(new URL(`../reference/${profile}/contract.json`, import.meta.url));
153
+ return resolveReferencePath(profile, "contract.json");
140
154
  }
141
155
  function referenceProfileRootfsDir(profile) {
142
- return fileURLToPath(new URL(`../reference/${profile}/rootfs/`, import.meta.url));
156
+ return resolveReferencePath(profile, "rootfs/");
143
157
  }
144
158
 
145
159
  // src/build-plan.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/rootfs",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Shared rootfs contract parsing, reference profile assets, and build helpers.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -0,0 +1,58 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "uc-go-peer",
4
+ "displayName": "Universal Connectivity Go Relay",
5
+ "source": {
6
+ "repository": "self",
7
+ "subdirectory": "go-peer"
8
+ },
9
+ "rootfs": {
10
+ "profile": "uc-go-peer",
11
+ "installMode": "prebaked",
12
+ "installDir": "/opt/go-peer",
13
+ "binaryPath": "/usr/local/bin/universal-chat-go",
14
+ "dataDir": "/var/lib/uc-go-peer",
15
+ "envFile": "/etc/default/uc-go-peer"
16
+ },
17
+ "services": {
18
+ "bootstrap": "uc-go-peer-bootstrap.service",
19
+ "main": "uc-go-peer.service",
20
+ "autotlsRefresh": "uc-go-peer-autotls-refresh.service"
21
+ },
22
+ "ports": [
23
+ {
24
+ "port": 22,
25
+ "tcp": true,
26
+ "udp": false,
27
+ "purpose": "SSH"
28
+ },
29
+ {
30
+ "port": 80,
31
+ "tcp": true,
32
+ "udp": false,
33
+ "purpose": "Temporary setup endpoint"
34
+ },
35
+ {
36
+ "port": 443,
37
+ "tcp": true,
38
+ "udp": false,
39
+ "purpose": "Caddy HTTPS and WSS proxy"
40
+ },
41
+ {
42
+ "port": 9097,
43
+ "tcp": true,
44
+ "udp": false,
45
+ "purpose": "libp2p secure websocket listener"
46
+ },
47
+ {
48
+ "port": 9095,
49
+ "tcp": true,
50
+ "udp": true,
51
+ "purpose": "libp2p raw TCP and UDP transports"
52
+ }
53
+ ],
54
+ "manifest": {
55
+ "copyTarget": "js-peer/public/rootfs/uc-go-peer/latest.json",
56
+ "notes": "The go-peer image keeps the raw relay on internal port 9095, uses an internal plain websocket backend on 9096 for Caddy, exposes a dedicated internal secure websocket listener on 9097 for AutoTLS/direct WSS, advertises the actual Aleph host port mappings for direct TCP/UDP and AutoTLS websocket transports after deployment, and can optionally add a proxy-backed secure WebSocket address on port 443 via Caddy."
57
+ }
58
+ }
@@ -0,0 +1,24 @@
1
+ FROM debian:12
2
+
3
+ ENV DEBIAN_FRONTEND=noninteractive
4
+ ENV LIBGUESTFS_BACKEND=direct
5
+ ARG GO_VERSION=1.25.4
6
+ ENV PATH=/usr/local/go/bin:${PATH}
7
+
8
+ RUN apt-get update \
9
+ && apt-get install -y --no-install-recommends \
10
+ ca-certificates \
11
+ curl \
12
+ jq \
13
+ libguestfs-tools \
14
+ linux-image-amd64 \
15
+ python3 \
16
+ qemu-system-x86 \
17
+ qemu-utils \
18
+ tar \
19
+ && curl -fsSL "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz" -o /tmp/go.tgz \
20
+ && tar -C /usr/local -xzf /tmp/go.tgz \
21
+ && rm -f /tmp/go.tgz \
22
+ && rm -rf /var/lib/apt/lists/*
23
+
24
+ WORKDIR /workspace/universal-connectivity/go-peer/aleph
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5
+ ALEPH_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
6
+ PROJECT_DIR="${PROJECT_DIR:-$(cd "${SCRIPT_DIR}/../../.." && pwd)}"
7
+ ROOTFS_CONTRACT_FILE="${ROOTFS_CONTRACT_FILE:-${ALEPH_DIR}/root-profiles/uc-go-peer.json}"
8
+ OUT_DIR="${OUT_DIR:-${ALEPH_DIR}/dist-rootfs}"
9
+ BASE_URL="${BASE_URL:-https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2}"
10
+ BASE_IMAGE="${OUT_DIR}/debian-12-genericcloud-amd64.qcow2"
11
+ IMAGE="${OUT_DIR}/aleph-uc-go-peer.qcow2"
12
+ APP_BINARY="${OUT_DIR}/universal-chat-go"
13
+ ROOTFS_IMAGE_SIZE="${ROOTFS_IMAGE_SIZE:-20G}"
14
+
15
+ require() {
16
+ command -v "$1" >/dev/null 2>&1 || {
17
+ echo "Missing required command: $1" >&2
18
+ exit 1
19
+ }
20
+ }
21
+
22
+ require curl
23
+ require qemu-img
24
+ require virt-customize
25
+ require python3
26
+ require go
27
+
28
+ eval "$(python3 "${SCRIPT_DIR}/read-rootfs-contract.py" "${ROOTFS_CONTRACT_FILE}")"
29
+
30
+ ROOTFS_CONTRACT_BINARY_PATH="${ROOTFS_CONTRACT_BINARY_PATH:-/usr/local/bin/universal-chat-go}"
31
+ GUEST_APP_DIR="$(dirname "${ROOTFS_CONTRACT_BINARY_PATH}")"
32
+
33
+ if [ "${ROOTFS_CONTRACT_PROFILE}" != "uc-go-peer" ]; then
34
+ echo "Only the uc-go-peer rootfs profile is supported, got: ${ROOTFS_CONTRACT_PROFILE}" >&2
35
+ exit 1
36
+ fi
37
+ if [ "${ROOTFS_CONTRACT_INSTALL_MODE}" != "prebaked" ]; then
38
+ echo "Only prebaked install mode is supported, got: ${ROOTFS_CONTRACT_INSTALL_MODE}" >&2
39
+ exit 1
40
+ fi
41
+ if [ ! -d "${PROJECT_DIR}/go-peer" ]; then
42
+ echo "Missing go-peer directory: ${PROJECT_DIR}/go-peer" >&2
43
+ exit 1
44
+ fi
45
+
46
+ mkdir -p "${OUT_DIR}"
47
+
48
+ echo "Building uc-go-peer image in prebaked mode"
49
+
50
+ if [ ! -f "${BASE_IMAGE}" ]; then
51
+ curl -L "${BASE_URL}" -o "${BASE_IMAGE}"
52
+ fi
53
+
54
+ cp "${BASE_IMAGE}" "${IMAGE}"
55
+ qemu-img resize "${IMAGE}" "${ROOTFS_IMAGE_SIZE}"
56
+
57
+ echo "Building universal-chat-go outside the guest image"
58
+ (
59
+ cd "${PROJECT_DIR}/go-peer"
60
+ GOMODCACHE="${OUT_DIR}/gomodcache" \
61
+ GOCACHE="${OUT_DIR}/gocache" \
62
+ CGO_ENABLED=0 \
63
+ go build -ldflags="-w -s" -o "${APP_BINARY}" .
64
+ )
65
+
66
+ rm -rf "${OUT_DIR}/gomodcache" "${OUT_DIR}/gocache"
67
+
68
+ virt-customize \
69
+ -a "${IMAGE}" \
70
+ --mkdir "${ROOTFS_CONTRACT_INSTALL_DIR}" \
71
+ --mkdir "${ROOTFS_CONTRACT_DATA_DIR}" \
72
+ --copy-in "${APP_BINARY}:${GUEST_APP_DIR}" \
73
+ --copy-in "${SCRIPT_DIR}/uc-go-peer-bootstrap.sh:/usr/local/sbin" \
74
+ --copy-in "${SCRIPT_DIR}/uc-go-peer-configure.sh:/usr/local/sbin" \
75
+ --copy-in "${SCRIPT_DIR}/uc-go-peer-autotls-refresh.py:/usr/local/sbin" \
76
+ --copy-in "${SCRIPT_DIR}/uc-go-peer-describe.py:/usr/local/sbin" \
77
+ --copy-in "${SCRIPT_DIR}/uc-go-peer-setup-server.py:/usr/local/sbin" \
78
+ --copy-in "${SCRIPT_DIR}/uc-go-peer-bootstrap.service:/etc/systemd/system" \
79
+ --copy-in "${SCRIPT_DIR}/uc-go-peer-autotls-refresh.service:/etc/systemd/system" \
80
+ --copy-in "${SCRIPT_DIR}/uc-go-peer.service:/etc/systemd/system" \
81
+ --run-command "chmod 0755 ${ROOTFS_CONTRACT_BINARY_PATH}" \
82
+ --run-command "chmod 0755 /usr/local/sbin/uc-go-peer-bootstrap.sh" \
83
+ --run-command "chmod 0755 /usr/local/sbin/uc-go-peer-configure.sh" \
84
+ --run-command "chmod 0755 /usr/local/sbin/uc-go-peer-autotls-refresh.py" \
85
+ --run-command "chmod 0755 /usr/local/sbin/uc-go-peer-describe.py" \
86
+ --run-command "chmod 0755 /usr/local/sbin/uc-go-peer-setup-server.py" \
87
+ --run-command "INSTALL_DIR=${ROOTFS_CONTRACT_INSTALL_DIR} APP_BINARY=${ROOTFS_CONTRACT_BINARY_PATH} DATA_DIR=${ROOTFS_CONTRACT_DATA_DIR} ENV_FILE=${ROOTFS_CONTRACT_ENV_FILE} SERVICE_USER=uc-go-peer /usr/local/sbin/uc-go-peer-bootstrap.sh base" \
88
+ --run-command "INSTALL_DIR=${ROOTFS_CONTRACT_INSTALL_DIR} APP_BINARY=${ROOTFS_CONTRACT_BINARY_PATH} DATA_DIR=${ROOTFS_CONTRACT_DATA_DIR} ENV_FILE=${ROOTFS_CONTRACT_ENV_FILE} SERVICE_USER=uc-go-peer /usr/local/sbin/uc-go-peer-bootstrap.sh build" \
89
+ --run-command "INSTALL_DIR=${ROOTFS_CONTRACT_INSTALL_DIR} APP_BINARY=${ROOTFS_CONTRACT_BINARY_PATH} DATA_DIR=${ROOTFS_CONTRACT_DATA_DIR} ENV_FILE=${ROOTFS_CONTRACT_ENV_FILE} SERVICE_USER=uc-go-peer /usr/local/sbin/uc-go-peer-bootstrap.sh finalize" \
90
+ --run-command "systemctl enable ${ROOTFS_CONTRACT_BOOTSTRAP_SERVICE}" \
91
+ --run-command "systemctl enable ${ROOTFS_CONTRACT_AUTOTLS_SERVICE}" \
92
+ --run-command "systemctl enable ${ROOTFS_CONTRACT_MAIN_SERVICE}"
93
+
94
+ echo "Rootfs image ready at ${IMAGE}"