Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Citadel 0.0.5 #45

Merged
merged 35 commits into from
Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6b29a76
Switch app store to beta branch
AaronDewes May 16, 2022
56946a9
Put the latest beta into info.json
AaronDewes May 16, 2022
611d4a1
Add Karen v2 demo
AaronDewes May 16, 2022
3cec303
Generate cache files for compose generator
AaronDewes May 16, 2022
f6dae9c
Add karen v2
AaronDewes May 19, 2022
a5e74fa
Remove log
AaronDewes May 19, 2022
80ead94
Remove unused import
AaronDewes May 20, 2022
d45da54
Merge branch 'stable' into beta
AaronDewes May 22, 2022
9a6501a
Merge remote-tracking branch 'origin/karen-v2' into beta
AaronDewes May 22, 2022
4eb9819
Remove leftovers from WIP karen v2
AaronDewes May 22, 2022
781299f
Update manager
AaronDewes May 22, 2022
62d51aa
0.0.4 rc1
AaronDewes May 22, 2022
6e74290
Merge branch 'stable' into beta
AaronDewes May 24, 2022
5b2b5a4
Merge branch 'stable' into beta
AaronDewes Jun 1, 2022
86c17c3
Remove leftovers from karen v1 (#42)
AaronDewes Jun 2, 2022
82af32f
Use new backup server
AaronDewes Jun 3, 2022
2b376b2
Update backup
AaronDewes Jun 4, 2022
a504257
Remove debug echp
AaronDewes Jun 4, 2022
1d28bc8
Merge remote-tracking branch 'origin/beta' into release/0.0.5
AaronDewes Jun 5, 2022
cc2f3d3
Merge remote-tracking branch 'origin/feat/new-backup-server' into rel…
AaronDewes Jun 5, 2022
a54237f
Revert "Switch app store to beta branch"
AaronDewes Jun 5, 2022
ce55a8e
Citadel 0.0.5
AaronDewes Jun 5, 2022
ce71560
New backup server (#43)
AaronDewes Jun 5, 2022
29d67d9
Update dashboard to 0.0.13
AaronDewes Jun 5, 2022
02fdae4
Publish a beta of 0.0.5 to the beta channel (#46)
AaronDewes Jun 5, 2022
f08711a
Add script to set update channel (#47)
AaronDewes Jun 5, 2022
e40e35f
Update manager (#48)
AaronDewes Jun 5, 2022
2a933ea
Fix the way UDP ports are declared (#49)
AaronDewes Jun 7, 2022
b87c54e
Fix memory scripts (#50)
AaronDewes Jun 7, 2022
7311369
Bump version
AaronDewes Jun 8, 2022
b3bdf48
Merge tag 'v0.0.5-rc.2' into release/0.0.5
AaronDewes Jun 8, 2022
336aa55
Update middleware & manager
AaronDewes Jun 10, 2022
f05c69c
Update dashboard
AaronDewes Jun 10, 2022
54e82e3
fix: update lncli binary docker container
pwltr Jun 5, 2022
9643778
add some validation to setService
pwltr Jun 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ electrs/*
fulcrumx/*
nginx/*
redis/*
events/signals/*
docker-compose.override.yml

# Commit these empty directories
Expand All @@ -36,7 +35,6 @@ docker-compose.override.yml
!db/citadel-seed
db/citadel-seed/*
!db/citadel-seed/.gitkeep
!events/signals/.gitkeep
!lnd/.gitkeep
!logs/.gitkeep
!tor/data/.gitkeep
Expand All @@ -46,7 +44,6 @@ db/citadel-seed/*
!nginx/.gitkeep
!redis/.gitkeep
!fulcrumx/.gitkeep
!events/signals/.gitkeep

!**/*.license
services/installed.json
Expand Down
2 changes: 1 addition & 1 deletion app/lib/composegenerator/v3/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def createComposeConfigFromV3(app: dict, nodeRoot: str):
del container.requiredPorts
for container in newApp.containers:
for udpPort in container.requiredUdpPorts:
container.ports.append("{}/udp:{}/udp".format(udpPort, udpPort))
container.ports.append("{}:{}/udp".format(udpPort, udpPort))
del container.requiredUdpPorts
newApp = configureMainPort(newApp, nodeRoot)
newApp = configureHiddenServices(newApp, nodeRoot)
Expand Down
2 changes: 1 addition & 1 deletion bin/lncli
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CITADEL_ROOT="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/..)"
result=$(docker compose \
--file "${CITADEL_ROOT}/docker-compose.yml" \
--env-file "${CITADEL_ROOT}/.env" \
exec lnd lncli "$@")
exec lightning lncli "$@")

# We need to echo with quotes to preserve output formatting
echo "$result"
7 changes: 3 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ services:
ipv4_address: $LND_IP
dashboard:
container_name: dashboard
image: ghcr.io/runcitadel/dashboard:v0.0.12@sha256:102a44b938765be8224c63785949b90bf796670f01aef4e282d58a4c26a42595
image: ghcr.io/runcitadel/dashboard:v0.0.15@sha256:a2cf5ad79367fb083db0f61e5a296aafee655c99af0c228680644c248ec674a5
restart: on-failure
stop_grace_period: 1m30s
networks:
default:
ipv4_address: $DASHBOARD_IP
manager:
container_name: manager
image: ghcr.io/runcitadel/manager:v0.0.13@sha256:3ced2643e12253fea46abb48a69dcd999d69d3d86ed9956ae0298d4f6be4f06d
image: ghcr.io/runcitadel/manager:v0.0.15@sha256:9fb5a86d9e40a04f93d5b6110d43a0f9a5c4ad6311a843b5442290013196a5ce
depends_on:
- tor
- redis
Expand All @@ -120,7 +120,6 @@ services:
volumes:
- ${PWD}/info.json:/info.json
- ${PWD}/db:/db
- ${PWD}/events/signals:/signals
- ${PWD}/events:/events
- ${PWD}/apps:/apps
- ${PWD}/lnd:/lnd:ro
Expand Down Expand Up @@ -163,7 +162,7 @@ services:
ipv4_address: $MANAGER_IP
middleware:
container_name: middleware
image: ghcr.io/runcitadel/middleware:v0.0.10@sha256:afd6e2b6f5ba27cde32f6f6d630ddc6dd46d1072871f7834d7424d0554d0f53d
image: ghcr.io/runcitadel/middleware:v0.0.11@sha256:e472da8cbfa67d9a9dbf321334fe65cdf20a0f9b6d6bab33fdf07210f54e7002
depends_on:
- manager
- bitcoin
Expand Down
Empty file removed events/signals/.gitkeep
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

CITADEL_ROOT="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../..)"

"${CITADEL_ROOT}/scripts/set-update-channel" beta
"${CITADEL_ROOT}/scripts/set-update-channel" "${1}"
9 changes: 0 additions & 9 deletions events/triggers/use-stable-builds

This file was deleted.

6 changes: 3 additions & 3 deletions info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "0.0.4",
"name": "Citadel 0.0.4",
"version": "0.0.5",
"name": "Citadel 0.0.5",
"requires": ">=0.0.1",
"notes": "This update fixes multiple bugs in the 0.0.3 release."
"notes": "This update fixes a few bugs in the 0.0.4 release that were preventing some apps from working correctly."
}
41 changes: 11 additions & 30 deletions scripts/backup/backup
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

# SPDX-FileCopyrightText: 2020 Umbrel. https://getumbrel.com
# SPDX-FileCopyrightText: 2022 Citadel and contributors. https://runcitadel.space
#
# SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -98,39 +99,19 @@ tar \
# --verbose \
# --gzip

# Check if a file exists on Firebase by checking if
# "https://firebasestorage.googleapis.com/v0/b/citadel-user-backups.appspot.com/o/backups%2F<THE_FILE_NAME>?alt=media"
# returns a 200 response code.
#
check_if_exists() {
curl -s -o /dev/null -w "%{http_code}" \
-X GET \
"https://firebasestorage.googleapis.com/v0/b/citadel-user-backups.appspot.com/o/backups%2F${1}?alt=media"
}

# Upload a file to Firebase Cloud Storage by uloading its name + a random ID.
# Before uploading, we need to check if a file with the same name already exists, and if it does, change the random ID.
# For example, if we want to upload a file named "<THE_FILE_NAME>" with the content AA, we'd use this command to upload:
# curl -X POST "https://firebasestorage.googleapis.com/v0/b/citadel-user-backups.appspot.com/o/backups%2F<THE_FILE_NAME>?alt=media" -d "AA" -H "Content-Type: text/plain"
# To check if a file exists, we can check if this endpoint returns an error 404:
# curl "https://firebasestorage.googleapis.com/v0/b/citadel-user-backups.appspot.com/o/backups%2F<THE_FILE_NAME>?alt=media"
# To download a file, we can the same endpoint
upload_file() {
local file_to_send="${1}"
local file_name="${2}"
# A random ID to avoid collisions
local random_id="$(tr -dc A-Za-z0-9 </dev/urandom | head -c 60 ; echo '')"
# Check if the file already exists
# While a file with the same name exists, we'll try to upload it with a different ID
while [[ $(check_if_exists "${file_name}-${random_id}") == "200" ]]; do
random_id="$(tr -dc A-Za-z0-9 </dev/urandom | head -c 60 ; echo '')"
done
# Upload the file
local backup_id="${2}"
local upload_data=$(jq --null-input \
--arg name "$backup_id" \
--arg data "$(base64 $file_to_send)" \
'{"name": $name, "data": $data}')
curl -X POST \
"https://firebasestorage.googleapis.com/v0/b/citadel-user-backups.appspot.com/o/backups%2F${file_name}-${random_id}?alt=media" \
-d @"${file_to_send}" \
-H "Content-Type: application/octet-stream" \
> /dev/null
"https://account.runcitadel.space/api/upload" \
-d "${upload_data}" \
-H "Content-Type: application/json" \
--socks5 "localhost:${TOR_PROXY_PORT}" \
> /dev/null
}

if [[ $BITCOIN_NETWORK == "testnet" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion scripts/backup/decoy-trigger
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ main () {
echo "Sleeping for ${delay} seconds..."
sleep $delay
echo "Triggering decoy backup..."
touch "${CITADEL_ROOT}/events/signals/backup"
"${CITADEL_ROOT}/scripts/backup/backup"
done
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/backup/monitor
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ monitor_file () {
sleep 1
done
echo "$file_path created! Triggering backup..."
touch "${CITADEL_ROOT}/events/signals/backup"
"${CITADEL_ROOT}/scripts/backup/backup"
fi

fswatch -0 --event Updated $file_path | xargs -0 -n 1 -I {} touch "${CITADEL_ROOT}/events/signals/backup"
fswatch -0 --event Updated $file_path | xargs -0 -n 1 -I {} "${CITADEL_ROOT}/scripts/backup/backup"
}

if [[ ! -d "${CITADEL_ROOT}" ]]; then
Expand Down
29 changes: 17 additions & 12 deletions scripts/memory-usage
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ function get_memory_usage() {
function mem_usage_to_percent() {
local mem_usage="$1"
local total_mem="$(free -m | awk 'NR==2 {print $2}')"
echo "$(awk "BEGIN {printf \"%.1f\", $mem_usage / $total_mem * 100}")"
echo "$(awk "BEGIN {printf \"%.1f\", ${mem_usage/,/.} / ${total_mem/,/.} * 100}")"
}

function app_mem_usage() {
# For every container of the app, get the mem usage, save it, and at the end, print the total mem usage of the app
local mem_usage=0
for container in $(get_app_containers "$1"); do
# Use awk to add, it supports floating point numbers
mem_usage=$(awk "BEGIN {printf \"%.2f\", $mem_usage + $(get_memory_usage "$container")}")
done
echo "${1}: $mem_usage%"
}

get_total_used_mem_raw() {
Expand All @@ -35,7 +45,7 @@ get_total_used_mem() {
# To get the containers of the app, list every container whose name starts with the name of the app
get_app_containers () {
local app_name="$1"
"${CITADEL_ROOT}/scripts/app" compose "${app_name}" ps | awk '{print $1}' | grep -v 'Name\|-----'
"${CITADEL_ROOT}/scripts/app" compose "${app_name}" ps | awk '{print $1}' | grep -v 'NAME'
}

# Get the memory usage of the whole system, excluding docker containers
Expand All @@ -48,22 +58,17 @@ get_system_memory_usage() {
}

main() {
echo "total: $(get_total_used_mem)%"&
echo "total: $(get_total_used_mem)%"
echo "system: $(get_system_memory_usage)%"
for service in bitcoin lightning electrum tor; do
echo "${service}: $(get_memory_usage "$service")%" &
done
for app in $("${CITADEL_ROOT}/scripts/app" ls-installed); do
# For every container of the app, get the mem usage, save it, and at the end, print the total mem usage of the app
local mem_usage=0
for container in $(get_app_containers "$app"); do
# Use awk to add, it supports floating point numbers
mem_usage=$(awk "BEGIN {printf \"%.2f\", $mem_usage + $(get_memory_usage "$container")}")
done
wait
echo "${app}: $mem_usage%"
app_mem_usage "${app}" &
done
echo "system: $(get_system_memory_usage)%"
wait
}

echo "Calculating memory usage..."
echo "This may take a while, please wait..."
main | sort --key 2 --numeric-sort --reverse
2 changes: 1 addition & 1 deletion scripts/start
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ echo
echo "Starting status monitors..."
echo
pkill -f ./scripts/status-monitor || true
./scripts/status-monitor memory 60 &>> "${CITADEL_LOGS}/status-monitor.log" &
./scripts/status-monitor memory 300 &>> "${CITADEL_LOGS}/status-monitor.log" &
./scripts/status-monitor storage 60 &>> "${CITADEL_LOGS}/status-monitor.log" &
./scripts/status-monitor temperature 15 &>> "${CITADEL_LOGS}/status-monitor.log" &
./scripts/status-monitor uptime 15 &>> "${CITADEL_LOGS}/status-monitor.log" &
Expand Down
7 changes: 5 additions & 2 deletions scripts/status/memory
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later

# To prevent tools we use from outputting in another language
LANG=C

CITADEL_ROOT="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../..)"

memory_total_bytes() {
Expand All @@ -23,7 +26,7 @@ get_app_memory_use() {

local app_memory=0

local app_containers=$("${CITADEL_ROOT}/app/app-manager.py" compose "${app}" ps | awk '{print $1}' | grep -v 'Name\|-----')
local app_containers=$("${CITADEL_ROOT}/scripts/app" compose "${app}" ps | awk '{print $1}' | grep -v 'NAME')
for container in $app_containers; do
local container_memory=$(get_container_memory_use "${container}")
app_memory=$(awk "BEGIN {print ${app_memory}+${container_memory}}")
Expand All @@ -43,7 +46,7 @@ used=$(memory_used_bytes)
json=$(echo $json | jq --arg used "${used}" '. + {used: $used|tonumber}')

cumulative_app_memory="0"
for app in $( "${CITADEL_ROOT}/app/app-manager.py" ls-installed); do
for app in $( "${CITADEL_ROOT}/scripts/app" ls-installed); do
app_memory=$(get_app_memory_use "${app}")
cumulative_app_memory=$(($cumulative_app_memory+$app_memory))
json=$(echo $json | jq --arg app "${app}" --arg app_memory "${app_memory}" '.breakdown |= .+ [{id: $app, used: $app_memory|tonumber}]')
Expand Down
1 change: 0 additions & 1 deletion scripts/update/.updateignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ lnd/*
statuses
tor/*
electrs/*
events/signals
logs/*
app-data/*
apps/networking.json
Expand Down
15 changes: 15 additions & 0 deletions services/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@
# Function to install a service
# To install it, read the service's YAML file (nodeRoot/services/name.yml) and add it to the main compose file (nodeRoot/docker-compose.yml)
def setService(name, implementation):
# Get all available services
services = next(os.walk(os.path.join(nodeRoot, "services")))[1]

if not name in services:
print("\"{}\" is not a valid service.".format(name))
exit(1)

# Get all available implementations
implementations = next(os.walk(os.path.join(nodeRoot, "services", name)), (None, None, []))[2]
implementations = [x.split('.')[0] for x in implementations]

if not implementation in implementations:
print("\"{}\" is not a valid implementation.".format(implementation))
exit(1)

# Read the YAML file
with open(os.path.join(nodeRoot, "services", name, implementation + ".yml"), 'r') as stream:
service = yaml.safe_load(stream)
Expand Down