Skip to content

Commit

Permalink
Merge pull request #35 from hngprojects/main-interns
Browse files Browse the repository at this point in the history
Main interns
  • Loading branch information
dominic-source authored Jul 31, 2024
2 parents b3d9ba1 + 65f0abe commit 6e9dd1f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion pr-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,29 @@ echo "Running docker container..."
sudo docker run -d -p $FREE_PORT:$EXPOSED_PORT --name $PR_ID $PR_ID

echo "Start SSH session..."

# Checks if serveo
check_serveo() {
grep -q "ssh: connect to host serveo.net port 22: Connection refused" serveo_output.log || grep -q "ssh: connect to host serveo.net port 22: Connection timed out" serveo_output.log
}

# Set up tunneling using Serveo with a random high-numbered port
nohup ssh -tt -o StrictHostKeyChecking=no -R 80:localhost:$FREE_PORT serveo.net > serveo_output.log 2>&1 &
sleep 3

DEPLOYED_URL=$(grep "Forwarding HTTP traffic from" serveo_output.log | tail -n 1 | awk '{print $5}')
# Check if Serveo tunnel was set up successfully
if [ check_serveo ]; then
DEPLOYED_URL=$(grep "Forwarding HTTP traffic from" serveo_output.log | tail -n 1 | awk '{print $5}')
else
nohup ssh -tt -o StrictHostKeyChecking=no -R 80:localhost:$FREE_PORT ssh.localhost.run > localhost_run_output.log 2>&1 &
sleep 3
if grep -q "Connect to" localhost_run_output.log; then
DEPLOYED_URL=$(grep "https://" localhost_run_output.log | tail -n 1 | awk '{print $NF}')
else
DEPLOYED_URL=""
fi
fi


# Output the final JSON
echo "{\"COMMENT_ID\": \"$COMMENT_ID\", \"DEPLOYED_URL\": \"$DEPLOYED_URL\"}"

0 comments on commit 6e9dd1f

Please sign in to comment.