Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build

on:
push:
branches: ['**']
pull_request:
branches: ['main']

permissions:
contents: read

jobs:
build:
name: Build Astro site
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
retention-days: 7
61 changes: 61 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Deploy to GitHub Pages

on:
push:
branches: ['main']
workflow_dispatch:

# Allow one concurrent deployment
concurrency:
group: 'pages'
cancel-in-progress: true

# Sets permissions of the GITHUB_TOKEN for GitHub Pages deployment
permissions:
contents: read
pages: write
id-token: write

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'

- name: Setup Pages
id: pages
uses: actions/configure-pages@v4

- name: Install dependencies
run: npm ci

- name: Build with Astro
run: |
npm run build -- \
--site "${{ steps.pages.outputs.origin }}" \
--base "${{ steps.pages.outputs.base_path }}"

- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: dist/

deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Dependencies
node_modules/

# Build output
dist/
.astro/

# Environment files
# .env is generated by `dotconfig load` — do not commit it
.env
.env.*
!.env.example

# Local developer config overrides
# Keep the `example` directory; ignore personal copies
config/local/*/
!config/local/example/

# dotconfig metadata
.dotconfig

# OS files
.DS_Store
Thumbs.db

# Editor directories
.vscode/
.idea/
*.swp
*.swo

# Logs
*.log
npm-debug.log*

# Runtime data
*.pid
*.seed
*.pid.lock
202 changes: 201 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,202 @@
# astro-template
A a template for starting astro websites.

A minimal, production-ready template for starting [Astro](https://astro.build) website projects.

## Features

- ⚡ **Minimal Astro setup** — static by default, fast and SEO-friendly
- 🚀 **GitHub Actions** — automatic build on every push; one-click deploy to GitHub Pages
- ⚙️ **[dotconfig](https://github.com/ericbusboom/dotconfig)** — layered environment configuration (dev / prod / local overrides)
- 🐳 **[rundbat](https://github.com/ericbusboom/rundbat)** — Docker-based deployment management for testing and production
- 📜 **Setup scripts** — get from clone to running in minutes

---

## Quick Start

```bash
# 1. Clone or fork this template
git clone https://github.com/your-org/your-project.git
cd your-project

# 2. Run the setup script (installs deps, creates local config)
./scripts/setup.sh

# 3. Start the dev server
npm run dev
# → open http://localhost:4321
```

---

## Project Structure

```
astro-template/
├── .github/
│ └── workflows/
│ ├── build.yml # Build on every push / PR
│ └── deploy.yml # Deploy to GitHub Pages on push to main
├── config/ # dotconfig configuration tree
│ ├── sops.yaml # SOPS encryption rules (edit with your age key)
│ ├── rundbat.yaml # rundbat project config
│ ├── dev/
│ │ └── public.env # Public dev environment variables
│ ├── prod/
│ │ └── public.env # Public prod environment variables
│ └── local/
│ └── example/
│ └── public.env # Template for personal local overrides
├── docker/
│ ├── Dockerfile # Multi-stage build → Nginx static server
│ └── docker-compose.yml # Docker Compose for local/Docker deployment
├── scripts/
│ ├── setup.sh # First-time setup
│ ├── dev.sh # Start dev server (with optional dotconfig load)
│ └── docker-run.sh # Build and run in Docker
├── src/
│ ├── layouts/
│ │ └── Layout.astro # Base HTML layout
│ └── pages/
│ └── index.astro # Home page
├── public/
│ └── favicon.svg
├── astro.config.mjs
├── package.json
└── tsconfig.json
```

---

## GitHub Pages Deployment

1. In your repository settings → **Pages**, set the source to **GitHub Actions**.
2. Push to `main` — the `deploy.yml` workflow builds and publishes the site automatically.
3. Update `astro.config.mjs` with your `site` and `base` if needed:

```js
export default defineConfig({
site: 'https://your-username.github.io',
base: '/your-repo-name',
});
```

---

## Configuration with dotconfig

This template uses [dotconfig](https://github.com/ericbusboom/dotconfig) to manage a layered `.env` file from multiple source files.

### Install dotconfig

```bash
pipx install dotconfig
```

### Configuration layout

```
config/
dev/public.env ← committed public vars for dev
prod/public.env ← committed public vars for prod
local/<yourname>/ ← your personal overrides (gitignored)
public.env
secrets.env ← SOPS-encrypted secrets (optional)
sops.yaml ← SOPS key rules
```

### Setup your local config

```bash
# Copy the example local config
cp -r config/local/example config/local/<yourname>
# Edit your overrides
$EDITOR config/local/<yourname>/public.env

# Generate .env
dotconfig load -d dev -l <yourname>
```

### Load / save config

```bash
# Load dev config with your local overrides
dotconfig load -d dev -l <yourname>

# Load prod config
dotconfig load -d prod

# After editing .env directly, save it back to the source files
dotconfig save
```

The generated `.env` is gitignored — the source files in `config/` are what you commit.

---

## Docker Deployment with rundbat

[rundbat](https://github.com/ericbusboom/rundbat) manages Docker-based deployment environments.

### Install rundbat

```bash
pipx install rundbat
```

### Quick Docker commands

```bash
# Detect environment
rundbat discover

# Initialize rundbat in this project
rundbat init

# Build and run in Docker via helper script
./scripts/docker-run.sh up # start (builds image first)
./scripts/docker-run.sh down # stop
./scripts/docker-run.sh logs # follow logs

# Or use rundbat directly
rundbat start dev
rundbat stop dev
rundbat health dev
```

The site will be available at `http://localhost:8080` by default.

### Adding a database

If your project needs a database, uncomment the `db` service in `docker/docker-compose.yml`, then use rundbat to provision and manage it:

```bash
rundbat add-service postgres
rundbat create-env dev
rundbat get-config dev # prints the DATABASE_URL
```

---

## Scripts Reference

| Script | Purpose |
|---|---|
| `./scripts/setup.sh [name]` | First-time setup: install deps, create local config, discover rundbat |
| `./scripts/dev.sh [name]` | Load dotconfig and start the Astro dev server |
| `./scripts/docker-run.sh [up\|down\|build\|logs]` | Manage Docker containers |

---

## Customization

- **Add pages**: create `.astro` (or `.md`) files in `src/pages/`
- **Add components**: place reusable components in `src/components/`
- **Add integrations**: `npx astro add <integration>` (e.g., `tailwind`, `react`, `mdx`)
- **Add a backend**: uncomment the `db` service in `docker/docker-compose.yml` and configure rundbat

---

## License

MIT
8 changes: 8 additions & 0 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'astro/config';

// https://astro.build/config
export default defineConfig({
// Set site to your GitHub Pages URL when deploying
// site: 'https://your-username.github.io',
// base: '/your-repo-name',
});
6 changes: 6 additions & 0 deletions config/dev/public.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Public configuration for the dev deployment.
# These values are committed to version control.
# Do NOT put secrets here.

NODE_ENV=development
SITE_URL=http://localhost:4321
9 changes: 9 additions & 0 deletions config/local/example/public.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Example personal local overrides.
# Copy this directory to config/local/<yourname>/ and edit the values.
# This file is committed as a template — your personal copy is gitignored.

# Override SITE_URL for your local machine if needed
SITE_URL=http://localhost:4321

# Docker context to use (e.g. default, orbstack, colima)
DOCKER_CONTEXT=default
6 changes: 6 additions & 0 deletions config/prod/public.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Public configuration for the prod deployment.
# TODO: Update SITE_URL to your actual production domain before deploying.
# Example: SITE_URL=https://your-username.github.io/your-repo-name

NODE_ENV=production
SITE_URL=https://REPLACE_WITH_YOUR_DOMAIN
9 changes: 9 additions & 0 deletions config/rundbat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# rundbat project configuration
# See: https://github.com/ericbusboom/rundbat
#
# app_name: The name of your application. Used to name Docker containers and databases.
# Update this to match your project name.

app_name: astro-template
container_template: "{app}-{env}"
notes: []
Loading
Loading