Commits

ltnooy committed e3d4130

Updating RsyncDeployment to produce a "previous" snapshot of the deployed code.

Comments (0)

Files changed (1)

baste/__init__.py

 
 REPO_EXCLUDES = [
     '.svn', '.git', '.hg', '.hgignore', 'requirements.txt', 'start.sh',
-    'fabfile.py', '*.pyc', 'env', '.swp'
+    'fabfile.py', '*.pyc', 'env', '*.swp'
 ]
 
 #-------------------------------------------------------------------------------
         self.local_directory = local_directory
 
     #---------------------------------------------------------------------------
-    def __call__(self):
+    def __call__(self, exclude=[]):
         """
         Actually perform the deployment.
         """
+
+        exclude += REPO_EXCLUDES
+
         source_directory = os.path.join(self.remote_directory, "source")
+        previous_directory = os.path.join(self.remote_directory, "previous")
+        tmp_previous = os.path.join(self.remote_directory, "previous_tmp")
         current_symlink = os.path.join(self.remote_directory, "current")
         tmp_symlink = os.path.join(self.remote_directory, "current_tmp")
         date_directory = os.path.join(
                 self.remote_directory,
                 datetime.datetime.now().strftime("%Y-%m-%dT%H%M%S")
             )
+        remote_run("mkdir -p %s" % source_directory)
+        remote_run("mkdir -p %s" % previous_directory)
+        remote_run("mv -Tf %s %s" % (previous_directory, tmp_previous))
+
+        # only if the current directly exists can we copy it to the previous directory.
+        if remote_run("ls -1 %s | grep current | cat" % self.remote_directory):
+            remote_run("cp -rH %s %s" % (current_symlink, previous_directory))
+
         rsync_project(
                 remote_dir=source_directory,
                 local_dir=self.local_directory,
-                exclude=REPO_EXCLUDES,
+                exclude=exclude,
                 delete=True,
             )
         remote_run("cp -r %s %s" % (source_directory, date_directory))
         remote_run("ln -sf %s %s; mv -Tf %s %s" % (date_directory, tmp_symlink, tmp_symlink, current_symlink))
-
+        remote_run("rm -rf %s" % tmp_previous)
 
 #-------------------------------------------------------------------------------
 class UbuntuPgCreateDbAndUser(object):