Deploy
All checks were successful
Build and Deploy Hugo Site / build-and-deploy (push) Successful in 14s
All checks were successful
Build and Deploy Hugo Site / build-and-deploy (push) Successful in 14s
This commit is contained in:
@@ -1,19 +1,38 @@
|
|||||||
name: Gitea Actions Demo
|
name: Build and Deploy Hugo Site
|
||||||
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
|
run-name: ${{ gitea.actor }} is deploying to production
|
||||||
on: [push]
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Explore-Gitea-Actions:
|
build-and-deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event."
|
- name: Checkout repository
|
||||||
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!"
|
|
||||||
- run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
|
|
||||||
- name: Check out repository code
|
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner."
|
|
||||||
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
|
- name: Setup Hugo
|
||||||
- name: List files in the repository
|
uses: peaceiris/actions-hugo@v3
|
||||||
|
with:
|
||||||
|
hugo-version: 'latest'
|
||||||
|
extended: true
|
||||||
|
|
||||||
|
- name: Build Hugo site
|
||||||
|
run: hugo --minify
|
||||||
|
|
||||||
|
- name: Setup SSH
|
||||||
run: |
|
run: |
|
||||||
ls ${{ gitea.workspace }}
|
mkdir -p ~/.ssh
|
||||||
- run: echo "🍏 This job's status is ${{ job.status }}."
|
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa
|
||||||
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
ssh-keyscan -H ${{ secrets.HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
- name: Deploy to production
|
||||||
|
run: |
|
||||||
|
scp -r public/* ${{ secrets.USERNAME }}@${{ secrets.HOST }}:/var/www/sometimescode.com/
|
||||||
|
|
||||||
|
- name: Cleanup
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
rm -f ~/.ssh/id_rsa
|
||||||
110
README.md
110
README.md
@@ -28,33 +28,106 @@ hugo new content posts/my-new-post.md
|
|||||||
```
|
```
|
||||||
├── content/
|
├── content/
|
||||||
│ ├── posts/ # Blog posts
|
│ ├── posts/ # Blog posts
|
||||||
│ └── resume.md # Resume page
|
│ └── pages/ # Static pages (resume, etc.)
|
||||||
├── themes/ananke/ # Hugo theme (git submodule)
|
├── themes/
|
||||||
|
│ └── sometimescode/ # Custom theme
|
||||||
├── hugo.toml # Site configuration
|
├── hugo.toml # Site configuration
|
||||||
└── .github/workflows/ # Deployment automation
|
└── .gitea/workflows/ # Gitea Actions for CI/CD
|
||||||
```
|
```
|
||||||
|
|
||||||
## Deployment
|
## Deployment
|
||||||
|
|
||||||
### Digital Ocean Setup
|
### Automatic Deployment (Gitea Actions)
|
||||||
|
|
||||||
|
The site automatically builds and deploys when you push to the `main` branch using Gitea Actions.
|
||||||
|
|
||||||
|
#### Required Gitea Secrets
|
||||||
|
|
||||||
|
Configure these secrets in your Gitea repository settings (Settings → Secrets):
|
||||||
|
|
||||||
|
1. **`SSH_KEY`**: Private SSH key for deployment authentication
|
||||||
|
```bash
|
||||||
|
# Generate a new SSH key pair on the host server
|
||||||
|
ssh-keygen -t ed25519 -C "gitea-deploy@sometimescode.com" -f ~/.ssh/gitea_deploy
|
||||||
|
|
||||||
|
# Copy the PRIVATE key content (this goes in Gitea secrets)
|
||||||
|
cat ~/.ssh/gitea_deploy
|
||||||
|
|
||||||
|
# Add the PUBLIC key to authorized_keys on the host
|
||||||
|
cat ~/.ssh/gitea_deploy.pub >> ~/.ssh/authorized_keys
|
||||||
|
chmod 600 ~/.ssh/authorized_keys
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **`HOST`**: IP address to reach the host from the Docker worker
|
||||||
|
- **Same-host deployment**: Use `172.17.0.1` (Docker bridge gateway IP)
|
||||||
|
- **Remote server**: Use the actual server IP or hostname
|
||||||
|
|
||||||
|
3. **`USERNAME`**: SSH username on the deployment server
|
||||||
|
- Example: `www-data`, `ubuntu`, or `deploy`
|
||||||
|
|
||||||
|
**Important for same-host deployment**: When your Gitea worker runs in Docker on the same machine as your web server, use `172.17.0.1` as the HOST. This is the default Docker bridge network IP that allows containers to reach the host machine.
|
||||||
|
|
||||||
|
#### How It Works
|
||||||
|
|
||||||
|
1. Push to `main` branch triggers the workflow
|
||||||
|
2. Gitea worker (Docker container) checks out the code
|
||||||
|
3. Hugo extended is installed via the peaceiris/actions-hugo action
|
||||||
|
4. Site is built with `hugo --minify`
|
||||||
|
5. SSH connection is established to the host (via `172.17.0.1` for same-host)
|
||||||
|
6. Built files in `public/` are copied via SCP to `/var/www/sometimescode.com/`
|
||||||
|
7. SSH keys are cleaned up after deployment
|
||||||
|
|
||||||
|
### Server Setup
|
||||||
|
|
||||||
1. **Server Requirements**:
|
1. **Server Requirements**:
|
||||||
- Ubuntu 22.04+ droplet
|
- Ubuntu 22.04+ or similar Linux server
|
||||||
- Nginx installed
|
- Nginx or Caddy web server
|
||||||
- SSL certificate (use certbot)
|
- SSL certificate (automatic with Caddy, or use certbot with Nginx)
|
||||||
|
|
||||||
2. **GitHub Secrets** (for automatic deployment):
|
2. **Prepare deployment directory**:
|
||||||
- `DO_HOST`: Your server IP or domain
|
|
||||||
- `DO_USERNAME`: SSH username (usually `root` or `ubuntu`)
|
|
||||||
- `DO_SSH_KEY`: Private SSH key for server access
|
|
||||||
|
|
||||||
3. **Server Setup**:
|
|
||||||
```bash
|
```bash
|
||||||
# Create web directory
|
# Create web directory
|
||||||
sudo mkdir -p /var/www/sometimescode.com
|
sudo mkdir -p /var/www/sometimescode.com
|
||||||
|
|
||||||
# Copy nginx config
|
# Set appropriate permissions for your deploy user
|
||||||
sudo cp nginx-example.conf /etc/nginx/sites-available/sometimescode.com
|
sudo chown -R deploy-user:deploy-user /var/www/sometimescode.com
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Configure Web Server**:
|
||||||
|
|
||||||
|
**Option A: Caddy (Recommended - automatic HTTPS)**
|
||||||
|
```bash
|
||||||
|
# Install Caddy if not already installed
|
||||||
|
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
|
||||||
|
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
|
||||||
|
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install caddy
|
||||||
|
|
||||||
|
# Edit Caddyfile
|
||||||
|
sudo nano /etc/caddy/Caddyfile
|
||||||
|
```
|
||||||
|
|
||||||
|
Add this configuration:
|
||||||
|
```caddy
|
||||||
|
sometimescode.com {
|
||||||
|
root * /var/www/sometimescode.com
|
||||||
|
file_server
|
||||||
|
encode gzip
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Reload Caddy
|
||||||
|
sudo systemctl reload caddy
|
||||||
|
```
|
||||||
|
|
||||||
|
**Option B: Nginx (manual SSL setup)**
|
||||||
|
```bash
|
||||||
|
# Create nginx config
|
||||||
|
sudo nano /etc/nginx/sites-available/sometimescode.com
|
||||||
|
|
||||||
|
# Enable site
|
||||||
sudo ln -s /etc/nginx/sites-available/sometimescode.com /etc/nginx/sites-enabled/
|
sudo ln -s /etc/nginx/sites-available/sometimescode.com /etc/nginx/sites-enabled/
|
||||||
|
|
||||||
# Get SSL certificate
|
# Get SSL certificate
|
||||||
@@ -66,6 +139,8 @@ hugo new content posts/my-new-post.md
|
|||||||
|
|
||||||
### Manual Deployment
|
### Manual Deployment
|
||||||
|
|
||||||
|
If needed, you can still deploy manually:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Build site
|
# Build site
|
||||||
hugo --minify
|
hugo --minify
|
||||||
@@ -76,10 +151,11 @@ scp -r public/* user@server:/var/www/sometimescode.com/
|
|||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
- **Theme**: [Ananke](https://github.com/theNewDynamic/gohugo-theme-ananke) with custom dark mode
|
- **Theme**: Custom "sometimescode" theme
|
||||||
- **Hugo Version**: 0.150.0+
|
- **Hugo Version**: 0.139.4+ (extended version)
|
||||||
- **Content Format**: Markdown with YAML frontmatter
|
- **Content Format**: Markdown with YAML frontmatter
|
||||||
- **Dark Mode**: Custom CSS and JavaScript implementation with toggle button
|
- **Dark Mode**: Custom CSS and JavaScript implementation with toggle button
|
||||||
|
- **CI/CD**: Gitea Actions for automated build and deployment
|
||||||
|
|
||||||
## Philosophy
|
## Philosophy
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user