

PEM_PATH=~/aws/hope.pem
NEW_ARCH_NAME=to_send.tar.gz
LAST_STATE_FOLDER=last_state/

# 1. compress
tar -czvf $NEW_ARCH_NAME _prod

# 2. send to server
scp -i $PEM_PATH $NEW_ARCH_NAME ubuntu@palladineve.com:/home/ubuntu

# 6. extract
ssh ubuntu@palladineve.com -i $PEM_PATH "tar -xzvf $NEW_ARCH_NAME && rm $NEW_ARCH_NAME"

# remove local files
rm $NEW_ARCH_NAME

# prare state
ssh ubuntu@palladineve.com -i $PEM_PATH "cp -r $LAST_STATE_FOLDER/pb_data _prod/be"
ssh ubuntu@palladineve.com -i $PEM_PATH "cp -r $LAST_STATE_FOLDER/downloaded_etf _prod/be"

# 7. start service
ssh ubuntu@palladineve.com -i $PEM_PATH "cd _prod && sudo docker compose up -d"
ssh ubuntu@palladineve.com -i $PEM_PATH "cd _prod && sudo caddy stop && sudo caddy start"