Skip to content

gitpod-samples/wait-for-port-and-open-browser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

"Wait for Port" Example

This repo holds the wait-for-port.sh script, which is a helper script that can be used in Gitpod automaitons and elsewhere to run your own code after a service has started to listen on a port.

Example 1: Foreground Waiting

Use this if you start the service that opens the port in a different terminal or task

./wait-for-port.sh 8080
URL=$(gitpod env ports list -o json | jq -r '.[] | select(.port==8080).url')
[ -z "$URL" ] && echo "port 8080 not opened in Gitpod"
code --openExternal "$URL"

Example 2: Background Waiting

Use this if you start the service that opens the port in a the same terminal or task

(
  ./wait-for-port.sh 8080
  URL=$(gitpod env ports list -o json | jq -r '.[] | select(.port==8080).url')
  [ -z "$URL" ] && echo "port 8080 not opened in Gitpod"
  code --openExternal "$URL"
) &   # background the whole subshell

# …then start the real server in the foreground
python3 -m http.server 8080

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages