How to serve this blog?
I wanted something simple to avoid loosing time in configuring and customizing this blog. I just have to focus on writing some new stuff to share 🙂
The backend is a simple docker compose with 2 services:
blog
to serve static content with Nginxblog-build
as a “sidecar” container constantly watch for updates in blog/ directory and generate static content
This is docker-compose.yml
content:
version: "3.9"
services:
blog:
container_name: blog
image: nginx
volumes:
- /srv/docker-compose/blog/_site/:/var/www/html
- /srv/docker-compose/nginx.conf.template:/etc/nginx/templates/nginx.conf.template
ports:
- "8001:8001"
environment:
NGINX_HOST: blog.ralex.fr
NGINX_PORT: 8001
restart: always
blog-build:
container_name: blog-build
image: jekyll/jekyll:latest
entrypoint: jekyll
command: build --watch --incremental
environment:
JEKYLL_ROOTLESS: 1
volumes:
- /srv/docker-compose/blog:/srv/jekyll
restart: always
There is a special feature of the official Nginx docker image that is used to customize hostname and port with nginx.conf.template
file:
server {
listen ${NGINX_PORT};
server_name ${NGINX_HOST};
root /var/www/html;
location / {
try_files $uri $uri/ $uri.html =404;
}
}
You can read more about it here.
Any modification to _config.yml
will need a restart with:
docker-compose restart blog-build
But any addition to _posts/ directory will be automatically published.
It is a good idea to put published: false
in the header of a new article while it is not yet available for public reading.
Another way is to put a date in the future in the header of your article. You will see this kind of message in your logs until the post is ready to be published:
Skipping: _posts/2023-12-21-how-to-serve-this-blog.md has a future date
Then, it’s up to you to choose to version this code in Git or, at least, back it up! 😉