Creative Deployment Strategies

Problem

The project you are working on uses the Saleor Framework. The Frontend is in React, the backend in Django.

The current task for you is to create a sitemap for the website. You´re getting very happy, you did that before. Just add a little bit of code, attach it to the React Router and you´re done.

Until you read the last two sentences of the requirement:

  1. The Sitemap needs to be updated in intervals that are independent of the normal deployment cycle.
  2. The individual urls of the pages need to be filtered and product page can only be included if certain backend fields are set.

Thoughts

Swearingly you start think how to solve this quickly because it´s also an urgent ASAP! task.

Just attaching to the Router won´t work. Hardcoding the included or excluded routes won´t work. Querying the Products according to the requirement is not available in GraphQL yet.

Saleor provides a set up to create a sitemap, but it has the same problems.

Seems like you need to do it in the backend. There you have all that you need. But wait, how to reliably bring the generated file from the backend container to the Frontend one?

And isn´t there a migration towards Kubernetes in progress? Relying on some mounted volumes will not work.

The Solution I used

  1. Use Django with Celery (the second backend from Saleor) to generate the sitemap.xml.
  2. Use it to update a GitHub repository too
  3. Use GitHub Actions to deploy

1. Use Django with Celery (the second backend from Saleor) to generate the sitemap.xml.

We already use Django with Celery and Django-Celery-Beat (1) and Redis to update product availability every night with a crontab.

So I reused the set up, created a new task that runs in the required interval to generate the sitemap.

For that it filters the products as required.

2. Use it to update a GitHub repository too

It basically creates a new temporary folder, clones the repo of the sitemap, generates the sitemap (see 1), commits the change and pushes back to the repo.

Last but not least in this step it deletes the temporary folder.

3. Use GitHub Actions to deploy

In the GitHub repository a GitHub action is configured. It uses an ssh connection and key to connect to the Server of this Docker Server when a push occurs to the master branch.

Via SSH it executes a command to the Frontend Container that creates a new temporary folder, clones the repository, copies the sitemap.xml to the correct location and deletes the temporary folder again.

Kubernetes Migration

The migration isn´t finished yet and I haven´t seen the infrastructure. But by separating out the creation and the deployment of the sitemap, it´s as future proof as it can be within the time available.

When I get access to the infrastructure, I can review the deployment process and adapt it as required.

Notes

Since I started working in a start up (and on some side projects) I´m more often ignoring some best practices and implement more creative Solutions.

Time will time if this is for the better or the worse. My colleague and I do our best to keep track of the Technical debt, so it can be tackled where and when required and/or time available.

There is kind of a saying that “workarounds survive the longest” and it might be true. Gotta follow the business value and focus on what´s bringing money, not only follow the textbook.

Let me know when this helped or inspired you.

Best,

Frank

Sources:

  1. https://github.com/celery/django-celery-beat
  2. Clone a repository
  3. Create a tempfile
  4. Saleor.io

Leave a Reply