Skip to content

Update build.sh #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ README_URL="https://github.com/oracle-quickstart/db-endpoint-latency-testing-amm

set -e

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

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

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

echo "🚦 [4/4] Launching app with uvicorn (running at http://localhost:8000)..."
if uvicorn app.main:app --host 0.0.0.0 --port 8000
then
echo "✅ App launched."
echo "� [4/5] Generating self-signed SSL certificate if not present..."
SSL_DIR="ssl"
KEY_FILE="$SSL_DIR/key.pem"
CERT_FILE="$SSL_DIR/cert.pem"

if ! command -v openssl &> /dev/null; then
echo "❌ OpenSSL is required for SSL certificate generation but is not installed."
echo "Refer to manual setup: $README_URL"
exit 1
fi

mkdir -p "$SSL_DIR"
if [[ -f "$KEY_FILE" && -f "$CERT_FILE" ]]; then
echo "✅ SSL certificate and key found."
else
echo "Generating self-signed cert/key. Expect prompts for certificate info."
openssl req -x509 -nodes -days 825 -newkey rsa:2048 \
-keyout "$KEY_FILE" -out "$CERT_FILE" \
-subj "/C=US/ST=Self/L=Self/O=Self/CN=localhost"
if [[ $? -eq 0 ]]; then
echo "✅ SSL certificate generated."
else
echo "❌ Failed to generate SSL certificate."
echo "Refer to manual setup: $README_URL"
exit 1
fi
fi

echo "🚦 [5/5] Launching app with uvicorn (https://localhost:8000, self-signed SSL)..."
if uvicorn app.main:app --host 0.0.0.0 --port 8000 --ssl-keyfile "$KEY_FILE" --ssl-certfile "$CERT_FILE"; then
echo "✅ App launched with HTTPS."
else
echo "❌ Failed to launch the app. Please check above for errors."
echo "Refer to manual setup: $README_URL"
Expand Down