Skip to content

Commit

Permalink
Add support for daemons plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNaif2018 committed Aug 26, 2024
1 parent d5f76ed commit 7978801
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions compose/coin-plugins.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ARG COIN

FROM bitcart/bitcart-${COIN}:original

COPY plugins/daemons modules
COPY scripts/install-backend-plugins.sh /usr/local/bin/
RUN bash install-backend-plugins.sh
LABEL org.bitcart.plugins=true
1 change: 1 addition & 0 deletions generator/docker-components/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ services:
BITCART_BACKEND_PLUGINS_DIR: /plugins/backend
BITCART_ADMIN_PLUGINS_DIR: /plugins/admin
BITCART_STORE_PLUGINS_DIR: /plugins/store
BITCART_DAEMONS_PLUGINS_DIR: /plugins/daemons
BITCART_DOCKER_PLUGINS_DIR: /plugins/docker
BITCART_HOST: ${BITCART_HOST}
BITCART_ADMIN_HOST: ${BITCART_ADMIN_HOST}
Expand Down
1 change: 1 addition & 0 deletions generator/docker-components/worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ services:
BITCART_BACKEND_PLUGINS_DIR: /plugins/backend
BITCART_ADMIN_PLUGINS_DIR: /plugins/admin
BITCART_STORE_PLUGINS_DIR: /plugins/store
BITCART_DAEMONS_PLUGINS_DIR: /plugins/daemons
BITCART_DOCKER_PLUGINS_DIR: /plugins/docker
BITCART_HOST: ${BITCART_HOST}
BITCART_ADMIN_HOST: ${BITCART_ADMIN_HOST}
Expand Down
13 changes: 13 additions & 0 deletions generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,24 @@ def get_components_list():
return list(add_components(settings))


def get_cryptos_list(): # pragma: no cover
def get_crypto(crypto):
for coin in CRYPTOS:
if CRYPTOS[coin]["component"] == crypto:
return coin.lower()
return False

return [coin for component in get_components_list() if (coin := get_crypto(component))]


def main(): # pragma: no cover
try:
if len(sys.argv) == 2 and sys.argv[1] == "--components-only":
print(" ".join(get_components_list()))
return
if len(sys.argv) == 2 and sys.argv[1] == "--cryptos-only":
print(" ".join(get_cryptos_list()))
return
save(generate_config())
except ConfigError as e:
sys.exit(str(e))
Expand Down
14 changes: 14 additions & 0 deletions helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ bitcart_reset_plugins() {
export ADMIN_PLUGINS_HASH=
export STORE_PLUGINS_HASH=
export BACKEND_PLUGINS_HASH=
export DAEMONS_PLUGINS_HASH=
export DOCKER_PLUGINS_HASH=
}

Expand Down Expand Up @@ -234,6 +235,7 @@ SCRIPTS_POSTFIX=$SCRIPTS_POSTFIX
ADMIN_PLUGINS_HASH=$(get_plugins_hash admin)
STORE_PLUGINS_HASH=$(get_plugins_hash store)
BACKEND_PLUGINS_HASH=$(get_plugins_hash backend)
DAEMONS_PLUGINS_HASH=$(get_plugins_hash daemons)
DOCKER_PLUGINS_HASH=$(get_plugins_hash docker)
EOF
chmod +x ${BITCART_DEPLOYMENT_CONFIG}
Expand All @@ -254,6 +256,7 @@ make_backup_image() {

install_plugins() {
COMPONENTS=$(./build.sh --components-only | tail -1)
COIN_COMPONENTS=$(./build.sh --cryptos-only | tail -1)
failed_file="/var/lib/docker/volumes/$(volume_name "bitcart_datadir")/_data/.plugins-failed"
error=false
rm -f $failed_file
Expand All @@ -266,6 +269,9 @@ install_plugins() {
if [[ " ${COMPONENTS[*]} " =~ " store " ]]; then
make_backup_image bitcart/bitcart-store
fi
for coin in $COIN_COMPONENTS; do
make_backup_image bitcart/bitcart-$coin
done
if [[ "$DOCKER_PLUGINS_HASH" != "$(get_plugins_hash docker)" ]]; then
./build.sh || touch $failed_file
docker compose -f compose/generated.yml config || touch $failed_file
Expand All @@ -279,6 +285,11 @@ install_plugins() {
if [[ "$error" = false ]] && [[ " ${COMPONENTS[*]} " =~ " store " ]] && [[ "$STORE_PLUGINS_HASH" != "$(get_plugins_hash store)" ]]; then
docker build -t bitcart/bitcart-store:stable -f compose/store-plugins.Dockerfile compose || error=true
fi
if [[ "$error" = false ]] && [[ "$DAEMONS_PLUGINS_HASH" != "$(get_plugins_hash daemons)" ]]; then
for coin in $COIN_COMPONENTS; do
docker build -t bitcart/bitcart-$coin:stable -f compose/coin-plugins.Dockerfile compose --build-arg COIN=$coin || error=true
done
fi
if [[ "$error" = true ]]; then
echo "Plugins installation failed, restoring original images"
if [[ " ${COMPONENTS[*]} " =~ " backend " ]]; then
Expand All @@ -290,6 +301,9 @@ install_plugins() {
if [[ " ${COMPONENTS[*]} " =~ " store " ]]; then
docker tag bitcart/bitcart-store:original bitcart/bitcart-store:stable
fi
for coin in $COIN_COMPONENTS; do
docker tag bitcart/bitcart-$coin:original bitcart/bitcart-$coin:stable
done
touch $failed_file
fi
save_deploy_config
Expand Down

0 comments on commit 7978801

Please sign in to comment.