feat: option to deploy with a proxy

This commit is contained in:
17ms 2024-08-15 22:43:26 +03:00
parent 6dea9fad14
commit ec38a2c35b
Signed by untrusted user who does not match committer: ae
GPG Key ID: 995EFD5C1B532B3E
3 changed files with 25 additions and 3 deletions

View File

@ -52,6 +52,10 @@ def load_cfg(dotenv_path=".env"):
return cfg
def get_ip(addr=const.IP_TEST_ADDR):
return requests.get(addr, timeout=10).text.strip()
def main():
cfg = load_cfg()
@ -66,6 +70,7 @@ def main():
logging.info("MODE: %s", cfg.mode)
logging.info("EXPORT_INTERVAL: %d (seconds)", cfg.export_interval)
logging.info("IS_EXPORT: %r", cfg.is_export)
logging.info("IP: %s", get_ip())
# Information for debugging issues caused by potential version differences
logging.info("Python version: %s", sys.version)

View File

@ -1,3 +1,4 @@
aioprocessing==2.0.1
python-dotenv==1.0.1
Requests==2.32.3
websockets==12.0

View File

@ -2,8 +2,10 @@
AUTOREMOVE=false
VOLUME_PATH="./data" # Local path to the volume's mount point
IS_PROXIED=false
PROXY=""
while getopts ":hy" opt
while getopts ":hyp:" opt
do
case "$opt" in
h)
@ -14,6 +16,11 @@ do
echo -e "[+] Automatically removing all containers with the same tag (if any)\n"
AUTOREMOVE=true
;;
p)
IS_PROXIED=true
PROXY=${OPTARG}
echo -e "[+] Proxying enabled: $PROXY"
;;
*)
exit 1
;;
@ -28,18 +35,27 @@ docker build --no-cache -t chainmapper .
[ ! -d "./data" ] && mkdir data && echo -e "\n[+] Created the default volume directory 'data'"
OLD_ID=$(docker ps -a -q -f name="chainmapper-prod")
OLD_ID=$(docker ps -a -q -f name="chainmapper")
if [ "$OLD_ID" ] && [ "$AUTOREMOVE" = true ]
then
echo -e "\n[+] Removing existing container with the same tag ($OLD_ID)"
docker stop "$OLD_ID" &> /dev/null
docker rm "$OLD_ID" &> /dev/null
elif [ "$OLD_ID" ]
then
read -p "[?] Existing container found with id '$OLD_ID', do you want to remove it? " -n 1 -r
[[ "$REPLY" =~ ^[Yy]$ ]] || (echo "[!] Exiting..." && exit 0)
docker stop "$OLD_ID" &> /dev/null
docker rm "$OLD_ID" &> /dev/null
fi
echo -e "\n[+] Deploying the container with 'docker run' ('data' as the volume)..."
docker run -it --restart unless-stopped -v $VOLUME_PATH:/app/data --name chainmapper-prod -d chainmapper
if [ "$IS_PROXIED" = true ]
then
# Override the default entrypoint to run the connections through the given proxy
docker run -it --restart unless-stopped -v $VOLUME_PATH:/app/data --name chainmapper --entrypoint /bin/bash -d chainmapper -c "HTTPS_PROXY=$PROXY python main.py"
else
docker run -it --restart unless-stopped -v $VOLUME_PATH:/app/data --name chainmapper -d chainmapper
fi