Skip to content

Commit

Permalink
Merge branch 'master' into restart-pm2-on-reboot
Browse files Browse the repository at this point in the history
  • Loading branch information
tobi-bams committed Nov 12, 2024
2 parents 0884b92 + 04812ea commit e69a4a8
Show file tree
Hide file tree
Showing 31 changed files with 721 additions and 334 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Sphinx Stack</title>
<link rel="stylesheet" href="g100.css" />
<script type="module" crossorigin src="/assets/index-d91d7471.js"></script>
<script type="module" crossorigin src="/assets/index-f894ec8d.js"></script>
<link rel="stylesheet" href="/assets/index-121261a7.css">
</head>
<body>
Expand Down
19 changes: 8 additions & 11 deletions app/src/Dashboard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,17 @@
import type { Node, Stack } from "./nodes";
import User from "carbon-icons-svelte/lib/User.svelte";
import ChangePassword from "./auth/ChangePassword.svelte";
import { get_signedin_user_details, type Container } from "./api/swarm";
import {
get_all_image_actual_version,
get_signedin_user_details,
type Container,
} from "./api/swarm";
import { getImageVersion } from "./helpers/swarm";
import RestartNode from "./nodes/RestartNode.svelte";
let selectedName = "";
async function getNodeVersion(nodes: Node[]) {
//loop throug nodes
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
// if node version is latest get digest
if (node.version === "latest") {
await getImageVersion(node.name, stack, selectedNode);
}
}
async function getNodeVersion() {
await getImageVersion(stack, selectedNode);
}
async function pollConfig() {
Expand All @@ -55,7 +52,7 @@
if (stackRemote.nodes !== $stack.nodes) {
stack.set(stackRemote);
// get node version
getNodeVersion(stackRemote.nodes);
getNodeVersion();
}
return stackRemote.ready;
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/api/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ export type Cmd =
| "RestartChildSwarmContainers"
| "GetSignedInUserDetails"
| "UpdateAwsInstanceType"
| "GetInstanceType";
| "GetInstanceType"
| "GetAllImageActualVersion"
| "GetSwarmChildImageVersions";

interface CmdData {
cmd: Cmd;
Expand Down
11 changes: 11 additions & 0 deletions app/src/api/swarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ export async function delete_swarm(data: { host: string }) {
return await swarmCmd("DeleteSwarm", { ...data });
}

export async function get_all_image_actual_version() {
return await swarmCmd("GetAllImageActualVersion");
}
export async function get_child_swarm_image_versions({
host,
}: {
host: string;
}) {
return await swarmCmd("GetSwarmChildImageVersions", { host });
}

export async function login(username, password) {
const r = await fetch(`${root}/login`, {
method: "POST",
Expand Down
128 changes: 24 additions & 104 deletions app/src/helpers/swarm.ts
Original file line number Diff line number Diff line change
@@ -1,117 +1,37 @@
import type { Writable } from "svelte/store";
import { get_image_tags } from "../api/swarm";
import { get_all_image_actual_version, get_image_tags } from "../api/swarm";
import type { Stack, Node } from "../nodes";
import { swarm } from "../api";

export async function getVersionFromDigest(
digest: string,
org_image_name: string,
page: string,
page_size: string
) {
try {
const splittedDigest = digest.split("@")[1];
const response = await get_image_tags(org_image_name, page, page_size);

const tags = JSON.parse(response);

for (let i = 0; i < tags.results.length; i++) {
const result = tags.results[i];
if (result.digest === splittedDigest) {
if (result.name !== "latest") {
return result.name;
} else {
const architectureDigests = [];
for (let j = 0; j < result.images.length; j++) {
architectureDigests.push(result.images[j].digest);
}
return findArchitectureDigest(architectureDigests, tags.results);
}
}
}

if (tags.next) {
const urlString = tags.next;
const url = new URL(urlString);
const params = new URLSearchParams(url.search);

const page = params.get("page");
const page_size = params.get("page_size");

return await getVersionFromDigest(
digest,
org_image_name,
page,
page_size
);
}
} catch (error) {
throw error;
}
}

function findArchitectureDigest(architectureDigests, results) {
for (let i = 0; i < results.length; i++) {
const result = results[i];
if (result.name !== "latest") {
for (let j = 0; j < result.images.length; j++) {
const image = result.images[j];
if (architectureDigests.includes(image.digest)) {
return result.name;
}
}
}
}
}

export async function getImageVersion(
node_name: string,
stack: Writable<Stack>,
selectedNode: Writable<Node>
) {
let image_name = `sphinx-${node_name}`;
if (node_name === "relay") {
image_name = `sphinx-relay-swarm`;
} else if (node_name === "cln") {
image_name = `cln-sphinx`;
} else if (node_name === "navfiber") {
image_name = `sphinx-nav-fiber`;
} else if (node_name === "cache") {
image_name = ``;
} else if (node_name === "jarvis") {
image_name = `sphinx-jarvis-backend`;
}
const image_digest_response = await swarm.get_image_digest(
`sphinxlightning/${image_name}`
);
if (image_digest_response.success) {
const version = await getVersionFromDigest(
image_digest_response.digest,
`sphinxlightning/${image_name}`,
"1",
"100"
);
const image_versions = await get_all_image_actual_version();
console.log(image_versions);
if (image_versions.success) {
let version_object = {};

for (let i = 0; i < image_versions.data.length; i++) {
const image_version = image_versions.data[i];
version_object[image_version.name] = image_version.version;
}

if (version) {
stack.update((stack) => {
for (let i = 0; i < stack.nodes.length; i++) {
const oldNode = { ...stack.nodes[i] };
if (oldNode.name === node_name) {
const newNode = {
...oldNode,
version,
};
stack.update((stack) => {
for (let i = 0; i < stack.nodes.length; i++) {
const newNode = {
...stack.nodes[i],
version: version_object[stack.nodes[i].name],
};

selectedNode.update((node) =>
node && node.name === newNode.name ? { ...newNode } : node
);
selectedNode.update((node) =>
node && node.name === newNode.name ? { ...newNode } : node
);

stack.nodes[i] = { ...newNode };
break;
}
}
return stack;
});
}
stack.nodes[i] = { ...newNode };
}

return stack;
});
}
}
2 changes: 1 addition & 1 deletion app/src/nodes/NodeUpdate.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
if (!name) return;
updating = true;
await api.swarm.update_node(name);
await getImageVersion(name, stack, selectedNode);
await getImageVersion(stack, selectedNode);
updating = false;
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion app/src/nodes/RestartNode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
console.log("restart!", name);
restarting = true;
await api.swarm.restart_node(name);
await getImageVersion(name, stack, selectedNode);
await getImageVersion(stack, selectedNode);
restarting = false;
}
</script>
Expand Down
4 changes: 1 addition & 3 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: "2"

services:
reverse-proxy:
image: traefik:v2.2.1
image: traefik:v2.9
container_name: traefik.sphinx
restart: unless-stopped
networks:
Expand Down Expand Up @@ -35,8 +35,6 @@ services:
- /var/run/docker.sock:/var/run/docker.sock
- /home/admin/letsencrypt:/letsencrypt
environment:
- AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
- AWS_REGION=$AWS_REGION
logging:
options:
Expand Down
9 changes: 3 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
load_balancer:
image: traefik:v2.2.1
image: traefik:v2.9
container_name: load_balancer
restart: unless-stopped
networks:
Expand Down Expand Up @@ -33,8 +33,6 @@ services:
- /var/run/docker.sock:/var/run/docker.sock
- /home/admin/letsencrypt:/letsencrypt
environment:
- AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
- AWS_REGION=$AWS_REGION
logging:
options:
Expand Down Expand Up @@ -73,10 +71,7 @@ services:
- NETWORK=bitcoin
- ROCKET_ADDRESS=0.0.0.0
- ROCKET_PORT=8000
- AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
- AWS_REGION=$AWS_REGION
- AWS_S3_REGION_NAME=$AWS_S3_REGION_NAME
- STAKWORK_ADD_NODE_TOKEN=$STAKWORK_ADD_NODE_TOKEN
- STAKWORK_RADAR_REQUEST_TOKEN=$STAKWORK_RADAR_REQUEST_TOKEN
- CLN_MAINNET_BTC=$CLN_MAINNET_BTC
Expand All @@ -91,6 +86,8 @@ services:
- FEATURE_FLAG_TEXT_EMBEDDINGS=$FEATURE_FLAG_TEXT_EMBEDDINGS
- SUPER_URL=$SUPER_URL
- SUPER_TOKEN=$SUPER_TOKEN
- QUESTION_AND_ANSWER_WORKFLOW_ID=$QUESTION_AND_ANSWER_WORKFLOW_ID
- AWS_S3_BUCKET_NAME=$AWS_S3_BUCKET_NAME

networks:
sphinx-swarm:
Expand Down
9 changes: 3 additions & 6 deletions second-brain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: "2"

services:
load_balancer:
image: traefik:v2.2.1
image: traefik:v2.9
container_name: load_balancer
restart: unless-stopped
networks:
Expand Down Expand Up @@ -37,8 +37,6 @@ services:
- /var/run/docker.sock:/var/run/docker.sock
- /home/admin/letsencrypt:/letsencrypt
environment:
- AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
- AWS_REGION=$AWS_REGION
logging:
options:
Expand Down Expand Up @@ -70,10 +68,7 @@ services:
- NETWORK=bitcoin
- ROCKET_ADDRESS=0.0.0.0
- ROCKET_PORT=8800
- AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
- AWS_REGION=$AWS_REGION
- AWS_S3_REGION_NAME=$AWS_S3_REGION_NAME
- STAKWORK_ADD_NODE_TOKEN=$STAKWORK_ADD_NODE_TOKEN
- STAKWORK_RADAR_REQUEST_TOKEN=$STAKWORK_RADAR_REQUEST_TOKEN
- SECOND_BRAIN_ONLY=true
Expand Down Expand Up @@ -104,6 +99,8 @@ services:
- WEBPAGE_TEXT_WORKFLOW_ID=$WEBPAGE_TEXT_WORKFLOW_ID
- SUPER_URL=$SUPER_URL
- LOCAL_LLAMA=$LOCAL_LLAMA
- QUESTION_AND_ANSWER_WORKFLOW_ID=$QUESTION_AND_ANSWER_WORKFLOW_ID
- AWS_S3_BUCKET_NAME=$AWS_S3_BUCKET_NAME

networks:
sphinx-swarm:
Expand Down
5 changes: 2 additions & 3 deletions sphinx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: "2"

services:
reverse-proxy:
image: traefik:v2.2.1
image: traefik:v2.9
container_name: traefik.sphinx
restart: unless-stopped
networks:
Expand Down Expand Up @@ -37,8 +37,6 @@ services:
- /var/run/docker.sock:/var/run/docker.sock
- /home/admin/letsencrypt:/letsencrypt
environment:
- AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
- AWS_REGION=$AWS_REGION
logging:
options:
Expand Down Expand Up @@ -76,6 +74,7 @@ services:
- TRIBES_HOST=$TRIBES_HOST
- SUPER_TOKEN=$SUPER_TOKEN
- SUPER_URL=$SUPER_URL
- AWS_S3_BUCKET_NAME=$AWS_S3_BUCKET_NAME

networks:
sphinx-swarm:
Expand Down
6 changes: 3 additions & 3 deletions sphinxv2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: "2"

services:
reverse-proxy:
image: traefik:v2.2.1
image: traefik:v2.9
container_name: traefik.sphinx
restart: unless-stopped
networks:
Expand Down Expand Up @@ -37,8 +37,6 @@ services:
- /var/run/docker.sock:/var/run/docker.sock
- /home/admin/letsencrypt:/letsencrypt
environment:
- AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
- AWS_REGION=$AWS_REGION
logging:
options:
Expand Down Expand Up @@ -75,6 +73,8 @@ services:
- IS_ROUTER=$IS_ROUTER
- SEED=$SEED
- CLN_MAINNET_BTC=$CLN_MAINNET_BTC
- AWS_REGION=$AWS_REGION
- AWS_S3_BUCKET_NAME=$AWS_S3_BUCKET_NAME

networks:
sphinx-swarm:
Expand Down
Loading

0 comments on commit e69a4a8

Please sign in to comment.