Skip to content

Commit

Permalink
Added a script for semi-automated docker_setup
Browse files Browse the repository at this point in the history
  • Loading branch information
NovusEdge committed Apr 10, 2021
1 parent 8b63f44 commit 50b5ada
Showing 1 changed file with 53 additions and 65 deletions.
118 changes: 53 additions & 65 deletions docker_setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import os
import pathlib
import shutil
import subprocess
import pathlib
import sys

import colorama
import os

PATH = pathlib.Path(__file__).parent.absolute()
os.chdir(PATH)


COLORS = {
"R": colorama.Fore.RED,
"G": colorama.Fore.GREEN,
Expand All @@ -17,68 +15,58 @@
}


def color_copy_file(src: str, dest: str):
def make_image() -> None:
subprocess.run('docker build' args=['--no-cache', '-t', 'BTBMT', '.'], shell=True)

def delete_image() -> None:
subprocess.run('docker' args=['rmi', '-f', 'BTBMT'], shell=True)

def update_image() -> None:
delete_image()
make_image()



def auto_run() -> None:
print(f"{COLORS['Y']}[*] Setting things up for docker...{COLORS['RESET']}")
try:
shutil.copyfile(src, dest)
print(f"{COLORS['G']}[+] Copying {src} to {dest}{COLORS['RESET']}")
except Exception:
print(
f"{COLORS['R']}[-] Couldn't find the file: {src}\n"
f"\tPlease manually create it at {dest}{COLORS['RESET']}"
)


def main():
if not os.path.exists("binance-trade-bot"):
subprocess.call(
"git clone https://github.com/edeng23/binance-trade-bot >/dev/null",
shell=True,
)

isBTB = input(
f"{COLORS['Y']}[*] Is a Binance Trade Bot installation already present on your filesystem (y/n)?: {COLORS['RESET']}"
subprocess.run('docker', args=[ 'image', 'inspect', 'BTBMT'], check=True)
update_image()

except Exception as e:
make_image()


def main() -> None:
parser = argparse.ArgumentParser()

parser.add_argument(
'-m', '--make-image',
help="Create a docker image for the bot.", action="store_true"
)
parser.add_argument(
'-u', '--update-image',
help="Update the docker image for the bot.", action="store_true"
)
parser.add_argument(
'-D', '--delete-image',
help="Delete the docker image for the bot.", action="store_true"
)
if isBTB in ["y", "Y"]:
btb_installation_dir = input(
f"{COLORS['Y']}[*] Enter path to your previous Binance Trade bot installation (e.g. ../binance-trade-bot/): {COLORS['RESET']}"
)
os.path.exists(btb_installation_dir)

while not os.path.exists(btb_installation_dir):
btb_installation_dir = input(
f"{COLORS['R']}[-] Couldn't find the specified path on the filesystem, try again: {COLORS['RESET']}"
)
else:
print(
f"{COLORS['G']}[+] Path {btb_installation_dir} found on the filesystem.{COLORS['RESET']}"
)

color_copy_file(
os.path.join(btb_installation_dir, "user.cfg"),
"./binance-trade-bot/user.cfg",
)
color_copy_file(
os.path.join(btb_installation_dir, "supported_coin_list"),
"./binance-trade-bot/supported_coin_list",
)
color_copy_file(
os.path.join(btb_installation_dir, "config/apprise.yml"),
"./binance-trade-bot/config/apprise.yml",
)

elif isBTB in ["n", "N"]:

print(
f"{COLORS['Y']}[*] Please manually create/edit the following files:\n"
f"\t./binance-trade-bot/user.cfg\n"
f"\t./binance-trade-bot/supported_coin_list\n"
f"\t./binance-trade-bot/config/apprise.yml"
)

else:
sys.exit(-1)

print(f"{COLORS['G']}[*] All set!{COLORS['RESET']}")

args.parse_args()

if not any([args.update_image, args.delete_image, args.make_image]):
auto_run()
return

if args.update_image and not (args.delete_image or args.make_image):
update_image()

elif args.delete_image and not args.update_image:
delete_image()

elif args.make_image:
make_image()


if __name__ == "__main__":
Expand Down

0 comments on commit 50b5ada

Please sign in to comment.