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

[Feat] Docker compose isolation #62

Merged
merged 10 commits into from
Jul 13, 2022
24 changes: 12 additions & 12 deletions app/app-manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@
else:
os.system(os.path.join(nodeRoot, "scripts", "configure"))
os.chdir(nodeRoot)
os.system("docker compose stop app-tor")
os.system("docker compose start app-tor")
os.system("docker compose stop app-2-tor")
os.system("docker compose start app-2-tor")
os.system("docker compose stop app-3-tor")
os.system("docker compose start app-3-tor")
os.system("docker compose -f docker-compose.citadel.yml stop app-tor")
os.system("docker compose -f docker-compose.citadel.yml start app-tor")
os.system("docker compose -f docker-compose.citadel.yml stop app-2-tor")
os.system("docker compose -f docker-compose.citadel.yml start app-2-tor")
os.system("docker compose -f docker-compose.citadel.yml stop app-3-tor")
os.system("docker compose -f docker-compose.citadel.yml start app-3-tor")
exit(0)
elif args.action == 'update':
if args.app is None:
Expand All @@ -77,12 +77,12 @@
else:
os.system(os.path.join(nodeRoot, "scripts", "configure"))
os.chdir(nodeRoot)
os.system("docker compose stop app-tor")
os.system("docker compose start app-tor")
os.system("docker compose stop app-2-tor")
os.system("docker compose start app-2-tor")
os.system("docker compose stop app-3-tor")
os.system("docker compose start app-3-tor")
os.system("docker compose -f docker-compose.citadel.yml stop app-tor")
os.system("docker compose -f docker-compose.citadel.yml start app-tor")
os.system("docker compose -f docker-compose.citadel.yml stop app-2-tor")
os.system("docker compose -f docker-compose.citadel.yml start app-2-tor")
os.system("docker compose -f docker-compose.citadel.yml stop app-3-tor")
os.system("docker compose -f docker-compose.citadel.yml start app-3-tor")
exit(0)
elif args.action == 'ls-installed':
# Load the userFile as JSON, check if installedApps is in it, and if so, print the apps
Expand Down
2 changes: 1 addition & 1 deletion app/app-standard-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ properties:
type: boolean
description: >-
Set this to true if the container shouldn't get an IP & port
exposed. This isn't necessary, but helps the docker-compose.yml generator to generate a cleaner output.
exposed. This isn't necessary, but helps the docker-compose.citadel.yml generator to generate a cleaner output.
hiddenServicePorts:
type:
- object
Expand Down
2 changes: 1 addition & 1 deletion app/app-standard-v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ properties:
type: boolean
description: >-
Set this to true if the container shouldn't get an IP & port
exposed. This isn't necessary, but helps the docker-compose.yml generator to generate a cleaner output.
exposed. This isn't necessary, but helps the docker-compose.citadel.yml generator to generate a cleaner output.
hiddenServicePorts:
type:
- object
Expand Down
12 changes: 6 additions & 6 deletions app/lib/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def update(verbose: bool = False):

# Loop through the apps and generate valid compose files from them, then put these into the app dir
for app in apps:
composeFile = os.path.join(appsDir, app, "docker-compose.yml")
composeFile = os.path.join(appsDir, app, "docker-compose.citadel.yml")
appYml = os.path.join(appsDir, app, "app.yml")
with open(composeFile, "w") as f:
appCompose = getApp(appYml, app)
Expand Down Expand Up @@ -176,7 +176,7 @@ def stopInstalled():
threads.append(thread)
joinThreads(threads)

# Loads an app.yml and converts it to a docker-compose.yml
# Loads an app.yml and converts it to a docker-compose.citadel.yml


def getApp(appFile: str, appId: str):
Expand All @@ -201,8 +201,8 @@ def compose(app, arguments):
print("Warning: App {} doesn't exist on Citadel".format(app))
return
# Runs a compose command in the app dir
# Before that, check if a docker-compose.yml exists in the app dir
composeFile = os.path.join(appsDir, app, "docker-compose.yml")
# Before that, check if a docker-compose.citadel.yml exists in the app dir
composeFile = os.path.join(appsDir, app, "docker-compose.citadel.yml")
commonComposeFile = os.path.join(appSystemDir, "docker-compose.common.yml")
os.environ["APP_DOMAIN"] = subprocess.check_output(
"hostname -s 2>/dev/null || echo 'citadel'", shell=True).decode("utf-8").strip() + ".local"
Expand Down Expand Up @@ -233,10 +233,10 @@ def compose(app, arguments):
appHiddenServiceFile), shell=True).decode("utf-8").strip()

