95 lines
3.2 KiB
Markdown
95 lines
3.2 KiB
Markdown
---
|
|
title: quartz-docker
|
|
draft: false
|
|
date: 2025-01-16
|
|
---
|
|
|
|
[quartz-docker image](https://code.modernleft.org/gravityfargo/-/packages/container/quartz-docker/v4.4.0)
|
|
|
|
```bash
|
|
docker pull code.modernleft.org/gravityfargo/quartz-docker:v4.4.0
|
|
```
|
|
|
|
This project runs **Quartz 4.4.0**, a fast, batteries-included static site generator, inside a **Docker container**. It transforms Markdown content into a fully functional website.
|
|
|
|
While Quartz provides [Docker support](https://quartz.jzhao.xyz/features/Docker-Support), it is not as self contained as this project.
|
|
|
|
## 🐳 Docker Compose Setup
|
|
|
|
Create a data directory
|
|
|
|
```bash
|
|
mkdir -p /srv/quartz
|
|
```
|
|
|
|
|
|
```yaml title="docker-compose.yml"
|
|
services:
|
|
quartz-docker:
|
|
container_name: quartz-docker
|
|
image: code.modernleft.org/gravityfargo/quartz-docker:dev
|
|
ports:
|
|
- 80:80
|
|
environment:
|
|
USER_ID: 1000
|
|
GROUP_ID: 1001
|
|
SERVER_NAME: "docs.modernleft.org"
|
|
ENABLE_CRON: "true"
|
|
BUILD_SCHEDULE: "*/30 * * * *"
|
|
CONTENT_REPO: "https://code.modernleft.org/gravityfargo/modernleft-docs.git"
|
|
volumes:
|
|
- /srv/quartz:/quartz
|
|
```
|
|
**First Run**
|
|
|
|
```bash
|
|
docker-compose up -d
|
|
docker stop quartz-wiki
|
|
```
|
|
|
|
On first run, the container will download the necessary dependencies, build the site, and download the content repository.
|
|
|
|
After that, you can configure whatever you would like in `/srv/quartz/src` using the stock options found in the quartz [documentation](https://quartz.jzhao.xyz/configuration)
|
|
`
|
|
|
|
## ⚙️ Configuration
|
|
|
|
### Optional `node_modules` volume
|
|
|
|
To keep the image small, `node_modules` are not included. When the container is run, they are downloaded to `/usr/share/nginx/html/node_modules`. Mounting this as a volume ensures they persist between container runs, reducing setup time.
|
|
|
|
### cron
|
|
|
|
This is the command run by cron
|
|
|
|
```bash
|
|
cd /quartz/content
|
|
git restore .
|
|
git pull
|
|
cd /quartz/src &
|
|
npx quartz build
|
|
echo 'Content Updated.'
|
|
```
|
|
|
|
Setting `ENABLE_CRON` to `true` and defining `BUILD_SCHEDULE` performs these actions.
|
|
If you need help configuring [Crontab.guru - The cron schedule expression generator](https://crontab.guru/) is a useful tool for that
|
|
|
|
Example:
|
|
|
|
```yaml
|
|
environment:
|
|
ENABLE_CRON: "true"
|
|
BUILD_SCHEDULE: "*/1 * * * *" # Runs every minute
|
|
```
|
|
|
|
### Environment Variables
|
|
|
|
| Variable | Description | Default Value |
|
|
| ---------------- | ----------------------------------------------------- | ----------------------------- |
|
|
| `USER_ID` | UID that` /content` and` /config` will be chown'd to. | `1000` |
|
|
| `GROUP_ID` | GID that` /content` and` /config` will be chown'd to. | `1000` |
|
|
| `NGINX_PORT` | Port for the Nginx server | `80` |
|
|
| `SERVER_NAME` | NGINX server name | `quartz.zhao.xyz` |
|
|
| `ENABLE_CRON` | Enables scheduled builds (`true` or `false`) | `false` |
|
|
| `BUILD_SCHEDULE` | Cron expression for scheduling site builds | `"*/10 * * * *"` every 10 min |
|
|
| `CONTENT_REPO` | URL of the content repository | |
|