Skip to content

Commit

Permalink
Update redeploy.sh (#3141)
Browse files Browse the repository at this point in the history
  • Loading branch information
wwzeng1 authored Feb 23, 2024
1 parent c749b80 commit b0a5427
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions bin/redeploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
# Remove old docker images only after 2 runs to allow for rollbacks.
# Docker images also need to finish processing their requests before they can be removed.
echo `docker ps`
containers_to_remove=$(docker ps -q | awk 'NR>3')
containers_to_remove=$(docker ps -q | awk 'NR>2')

if [ ! -z "$containers_to_remove" ]; then
echo "Removing old docker runs"
docker kill -f $containers_to_remove
docker rm -f $containers_to_remove
else
echo "No old docker runs to remove"
Expand All @@ -15,8 +16,11 @@ fi
# Find next available port to deploy to
PORT=8081
is_port_free() {
lsof -i :$1 > /dev/null
return $?
if curl -s http://localhost:$1 > /dev/null; then
return 0 # Port is in use
else
return 1 # Port is free
fi
}

while is_port_free $PORT; do
Expand All @@ -26,8 +30,8 @@ done
echo "Found open port: $PORT"

# Start new docker container on the next available port
cd ~/sweep
docker run --env-file .env -p $PORT:8080 -d sweepai/sweep.hosted
cd /app
docker run --env-file env -p $PORT:8080 -d sweepai/sweep.hosted:latest

sleep 5

Expand All @@ -49,5 +53,8 @@ done
sudo iptables -t nat -L PREROUTING --line-numbers | grep 'REDIRECT' | tail -n1 | awk '{print $1}' | xargs -I {} sudo iptables -t nat -D PREROUTING {}
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port $PORT

# kill previous docker image after 20 min
(sleep 1200 && docker kill $(docker ps -q | awk 'NR>1')) &

echo "Command sent to screen session on port: $PORT"
echo "Success!"

0 comments on commit b0a5427

Please sign in to comment.