if not os.path.isfile(composeFile):
print("Error: Could not find docker-compose.yml in " + app)
print("Error: Could not find docker-compose.citadel.yml in " + app)
exit(1)
os.system(
"docker compose --env-file '{}' --project-name '{}' --file '{}' --file '{}' {}".format(
"docker compose -f docker-compose.citadel.yml --env-file '{}' --project-name '{}' --file '{}' --file '{}' {}".format(
os.path.join(nodeRoot, ".env"), app, commonComposeFile, composeFile, arguments))


Expand Down
2 changes: 1 addition & 1 deletion app/lib/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def findApps(dir: str):
for root, dirs, files in os.walk(dir, topdown=False):
for name in dirs:
app_dir = os.path.join(root, name)
if os.path.isfile(os.path.join(app_dir, "app.yml")) or os.path.isfile(os.path.join(app_dir, "docker-compose.yml")):
if os.path.isfile(os.path.join(app_dir, "app.yml")) or os.path.isfile(os.path.join(app_dir, "docker-compose.citadel.yml")):
apps.append(name)
return apps

Expand Down
4 changes: 2 additions & 2 deletions bin/bitcoin-cli
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ set -euo pipefail

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

result=$(docker compose \
--file "${CITADEL_ROOT}/docker-compose.yml" \
result=$(docker compose -f docker-compose.citadel.yml \
--file "${CITADEL_ROOT}/docker-compose.citadel.yml" \
--env-file "${CITADEL_ROOT}/.env" \
exec bitcoin bitcoin-cli "$@")

Expand Down
4 changes: 2 additions & 2 deletions bin/lncli
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ set -euo pipefail

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

result=$(docker compose \
--file "${CITADEL_ROOT}/docker-compose.yml" \
result=$(docker compose -f docker-compose.citadel.yml \
--file "${CITADEL_ROOT}/docker-compose.citadel.yml" \
--env-file "${CITADEL_ROOT}/.env" \
exec lightning lncli "$@")

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion scripts/configure
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if not is_arm64 and not is_amd64:
print('Citadel only works on arm64 and amd64!')
exit(1)

# Check the output of "docker compose version", if it matches "Docker Compose version v2.0.0-rc.3", return true
# Check the output of "docker compose -f docker-compose.citadel.yml version", if it matches "Docker Compose version v2.0.0-rc.3", return true
# Otherwise, return false
def is_compose_rc_or_outdated():
try:
Expand Down
14 changes: 7 additions & 7 deletions scripts/debug
Original file line number Diff line number Diff line change
Expand Up @@ -139,28 +139,28 @@ if [[ "${1}" == "--run" ]]; then
echo "Bitcoin Core logs"
echo "-----------------"
echo
docker compose logs --tail=30 bitcoin
docker compose -f docker-compose.citadel.yml logs --tail=30 bitcoin

echo
echo "Lightning logs"
echo "--------------"
echo
docker compose logs --tail=30 lightning
docker compose -f docker-compose.citadel.yml logs --tail=30 lightning

echo
echo "Electrum logs"
echo "-------------"
echo
docker compose logs --tail=30 electrum
docker compose -f docker-compose.citadel.yml logs --tail=30 electrum

echo
echo "Tor logs"
echo "--------"
echo
docker compose logs --tail=30 tor
docker compose logs --tail=30 app-tor
docker compose logs --tail=30 app-2-tor
docker compose logs --tail=30 app-3-tor
docker compose -f docker-compose.citadel.yml logs --tail=30 tor
docker compose -f docker-compose.citadel.yml logs --tail=30 app-tor
docker compose -f docker-compose.citadel.yml logs --tail=30 app-2-tor
docker compose -f docker-compose.citadel.yml logs --tail=30 app-3-tor

installed_apps=$(./scripts/app ls-installed)
if [[ ! -z "${installed_apps:-}" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion scripts/start
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ echo
echo
echo "Starting Docker services..."
echo
docker compose up --detach --build --remove-orphans || {
docker compose -f docker-compose.citadel.yml up --detach --build --remove-orphans || {
echo "Failed to start containers"
exit 1
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/stop
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ echo

echo "Stopping Docker services..."
echo
docker compose down
docker compose -f docker-compose.citadel.yml down
2 changes: 1 addition & 1 deletion scripts/update/01-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ echo "Pulling new containers"
cat <<EOF > "$CITADEL_ROOT"/statuses/update-status.json
{"state": "installing", "progress": 50, "description": "Pulling new containers", "updateTo": "$RELEASE"}
EOF
docker compose pull
docker compose -f docker-compose.citadel.yml pull

# Stopping karen
echo "Stopping background daemon"
Expand Down
2 changes: 1 addition & 1 deletion scripts/update/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ How over-the-air updates work on Citadel.

1. New developments across the any/entire fleet of Citadel's services (bitcoind, lnd, dashboard, middleware, etc) are made, which maintain their own independent version-control and release-schedule. Subsequently, their new docker images are built, tagged and pushed to Docker Hub.

2. The newly built and tagged images are updated in the main repository's (i.e. this repo) [`docker-compose.yml`](https://github.com/runcitadel/core/blob/main/docker-compose.yml) file.
2. The newly built and tagged images are updated in the main repository's (i.e. this repo) [`docker-compose.citadel.yml`](https://github.com/runcitadel/core/blob/main/docker-compose.citadel.yml) file.

3. Any new developments to the main repository (i.e. this repo) are made, eg. adding a new directory or a new config file.

Expand Down
10 changes: 5 additions & 5 deletions services/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
args = parser.parse_args()

# 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)
# To install it, read the service's YAML file (nodeRoot/services/name.yml) and add it to the main compose file (nodeRoot/docker-compose.citadel.yml)
def setService(name, implementation):
# Get all available services
services = next(os.walk(os.path.join(nodeRoot, "services")))[1]
Expand All @@ -51,14 +51,14 @@ def setService(name, implementation):
service = yaml.safe_load(stream)

# Read the main compose file
with open(os.path.join(nodeRoot, "docker-compose.yml"), 'r') as stream:
with open(os.path.join(nodeRoot, "docker-compose.citadel.yml"), 'r') as stream:
compose = yaml.safe_load(stream)

# Add the service to the main compose file
compose['services'].update(service)

# Write the main compose file
with open(os.path.join(nodeRoot, "docker-compose.yml"), 'w') as stream:
with open(os.path.join(nodeRoot, "docker-compose.citadel.yml"), 'w') as stream:
yaml.dump(compose, stream, sort_keys=False)
# Save the service name in nodeRoot/services/installed.json, which is a JSON file with a list of installed services
# If the file doesn't exist, put [] in it, then run the code below
Expand All @@ -81,7 +81,7 @@ def uninstallService(name):
print("Service definition not found, cannot uninstall")
exit(1)
# Read the main compose file
with open(os.path.join(nodeRoot, "docker-compose.yml"), 'r') as stream:
with open(os.path.join(nodeRoot, "docker-compose.citadel.yml"), 'r') as stream:
compose = yaml.safe_load(stream)

# Remove the service from the main compose file
Expand All @@ -91,7 +91,7 @@ def uninstallService(name):
pass

# Write the main compose file
with open(os.path.join(nodeRoot, "docker-compose.yml"), 'w') as stream:
with open(os.path.join(nodeRoot, "docker-compose.citadel.yml"), 'w') as stream:
yaml.dump(compose, stream, sort_keys=False)
# Save the service name in nodeRoot/services/installed.json, which is a JSON file with a list of installed services
try:
Expand Down
2 changes: 0 additions & 2 deletions setenv
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ CITADEL_ROOT="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
alias citadel-update="${CITADEL_ROOT}/scripts/update/update"
alias lncli="docker exec -it lnd lncli"
alias bitcoin-cli="docker exec -it bitcoin bitcoin-cli"
alias docker-compose="sudo docker compose"
alias docker="sudo docker"
alias debug="${CITADEL_ROOT}/scripts/debug"
alias app="${CITADEL_ROOT}/scripts/app"

Expand Down