Skip to content

Commit 3fa7b1a

Browse files
Merge pull request #38 from shadab-mohammad-oracle/patch-5
Update build.sh
2 parents f4939dc + 3f5b78c commit 3fa7b1a

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

build.sh

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ README_URL="https://github.com/oracle-quickstart/db-endpoint-latency-testing-amm
44

55
set -e
66

7-
echo "🔧 [1/4] Creating Python virtual environment (.venv)..."
7+
echo "🔧 [1/5] Creating Python virtual environment (.venv)..."
88
if python3 -m venv .venv; then
99
echo "✅ Virtual environment created."
1010
else
@@ -13,7 +13,7 @@ else
1313
exit 1
1414
fi
1515

16-
echo "🔧 [2/4] Activating virtual environment..."
16+
echo "🔧 [2/5] Activating virtual environment..."
1717
# shellcheck source=/dev/null
1818
if source .venv/bin/activate 2>/dev/null; then
1919
echo "✅ Virtual environment activated."
@@ -23,7 +23,7 @@ else
2323
exit 1
2424
fi
2525

26-
echo "🔧 [3/4] Installing requirements from requirements.txt..."
26+
echo "🔧 [3/5] Installing requirements from requirements.txt..."
2727
if pip install --upgrade pip > /dev/null 2>&1 && pip install -r requirements.txt; then
2828
echo "✅ Dependencies installed."
2929
else
@@ -32,10 +32,37 @@ else
3232
exit 1
3333
fi
3434

35-
echo "🚦 [4/4] Launching app with uvicorn (running at http://localhost:8000)..."
36-
if uvicorn app.main:app --host 0.0.0.0 --port 8000
37-
then
38-
echo "✅ App launched."
35+
echo "� [4/5] Generating self-signed SSL certificate if not present..."
36+
SSL_DIR="ssl"
37+
KEY_FILE="$SSL_DIR/key.pem"
38+
CERT_FILE="$SSL_DIR/cert.pem"
39+
40+
if ! command -v openssl &> /dev/null; then
41+
echo "❌ OpenSSL is required for SSL certificate generation but is not installed."
42+
echo "Refer to manual setup: $README_URL"
43+
exit 1
44+
fi
45+
46+
mkdir -p "$SSL_DIR"
47+
if [[ -f "$KEY_FILE" && -f "$CERT_FILE" ]]; then
48+
echo "✅ SSL certificate and key found."
49+
else
50+
echo "Generating self-signed cert/key. Expect prompts for certificate info."
51+
openssl req -x509 -nodes -days 825 -newkey rsa:2048 \
52+
-keyout "$KEY_FILE" -out "$CERT_FILE" \
53+
-subj "/C=US/ST=Self/L=Self/O=Self/CN=localhost"
54+
if [[ $? -eq 0 ]]; then
55+
echo "✅ SSL certificate generated."
56+
else
57+
echo "❌ Failed to generate SSL certificate."
58+
echo "Refer to manual setup: $README_URL"
59+
exit 1
60+
fi
61+
fi
62+
63+
echo "🚦 [5/5] Launching app with uvicorn (https://localhost:8000, self-signed SSL)..."
64+
if uvicorn app.main:app --host 0.0.0.0 --port 8000 --ssl-keyfile "$KEY_FILE" --ssl-certfile "$CERT_FILE"; then
65+
echo "✅ App launched with HTTPS."
3966
else
4067
echo "❌ Failed to launch the app. Please check above for errors."
4168
echo "Refer to manual setup: $README_URL"

0 commit comments

Comments
 (0)