[Feat] Docker compose isolation (#62)

* Moved docker-compose.yml out of default place

* Changed docker-compose.yml references everywhere, added as default option

* Fixed docker-compose name to have yaml extension

* Fixed docker-compose usage with new name

* Removed Docker cmd from setenv
This commit is contained in:
Lele 2022-07-13 13:43:48 +02:00 committed by GitHub
parent 17c116e1ac
commit 1b61d525f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 42 additions and 44 deletions

View File

@ -58,12 +58,12 @@ elif args.action == 'generate':
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:
@ -77,12 +77,12 @@ elif args.action == 'update':
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

View File

@ -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

View File

@ -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

View File

@ -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)
@ -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):
@ -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"
@ -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))

View File

@ -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

View File

@ -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 "$@")

View File

@ -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 "$@")

2
scripts/configure vendored
View File

@ -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:

View File

@ -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

View File

@ -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
}

View File

@ -37,4 +37,4 @@ echo
echo "Stopping Docker services..."
echo
docker compose down
docker compose -f docker-compose.citadel.yml down

View File

@ -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"

View File

@ -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.

View File

@ -29,7 +29,7 @@ parser.add_argument(
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]
@ -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
@ -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
@ -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:

2
setenv
View File

@ -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"