From 8289f7ff46a0617898474418029edb9a4f011446 Mon Sep 17 00:00:00 2001
From: Kirill Smelkov <kirr@nexedi.com>
Date: Thu, 11 Feb 2016 14:23:23 +0300
Subject: [PATCH] gitlab: Let's keep shared/ and builds/ under var/ , not in
 gitlab-work/

Even though we do not use LFS objects, builds and build artifacts,
gitlab backups corresponding directories and recreates them upon
restore.

Current state is: the directories are living under Rails root - that is
in our gitlab-work/ inside instance, and since gitlab-work is recreated
almost on every re-instantiation if we'll have some content in that
directories - it will be lost.

Don't allow even a chance for that to happen and move what is designed
to hold data to under var/ .

NOTE we create shared/lfs-objects/ and shared/artifacts/ because if we
    do not have this dirs, gitlab backup fails. Upstream code just
    assumes the directories are there.

/cc @kazuhiko, @jerome
---
 software/gitlab/instance-gitlab.cfg.in | 14 ++++++++++++--
 software/gitlab/software.cfg           |  4 ++--
 software/gitlab/template/gitlab.yml.in |  2 +-
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/software/gitlab/instance-gitlab.cfg.in b/software/gitlab/instance-gitlab.cfg.in
index 040b14bba..7aeee3f95 100644
--- a/software/gitlab/instance-gitlab.cfg.in
+++ b/software/gitlab/instance-gitlab.cfg.in
@@ -118,6 +118,10 @@ var     = ${directory:var}/gitlab
 tmp     = ${:var}/tmp
 uploads = ${:var}/uploads
 assets  = ${:var}/assets
+shared  = ${:var}/shared
+artifacts = ${:shared}/artifacts
+lfs-objects = ${:shared}/lfs-objects
+builds  = ${:var}/builds
 backup  = ${directory:var}/backup
 
 [gitlab-repo-dir]
@@ -139,6 +143,10 @@ var     = ${gitlab-dir:var}
 tmp     = ${gitlab-dir:tmp}
 uploads = ${gitlab-dir:uploads}
 assets  = ${gitlab-dir:assets}
+shared  = ${gitlab-dir:shared}
+artifacts = ${gitlab-dir:artifacts}
+lfs-objects = ${gitlab-dir:lfs-objects}
+builds  = ${gitlab-dir:builds}
 backup  = ${gitlab-dir:backup}
 repositories = ${gitlab-repo-xdir:repositories}
 
@@ -357,14 +365,16 @@ update-command =
 <= work-base
 software = {{ gitlab_repository_location }}
 tune-command =
-# secret* config.ru tmp/ log/
+# secret* config.ru tmp/ log/ shared/ builds/
     rm -f .secret  &&
     rm -f config.ru  &&
-    rm -rf log tmp  &&
+    rm -rf log tmp shared builds  &&
     ln -sf ${secrets:secrets}/gitlab_rails_secret .secret  &&
     ln -sf ${config.ru:rendered} config.ru  &&
     ln -sf ${gitlab:log} log  &&
     ln -sf ${gitlab:tmp} tmp  &&
+    ln -sf ${gitlab:shared} shared  &&
+    ln -sf ${gitlab:builds} builds  &&
 # config/
     cd config  &&
     ln -sf ${unicorn.rb:rendered} unicorn.rb  &&
diff --git a/software/gitlab/software.cfg b/software/gitlab/software.cfg
index eed18bec9..d15daa04a 100644
--- a/software/gitlab/software.cfg
+++ b/software/gitlab/software.cfg
@@ -243,11 +243,11 @@ md5sum  = 2716afaa9445c0c429c6b211356ebe8f
 
 [gitlab.yml.in]
 <= download-template
-md5sum  = 97b7f5654bc280542ee348cb6fa60893
+md5sum  = cd7aaeeb1917fdedb7656943065c0a9c
 
 [instance-gitlab.cfg.in]
 <= download-file
-md5sum  = 937640a46b8300edbc72901053e0392b
+md5sum  = 33309e35eb67ea27f7c7a4a5abd459cc
 
 [macrolib.cfg.in]
 <= download-file
diff --git a/software/gitlab/template/gitlab.yml.in b/software/gitlab/template/gitlab.yml.in
index cfc44d770..a6f735b84 100644
--- a/software/gitlab/template/gitlab.yml.in
+++ b/software/gitlab/template/gitlab.yml.in
@@ -313,7 +313,7 @@ production: &base
 <% end %>
     #}
 
-  {# default ($RAILS_ROOT/shared/) is just ok
+  {# default ($RAILS_ROOT/shared/) is ok - we symlinked it to proper place
   # Shared file storage settings
   shared:
     path: <%= @shared_path %>
-- 
2.30.9