From 5edde7f59f2ff4ff697edd3d141df9384f90cff3 Mon Sep 17 00:00:00 2001 From: Dominic Date: Wed, 31 Jul 2024 15:20:42 +0100 Subject: [PATCH 1/2] Update pr-deploy.sh Signed-off-by: Dominic --- pr-deploy.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pr-deploy.sh b/pr-deploy.sh index d869e525..310026fb 100644 --- a/pr-deploy.sh +++ b/pr-deploy.sh @@ -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\"}" From 65f0abec691ce7c9e4b437d3a86243ffc64c9d67 Mon Sep 17 00:00:00 2001 From: Dominic Date: Wed, 31 Jul 2024 15:29:46 +0100 Subject: [PATCH 2/2] Update pr-deploy.sh Signed-off-by: Dominic --- pr-deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr-deploy.sh b/pr-deploy.sh index 310026fb..c74204b0 100644 --- a/pr-deploy.sh +++ b/pr-deploy.sh @@ -93,7 +93,7 @@ nohup ssh -tt -o StrictHostKeyChecking=no -R 80:localhost:$FREE_PORT serveo.net sleep 3 # Check if Serveo tunnel was set up successfully -if [ ! check_serveo ]; then +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 &