# Deployment Guide — Lucas Weiss Photography

## Prerequisites
- AWS account with EC2 + S3 + CloudFront set up (see AWS Setup Guide)
- Domain pointing to your Elastic IP
- SSH access to your EC2 instance

---

## 1. Upload code to server

On your Windows PC, open PowerShell:

```powershell
# Copy the entire project to your server
scp -i "C:\path\to\lucas-weiss-key.pem" -r "C:\path\to\lucas-weiss-photography" ubuntu@YOUR_ELASTIC_IP:/home/ubuntu/
```

---

## 2. Configure environment variables

SSH into your server:
```bash
ssh -i "C:\path\to\lucas-weiss-key.pem" ubuntu@YOUR_ELASTIC_IP
```

Create your .env file:
```bash
cd /home/ubuntu/lucas-weiss-photography
cp .env.example .env
nano .env
```

Fill in your values:
- AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY from your IAM user CSV
- S3_BUCKET_NAME — your bucket name
- CLOUDFRONT_DOMAIN — your CloudFront URL e.g. https://d1234abcd.cloudfront.net
- JWT_SECRET — run: node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
- ADMIN_USERNAME — e.g. lucas
- ADMIN_PASSWORD_HASH — generate with: node server/hashpassword.js yourpassword

Save with Ctrl+X, Y, Enter

---

## 3. Install dependencies

```bash
cd /home/ubuntu/lucas-weiss-photography
npm install
```

---

## 4. Set up SSL certificate

Make sure your domain is pointing to your server first, then:

```bash
sudo certbot --nginx -d lucasweiss.com -d www.lucasweiss.com
```

Follow the prompts — certbot will automatically configure nginx for HTTPS.

---

## 5. Configure nginx

```bash
sudo cp /home/ubuntu/lucas-weiss-photography/nginx.conf /etc/nginx/sites-available/lucasweiss.com
sudo ln -s /etc/nginx/sites-available/lucasweiss.com /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl reload nginx
```

---

## 6. Start the Node.js app with PM2

```bash
cd /home/ubuntu/lucas-weiss-photography
pm2 start server/index.js --name "lucas-weiss-photography"
pm2 save
pm2 startup
# Run the command PM2 outputs to make it start on reboot
```

---

## 7. Upload your Gambetta fonts

In the AWS S3 console, upload your Gambetta .woff2 font files to:
```
s3://lucas-weiss-photography/fonts/
```

Then on your server, create a symlink so they're served:
```bash
mkdir -p /home/ubuntu/lucas-weiss-photography/public/fonts
```

Or better — download them from S3 to the server:
```bash
aws s3 sync s3://lucas-weiss-photography/fonts/ /home/ubuntu/lucas-weiss-photography/public/fonts/ --region us-east-1
```

---

## 8. Upload UI assets to S3

In the AWS S3 console, upload to the ui/ folder:
- background-texture.jpg
- logo-white.png
- logo-black.png

And all hero images to images/hero/

---

## 9. Set up the admin panel

Visit https://lucasweiss.com/admin
Log in with your username and password
Upload photos to each category via drag and drop

---

## 10. Set up the Windows folder watcher

On your Windows PC:

```powershell
# Install Python if you haven't already
# Download from python.org

# Install dependencies
pip install watchdog requests

# Edit the config
notepad C:\path\to\lucas-weiss-photography\watcher\config.json
# Update server_url, admin_username, admin_password
# Update folder paths to match where you keep your photos

# Test it works
cd C:\path\to\lucas-weiss-photography\watcher
python watcher.py
```

To run automatically on Windows startup:
1. Press Win+R → type `taskschd.msc`
2. Create Basic Task → name it "Photo Watcher"
3. Trigger: When I log on
4. Action: Start a program
5. Program: `pythonw.exe` (uses pythonw so no console window)
6. Arguments: `C:\path\to\watcher\watcher.py`
7. Finish

---

## Useful commands

```bash
# Check app status
pm2 status

# View logs
pm2 logs lucas-weiss-photography

# Restart app
pm2 restart lucas-weiss-photography

# Update code (after making changes)
# On your PC:
scp -i "key.pem" -r ./server ubuntu@YOUR_IP:/home/ubuntu/lucas-weiss-photography/
# On server:
pm2 restart lucas-weiss-photography

# Check nginx logs
sudo tail -f /var/log/nginx/error.log
sudo tail -f /var/log/nginx/access.log
```

---

## Updating the site

When you want to update front-end HTML/CSS/JS:
1. Edit files locally
2. SCP the public/ folder to the server
3. No restart needed — nginx serves them directly

When you update server code:
1. SCP the server/ folder
2. Run: pm2 restart lucas-weiss-photography
