Skip to main content

Linting nginx config in our Docusaurus CI setup

This blog post might be outdated!
This blog post was published more than one year ago and might be outdated!
· 2 min read
Stephan Hochdörfer
Head of IT Business Operations

We've covered the basics of our Docusaurus CI setup already in another blog post. In this blog post, we'll show you how to the build pipeline to lint the nginx configuration used in our Docusaurus setup.

Since we have migrated our blog a few times in the past, I realized that some links did not work anymore. The Google Search console is a good tool to get those insights from.

Naturally, I started adding redirects to the nginx configuration and apparently I messed a few things up. As an outcome of this, the Docker container we built in our Gitlab CI pipeline did not start anymore. Since that happened not only once but a few times now, I decided I want a guard for it. Why not check the nginx configuration in our CI pipeline and let the pipeline fail when an invalid nginx configuration is used?

Actually, it turns out, this is a fairly trivial task. All that needs to be done is to add a new job to our GitLab CI configuration file:

test:nginx:
stage: test
image: nginx:latest
only:
- merge_requests
script:
- cp ./docker/nginx.conf /etc/nginx/nginx.conf
- nginx -t

As an image for the test:nginx job, the same nginx image is used that we use to build our Docusaurus image. All we need to do is run the nginx -t command to let nginx check its configuration file. Apparently, you can't pass a custom path to our own nginx configuration file when running the command. That's why we decided to copy our own nginx configuration file to /etc/nginx/nginx.conf before invoking the test command.

If a syntax error exists in our nginx configuration, the job will fail and so will the build pipeline. Problem solved.