205 lines
4.6 KiB
Markdown
205 lines
4.6 KiB
Markdown
# Deployment Guide for LXC Container
|
|
|
|
This guide explains how to deploy this Hugo website to an LXC container running Arch Linux (or similar). The site is built as a static site and served via nginx.
|
|
|
|
## Prerequisites
|
|
|
|
- LXC container with Arch Linux (or adjust package manager commands for your distribution)
|
|
- SSH access to the container
|
|
- Git installed on container
|
|
- Domain name `dustin.coffee` pointing to container's IP address (or adjust baseURL in `hugo.toml`)
|
|
|
|
## Step 1: Install Hugo on LXC
|
|
|
|
On the container, install Hugo (extended version recommended):
|
|
|
|
```bash
|
|
# For Arch Linux
|
|
sudo pacman -S hugo
|
|
|
|
# For Debian/Ubuntu
|
|
# sudo apt install hugo
|
|
|
|
# For other distributions, see https://gohugo.io/installation/
|
|
```
|
|
|
|
Verify installation:
|
|
```bash
|
|
hugo version
|
|
```
|
|
|
|
## Step 2: Clone Repository
|
|
|
|
Clone your git repository to a directory, e.g., `/srv/www/dustin.coffee`:
|
|
|
|
```bash
|
|
sudo mkdir -p /srv/www
|
|
sudo chown $USER:$USER /srv/www
|
|
cd /srv/www
|
|
git clone <your-git-repo-url> dustin.coffee
|
|
cd dustin.coffee
|
|
```
|
|
|
|
## Step 3: Build Static Site
|
|
|
|
Generate the static site:
|
|
|
|
```bash
|
|
hugo --minify
|
|
```
|
|
|
|
The built site will be in the `public/` directory.
|
|
|
|
## Step 4: Install and Configure nginx
|
|
|
|
Install nginx:
|
|
|
|
```bash
|
|
sudo pacman -S nginx
|
|
```
|
|
|
|
Create nginx configuration file at `/etc/nginx/sites-available/dustin.coffee` (create directory if needed):
|
|
|
|
```nginx
|
|
server {
|
|
listen 80;
|
|
listen [::]:80;
|
|
server_name dustin.coffee www.dustin.coffee;
|
|
|
|
root /srv/www/dustin.coffee/public;
|
|
index index.html;
|
|
|
|
# Security headers
|
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
|
|
# Gzip compression
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_min_length 1024;
|
|
gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json;
|
|
|
|
location / {
|
|
try_files $uri $uri/ =404;
|
|
}
|
|
|
|
# Cache static assets
|
|
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
|
|
expires 365d;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
}
|
|
```
|
|
|
|
Enable the site by creating a symlink:
|
|
|
|
```bash
|
|
sudo ln -s /etc/nginx/sites-available/dustin.coffee /etc/nginx/sites-enabled/
|
|
sudo nginx -t # Test configuration
|
|
sudo systemctl restart nginx
|
|
```
|
|
|
|
## Step 5: Set Up SSL with Let's Encrypt (Optional but Recommended)
|
|
|
|
Install certbot:
|
|
|
|
```bash
|
|
sudo pacman -S certbot certbot-nginx
|
|
```
|
|
|
|
Obtain certificate:
|
|
|
|
```bash
|
|
sudo certbot --nginx -d dustin.coffee -d www.dustin.coffee
|
|
```
|
|
|
|
Certbot will automatically update nginx configuration.
|
|
|
|
## Step 6: Automation Script
|
|
|
|
Create a deployment script `deploy.sh` in the repository root:
|
|
|
|
```bash
|
|
#!/bin/bash
|
|
# deploy.sh - rebuild and copy site
|
|
|
|
set -e
|
|
|
|
cd /srv/www/dustin.coffee
|
|
|
|
# Pull latest changes
|
|
git pull
|
|
|
|
# Build site
|
|
hugo --minify
|
|
|
|
# Optional: restart nginx if configuration changed
|
|
# sudo systemctl reload nginx
|
|
|
|
echo "Deployment completed at $(date)"
|
|
```
|
|
|
|
Make it executable:
|
|
|
|
```bash
|
|
chmod +x deploy.sh
|
|
```
|
|
|
|
Now after SSH-ing into the container, you can run `./deploy.sh` to update the site.
|
|
|
|
## Step 7: Systemd Service (Alternative: Hugo Server)
|
|
|
|
If you prefer to run Hugo as a server (not recommended for production), create a systemd service:
|
|
|
|
Create `/etc/systemd/system/hugo-dustin.service`:
|
|
|
|
```ini
|
|
[Unit]
|
|
Description=Hugo Server for dustin.coffee
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=www-data
|
|
Group=www-data
|
|
WorkingDirectory=/srv/www/dustin.coffee
|
|
ExecStart=/usr/bin/hugo server --bind 0.0.0.0 --port 1313 --baseURL=https://dustin.coffee/
|
|
Restart=on-failure
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
```
|
|
|
|
Then enable and start:
|
|
|
|
```bash
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable hugo-dustin
|
|
sudo systemctl start hugo-dustin
|
|
```
|
|
|
|
## Notes
|
|
|
|
- Update the `baseURL` in `hugo.toml` if your domain changes.
|
|
- The site uses a custom theme `personal`; ensure all theme files are committed to git.
|
|
- Blog posts are stored in `content/posts/` as markdown files.
|
|
- To add new blog posts, create markdown files in `content/posts/` on your development machine, push to git, then run the deploy script on the container.
|
|
|
|
## Troubleshooting
|
|
|
|
- If nginx shows 404, ensure the `public/` directory exists and contains built files.
|
|
- If Hugo fails to build, check Hugo version matches the one used in development.
|
|
- Check nginx error logs: `sudo journalctl -u nginx`
|
|
- Check Hugo build logs: run `hugo --verbose`
|
|
|
|
## Updating
|
|
|
|
To update the site after making changes on your development machine:
|
|
|
|
1. Push changes to your git server
|
|
2. SSH into LXC container
|
|
3. Navigate to site directory: `cd /srv/www/dustin.coffee`
|
|
4. Run `git pull` then `./deploy.sh` (or just `hugo --minify`)
|
|
|