Adding deployment to raspberrypi

This commit is contained in:
2026-03-17 16:53:19 -07:00
parent 51717b3d6f
commit 437ee886b7
7 changed files with 135 additions and 51 deletions

18
scripts/deploy.sh Normal file
View File

@@ -0,0 +1,18 @@
#!/bin/bash
set -e
REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)"
SERVICE_NAME="birdcam"
echo "Pulling latest code..."
cd "$REPO_DIR"
git pull origin main
echo "Installing dependencies..."
poetry install --without pi --no-dev
echo "Restarting service..."
sudo systemctl restart "$SERVICE_NAME"
sudo systemctl status "$SERVICE_NAME" --no-pager
echo "Deployed successfully."

43
scripts/setup_nginx.sh Normal file
View File

@@ -0,0 +1,43 @@
#!/bin/bash
set -e
DOMAIN="${1:-birdcam.letteka.com}"
SERVICE_PORT=8000
echo "Configuring nginx for $DOMAIN..."
sudo tee /etc/nginx/sites-available/birdcam > /dev/null <<EOF
server {
listen 80;
server_name ${DOMAIN} _;
# proxy to gunicorn
location / {
proxy_pass http://127.0.0.1:${SERVICE_PORT};
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_read_timeout 300s;
}
# serve HLS segments directly — bypasses gunicorn entirely
location /camera/hls/ {
alias /tmp/hls/;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
}
}
EOF
sudo ln -sf /etc/nginx/sites-available/birdcam \
/etc/nginx/sites-enabled/birdcam
sudo rm -f /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl reload nginx
echo "nginx configured — listening on port 80"

View File

@@ -8,7 +8,8 @@ sudo apt-get install -y \
python3-prctl \
python3-picamera2 \
python3-pil \
ffmpeg
ffmpeg \
nginx
echo "Configuring Poetry to use system site-packages..."
poetry config virtualenvs.options.system-site-packages true
@@ -17,7 +18,7 @@ echo "Removing existing venv to ensure clean state..."
poetry env remove python3 2>/dev/null || true
echo "Installing Python dependencies..."
poetry install --without pi
poetry install --without pi --no-dev
echo "Verifying picamera2 is accessible..."
poetry run python -c "import picamera2; print(f'picamera2 found at: {picamera2.__file__}')"

41
scripts/setup_service.sh Normal file
View File

@@ -0,0 +1,41 @@
#!/bin/bash
set -e
REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)"
SERVICE_NAME="birdcam"
USER="$(whoami)"
VENV_PYTHON="$(poetry env info --path)/bin/python"
GUNICORN="$(poetry env info --path)/bin/gunicorn"
echo "Installing systemd service..."
sudo tee /etc/systemd/system/${SERVICE_NAME}.service > /dev/null <<EOF
[Unit]
Description=Birdcam Flask Application
After=network.target
[Service]
User=${USER}
WorkingDirectory=${REPO_DIR}
ExecStart=${GUNICORN} \
--workers 2 \
--worker-class gthread \
--threads 4 \
--bind 127.0.0.1:8000 \
--access-logfile - \
--error-logfile - \
"src.app:app"
Restart=on-failure
RestartSec=5
Environment=PYTHONPATH=${REPO_DIR}
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable "$SERVICE_NAME"
sudo systemctl start "$SERVICE_NAME"
sudo systemctl status "$SERVICE_NAME" --no-pager
echo "Service installed and started."