2025-01-17 02:28:51 +00:00
---
2025-01-18 01:49:03 +00:00
title: quartz-docker
2025-01-17 02:28:51 +00:00
draft: false
date: 2025-01-16
---
2025-01-17 16:50:09 +00:00
2025-01-18 20:57:22 +00:00
| | |
| ----------------------- | ---------------------------------------------------------------------------------------------- |
| Image on Forgejo | [Forgejo ](https://code.modernleft.org/gravityfargo/-/packages/container/quartz-docker/v4.4.0 ) |
| Official quartz project | [GitHub - jackyzha0/quartz ](https://github.com/jackyzha0/quartz ) |
| Image Source | [Forgejo - gravityfargo/quartz-docker ](https://code.modernleft.org/gravityfargo/quartz-docker ) |
| Issue Tracker | |
| | |
2025-01-17 15:48:51 +00:00
2025-01-17 16:24:01 +00:00
```bash
docker pull code.modernleft.org/gravityfargo/quartz-docker:v4.4.0
```
2025-01-18 19:37:22 +00:00
---
2025-01-18 01:33:34 +00:00
This project runs **Quartz** v4.4.0, a fast, batteries-included static site generator, inside a **Docker container** . It transforms Markdown content into a fully functional website.
2025-01-17 03:07:26 +00:00
2025-01-17 22:30:42 +00:00
While Quartz provides [Docker support ](https://quartz.jzhao.xyz/features/Docker-Support ), it is not as self contained as this project.
2025-01-17 22:05:45 +00:00
2025-01-18 01:38:34 +00:00
There is no support for SSL or any other features that are not directly related to building the site. I run everything behind traeffik, so I don't need it.
2025-01-17 21:55:45 +00:00
## 🐳 Docker Compose Setup
2025-01-17 03:07:26 +00:00
2025-01-18 01:23:34 +00:00
Create a data directory
2025-01-17 15:59:26 +00:00
2025-01-17 21:55:45 +00:00
```bash
2025-01-18 01:23:34 +00:00
mkdir -p /srv/quartz
2025-01-17 21:55:45 +00:00
```
2025-01-17 15:59:26 +00:00
2025-01-18 01:28:34 +00:00
```yaml title="docker-compose.yml"
services:
2025-01-18 02:29:47 +00:00
quartz-wiki:
container_name: quartz-wiki
2025-01-18 01:28:34 +00:00
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
```
2025-01-18 01:33:34 +00:00
2025-01-18 01:23:34 +00:00
**First Run**
2025-01-17 16:18:00 +00:00
2025-01-17 21:55:45 +00:00
```bash
docker-compose up -d
docker stop quartz-wiki
```
2025-01-17 16:18:00 +00:00
2025-01-18 01:33:34 +00:00
On first run, the container will download the necessary dependencies, build the site, and download the content repository.
2025-01-18 01:38:34 +00:00
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 ) Bare minimum should be `baseUrl` and `pageTitle` .
2025-01-18 01:28:34 +00:00
2025-01-18 01:33:34 +00:00
🥳 Done! 🎉
2025-01-17 16:50:09 +00:00
2025-01-18 01:51:17 +00:00
## Manually Building the Site
2025-01-18 02:09:47 +00:00
If you don't use the cron job, and don't feel like restarting the container, you can build the site manually.
2025-01-18 01:51:17 +00:00
```bash
docker exec -it quartz-wiki bash
2025-01-18 01:54:00 +00:00
cd /quartz/content/ & & git restore . & & git pull
cd /quartz/src/ & & npx quartz build
2025-01-18 01:51:17 +00:00
```
2025-01-17 21:55:45 +00:00
## ⚙️ Configuration
2025-01-17 16:50:09 +00:00
2025-01-18 02:09:47 +00:00
**cron**
2025-01-17 15:59:26 +00:00
2025-01-18 02:09:47 +00:00
This is the an equivalent command to the cron job.
2025-01-17 16:18:00 +00:00
2025-01-17 21:55:45 +00:00
```bash
2025-01-18 01:23:34 +00:00
cd /quartz/content
git restore .
git pull
cd /quartz/src &
npx quartz build
echo 'Content Updated.'
2025-01-17 21:55:45 +00:00
```
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
2025-01-17 16:50:09 +00:00
2025-01-17 21:55:45 +00:00
Example:
```yaml
environment:
2025-01-18 01:23:34 +00:00
ENABLE_CRON: "true"
2025-01-17 21:55:45 +00:00
BUILD_SCHEDULE: "*/1 * * * * " # Runs every minute
```
2025-01-17 16:18:00 +00:00
2025-01-17 21:55:45 +00:00
### Environment Variables
2025-01-17 16:18:00 +00:00
2025-01-18 03:09:47 +00:00
| Variable | Description | Default Value |
| -------------------- | -------------------------------------------- | ---------------------------------------------------- |
| `USER_ID` /`GROUP_ID` | UID/GID that` /quartz` will be chown'd to. | `1000` :`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 | `https://code.modernleft.org/gravityfargo/empty.git` |
2025-01-18 20:47:22 +00:00
> [!NOTE] > `CONTENT_REPO` Must use https, not git.