Spaces:
Running
Running
| # | |
| # One-shot deploy script for the LookUP IT chatbot on an | |
| # Amazon Linux 2023 Lightsail instance (IPv6-only). | |
| # | |
| # RUN THIS ON THE SERVER (the black "Connect using SSH" browser window), | |
| # NOT on your Windows laptop. | |
| # | |
| # Usage (on the server): | |
| # cd ~/chatbot_lookupit | |
| # bash deploy/deploy.sh | |
| # | |
| set -euo pipefail | |
| DOMAIN="chat.lookupitaibot.com" | |
| EMAIL="lookupit8013@gmail.com" # used for the Let's Encrypt account | |
| APP_DIR="$HOME/chatbot_lookupit" | |
| IMAGE="chatbot-lookupit" | |
| echo "==> 0. Sanity check: are we on Linux?" | |
| if [[ "$(uname -s)" != "Linux" ]]; then | |
| echo "!! This script must run on the Amazon Linux server, not on Windows." >&2 | |
| exit 1 | |
| fi | |
| echo "==> 1. Installing Docker, git, nginx, certbot ..." | |
| sudo dnf update -y | |
| sudo dnf install -y docker git nginx certbot python3-certbot-nginx | |
| sudo systemctl enable --now docker | |
| sudo systemctl enable --now nginx | |
| sudo usermod -aG docker "$USER" || true | |
| cd "$APP_DIR" | |
| echo "==> 2. Checking for .env (your secrets) ..." | |
| if [[ ! -f .env ]]; then | |
| echo "!! No .env file found in $APP_DIR." | |
| echo " Create it first with: nano .env" | |
| echo " (paste your GROQ_API_KEY, SMTP_*, FIREBASE_CREDENTIALS_JSON, etc.)" | |
| exit 1 | |
| fi | |
| echo "==> 3. Building the Docker image ..." | |
| sudo docker build -t "$IMAGE" . | |
| echo "==> 4. (Re)starting the container ..." | |
| sudo docker rm -f chatbot 2>/dev/null || true | |
| sudo docker run -d \ | |
| --name chatbot \ | |
| --restart unless-stopped \ | |
| --env-file .env \ | |
| -p 127.0.0.1:7860:7860 \ | |
| "$IMAGE" | |
| echo "==> 5. Waiting for the app to come up ..." | |
| sleep 5 | |
| if curl -fsS http://127.0.0.1:7860/ >/dev/null; then | |
| echo " App is responding on 127.0.0.1:7860 ✓" | |
| else | |
| echo "!! App did not respond. Check logs: sudo docker logs chatbot" | |
| exit 1 | |
| fi | |
| echo "==> 6. Configuring nginx reverse proxy for $DOMAIN ..." | |
| sudo cp deploy/nginx-chatbot.conf /etc/nginx/conf.d/chatbot.conf | |
| sudo sed -i "s/chat\.lookupitaibot\.com/$DOMAIN/g" /etc/nginx/conf.d/chatbot.conf | |
| sudo nginx -t | |
| sudo systemctl reload nginx | |
| echo "==> 7. Requesting HTTPS certificate (Let's Encrypt) ..." | |
| sudo certbot --nginx -d "$DOMAIN" --agree-tos -m "$EMAIL" --redirect -n || { | |
| echo "!! Certbot failed. Make sure:" | |
| echo " - Lightsail IPv6 firewall has ports 80 and 443 open" | |
| echo " - $DOMAIN resolves (AAAA) to this instance" | |
| exit 1 | |
| } | |
| echo "" | |
| echo "============================================================" | |
| echo " Done! Your chatbot is live at: https://$DOMAIN" | |
| echo " Update later with: cd ~/chatbot_lookupit && git pull && bash deploy/update.sh" | |
| echo " (or just push to main — GitHub Actions deploys automatically)" | |
| echo "============================================================" | |