meeb/django-distill

How to protect .git directory with distill-local

Closed this issue · 3 comments

kc1 commented

I'm trying to turn a django site into a static site using https://github.com/mgrp/django-distill . I am outputting the static files into

/e/ENVS/STATIC/static1

on my win10 local system. As I make changes I want to overwrite all the non hidden files including the .git directory, the commit and push the changes to my github repo for deployment. Unfortunately the distill project overwrites the entire directory , deleting the .git/ files. I've tried to protect the git files with

$ chmod -R 707 .git/ 

using git-bash, but the output looks like:

drwxr-xr-x 1 me 197121     0 Oct 21 14:35 ./
drwxr-xr-x 1 me 197121     0 Oct 20 17:11 ../
drwxr-xr-x 1 me 197121     0 Oct 21 14:35 .git/
drwxr-xr-x 1 me 197121     0 Oct 21 14:36 .idea/
-rw-r--r-- 1 me 197121  9963 Oct 21 15:02 agreement.html
-rw-r--r-- 1 me 197121    17 Oct 21 15:02 contact.html
-rw-r--r-- 1 me 197121 14027 Oct 21 15:02 documents.html
-rw-r--r-- 1 me 197121 17048 Oct 21 15:02 form.html
-rw-r--r-- 1 me 197121 11060 Oct 21 15:02 index.html
-rw-r--r-- 1 me 197121  4921 Oct 21 15:02 slideshow.html
drwxr-xr-x 1 me 197121     0 Oct 21 15:02 static/

Do you have any advice on how to protect the .git/ directory or copy the new files without deleting the .git directory. This would really simplify the workflow, by allowing you to quickly stage and push to my github repo which is linked to (in my case) a netlify account.

meeb commented

Hi,

I'm not too sure what your workflow is here, distill is meant to create a static copy of your Django site then publish it somewhere, if you edit the content the design is you just re-export the website and publish it again rather than edit the exported website. Are you trying to push the static website to GitHub to host on GiyHub pages or something?

Anyway, the easiest would probably be to export it into a subdirectory like: /e/ENVS/STATIC/static1/public/. This won't touch the .git dir in the parent /e/ENVS/STATIC/static1 directory. You would need to change whatever static / public / publishing directory you use on your hosting end of course.

There are easier options. Personally, for small projects with just one or two people editing the site content we use an SQLite3 database which we directly commit into the repo, then use Netlify to build and host the website automatically each time we push content. Similar setups are quite easy with GitLab pages, GitHub pages or any other CI/CD pipeline.

Alternatively, just publish the site to an AWS bucket or Google Cloud Storage container directly from Django?

Either way my advice would be to work around where you export the directory locally or use a cleaner deployment pipeline which doesn't require a committing of static code into an intermediate repository.

Good luck!

kc1 commented

Thanks for your comments on this. I have a couple of questions though. I am leaning towards the first solution you provided (static1/public/) . I am also using netlify from a github repo.

  1. Locally, would it be best to use distill-publish for this ? I have been using distill-local.

  2. What is the purpose of the sqlite db in your pipeline?

  3. "Alternatively, just publish the site to an AWS bucket or Google Cloud Storage container directly from Django?" - I'm assuming you are referring to distill-publish?

meeb commented

I'd suggest you either:

  1. Have a remote continuous deployment service (e.g Netlify, GitLab pages) run distill-local for you; or
  2. Deploy to a static storage bucket like Google Cloud Storage - and yes this would be with the distill-publish command after you've configured your bucket details in settings.py

As this question has been asked directly quite a lot I've made a complete example demo blog using django-distill and Netlify as a continuous deployment service and host here:

https://github.com/mgrp/django-distill-example

Live output is here:

https://django-distill-example.m.pr/

As you can see in this demo the site content is directly stored in an SQLite database into the repo, this is pushed to GitHub, GitHub notifies Netlify via a hook, Netflify then starts a build process, clones the repo and runs make, this creates a public directory which Netlify deploys live.

End result is you can just edit content in the Django admin, do a git push and your content is automatically deployed for you. If you have a bigger team you could use a remote SQL database of some kind.

Hopefully this should clear up with a concise example how django-distill should be used.