mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-26 05:38:11 +08:00
Collect all env vars in one, easy-to-find place (#1149)
* Collect all env vars in one, easy-to-find place Past state: * Default environement variables were stored in both client/package.json and client/__tests__/e2e/config.js * Constants that should have been linked--like the cellxgene server port during testing--were repeated. With this commit: * All environment variables are parameterized * All environment variables are packaged in default env files * Move npm scripts to client Makefile * Respond to feedback from @seve and @bkmartinjr
This commit is contained in:
Executable
+58
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import errno
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
|
||||
# await_port
|
||||
#
|
||||
# Functionality:
|
||||
# 1. Wait for a process to be listening on a port - await_port will poll the address with a bind request and close it
|
||||
# until another process takes the address.
|
||||
# 2. Wait for a port to be free - await_port will poll the address with a bind request and close it until the port is
|
||||
# free.
|
||||
|
||||
parser = argparse.ArgumentParser(description='Wait for a port either to be bound to or to be free.')
|
||||
parser.add_argument('port', type=int, help='port to wait for')
|
||||
parser.add_argument('--sleep-increment', type=int, default=2.0, help='sleep duration in between checks of the port')
|
||||
parser.add_argument('--timeout', type=int, default=20.0, help='How long should we wait before timing out?')
|
||||
parser.add_argument('--await-free', default=False, action='store_true',
|
||||
help='Wait for the port to be active or free?')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
start = time.time()
|
||||
|
||||
port_in_use = None
|
||||
|
||||
desired_state = 'free' if args.await_free else 'in use'
|
||||
|
||||
|
||||
def condition_reached(port_in_use):
|
||||
return not port_in_use if args.await_free else port_in_use
|
||||
|
||||
|
||||
while True:
|
||||
# halt if we've reached the timeout
|
||||
elapsed = time.time() - start
|
||||
if elapsed > args.timeout:
|
||||
print(f"Timed out while waiting for port {args.port}")
|
||||
sys.exit(1)
|
||||
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
try:
|
||||
s.bind(('localhost', args.port))
|
||||
port_in_use = False
|
||||
except socket.error as e:
|
||||
if e.errno != errno.EADDRINUSE:
|
||||
raise e
|
||||
port_in_use = True
|
||||
|
||||
if condition_reached(port_in_use):
|
||||
break
|
||||
|
||||
print(f"Waiting for port {args.port} to be {desired_state}... sleeping for {args.sleep_increment} seconds.")
|
||||
time.sleep(args.sleep_increment)
|
||||
|
||||
print(f"Port {args.port} is {desired_state}!")
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# start_server_and_test
|
||||
# Replicates the basic functionality of the start-server-and-test npm package
|
||||
# https://www.npmjs.com/package/start-server-and-test
|
||||
|
||||
if [[ $# -ne 3 ]]; then
|
||||
echo "Usage: start_server_and_test \'[start server script]\' [port] \'[test script]\'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
START_SERVER_SCRIPT="$1"
|
||||
PORT="$2"
|
||||
TEST_SCRIPT="$3"
|
||||
|
||||
eval "$START_SERVER_SCRIPT &"
|
||||
SERVER_PID=$!
|
||||
|
||||
function finish {
|
||||
kill $SERVER_PID || true
|
||||
}
|
||||
|
||||
trap finish EXIT
|
||||
|
||||
await_port "$PORT"
|
||||
|
||||
eval "$TEST_SCRIPT"
|
||||
Reference in New Issue
Block a user