Fix githash setting for deploystatic:ed templates
authorMagnus Hagander <magnus@hagander.net>
Fri, 29 Dec 2017 14:41:27 +0000 (15:41 +0100)
committerMagnus Hagander <magnus@hagander.net>
Fri, 29 Dec 2017 14:41:27 +0000 (15:41 +0100)
When using deploystatic to deploy directly from a repository branch,
there is no git repository in the resulting template directory. This
means that when the directory is loaded from the main jinja parser, it
does not find a .git, and thus does not set a githash.

To make this work, have deploystatic drop a file called
.deploystatic_githash into the target directory, and have the jinja code
specifically look for this code when trying to find the githash.

postgresqleu/confreg/jinjafunc.py
tools/deploystatic/deploystatic.py

index 286d63be629e58b256de32201073aab278c3b191..647182ddee47b597ba2c02c92b72079b227e340d 100644 (file)
@@ -42,8 +42,13 @@ def find_git_revision(path):
                        with open(refname) as f:
                                fullref = f.readline()
                                return fullref[:7]
+               elif os.path.exists(os.path.join(path, ".deploystatic_githash")):
+                       with open(os.path.join(path, ".deploystatic_githash")) as f:
+                               return f.readline().strip()
+
                # Else step up one level
                path = os.path.dirname(path)
+       # If no direct git hash found, search for a deploystatic file
        return None
 
 
index 79f68d89f36841421538944bddc796020469f6f5..506ec4dc2e713d1999bcc3b4e646b111c28ddb5a 100755 (executable)
@@ -279,6 +279,10 @@ if __name__ == "__main__":
                                if not f in knownfiles:
                                        os.unlink(os.path.join(args.destpath, f))
 
+               # Generate a githash file
+               with open(os.path.join(args.destpath, ".deploystatic_githash"), "w") as f:
+                       f.write(find_git_revision(args.sourcepath))
+
                sys.exit(0)
 
        # Set up jinja environment