gitlab: start automation of gitlab-backup
- git-clone and build git-backup sources - add a crontab doing `gitlab-backup pull` every 4 hours - add xnice for using less resources while backuping - add lock to avoid concurrent calls of backup script
... | ... | @@ -30,6 +30,7 @@ parts = |
service-redis | ||
service-cron | ||
cron-entry-gitlab-backup | ||
on-reinstantiate | ||
... | ... | @@ -759,9 +760,7 @@ cron-entries = ${cron-dir:cron.d} |
crontabs = ${cron-dir:crontabs} | ||
cronstamps = ${cron-dir:cronstamps} | ||
catcher = ${cron-simplelogger:wrapper} | ||
dcrond-binary = {{ dcron_bin }} | ||
|
||
depends = | ||
${logrotate-entry-cron:recipe} | ||
... | ... | @@ -771,7 +770,6 @@ recipe = slapos.cookbook:simplelogger |
wrapper = ${directory:bin}/${:_buildout_section_name_} | ||
log = ${cron-dir:log}/cron.log | ||
|
||
# base entry for clients who registers to cron | ||
[cron-entry] | ||
recipe = slapos.cookbook:cron.d | ||
... | ... | @@ -837,7 +835,11 @@ backup = ... |
time = daily | ||
command = ${logrotate:wrapper} | ||
[cron-entry-gitlab-backup] | ||
<= cron-entry | ||
# run backup script every four hours | ||
frequency = 0 */4 * * * | ||
|
||
command = {{ backup_script }} | ||
# 6. on-reinstantiate actions | ||
... | ... |
# GitLab "switch-softwaretype" instance | ||
[buildout] | ||
parts = switch-softwaretype | ||
parts = | ||
switch-softwaretype | ||
# std stuff for slapos instance | ||
eggs-directory = ${buildout:eggs-directory} | ||
develop-eggs-directory = ${buildout:develop-eggs-directory} | ||
offline = true | ||
[switch-softwaretype] | ||
recipe = slapos.cookbook:softwaretype | ||
default = $${instance-gitlab.cfg:rendered} | ||
# TODO -export, -import, -pull-backup | ||
[instance-gitlab.cfg] | ||
recipe = slapos.recipe.template:jinja2 | ||
mode = 0644 | ||
... | ... | @@ -50,6 +49,9 @@ context = |
raw ruby_location ${bundler-4gitlab:ruby-location} | ||
raw watcher_sigkill ${watcher-sigkill:rendered} | ||
# script | ||
raw backup_script $${backup_script.bash:rendered} | ||
|
||
# config files | ||
raw database_yml_in ${database.yml.in:target} | ||
raw gitconfig_in ${gitconfig.in:target} | ||
... | ... | @@ -64,3 +66,14 @@ context = |
raw resque_yml_in ${resque.yml.in:target} | ||
raw smtp_settings_rb_in ${smtp_settings.rb.in:target} | ||
raw unicorn_rb_in ${unicorn.rb.in:target} | ||
[backup_script.bash] | ||
recipe = slapos.recipe.template:jinja2 | ||
mode = 0770 | ||
template = ${backup_script.bash.in:target} | ||
rendered = $${buildout:directory}/backup_script.bash | ||
context = | ||
# XXX remove /usr/bin below? this is currently useful for command `which` | ||
raw env_path /usr/bin:${coreutils:location}/bin:${grep:location}/bin:${tar:location}/bin:${gzip:location}/bin:$${buildout:directory}/bin:${gopath:bin-directory}:${git:location}/bin:${xnice-repository:location}/bin | ||
raw backup_repo $${buildout:directory}/backup-gitlab.git | ||
|
||
raw bash_bin ${bash:location}/bin/bash |
... | ... | @@ -14,9 +14,12 @@ extends = |
../../component/nginx/buildout.cfg | ||
# for instance | ||
../../component/coreutils/buildout.cfg | ||
../../component/bash/buildout.cfg | ||
../../component/grep/buildout.cfg | ||
../../component/bzip2/buildout.cfg | ||
../../component/curl/buildout.cfg | ||
../../component/tar/buildout.cfg | ||
|
||
../../component/gzip/buildout.cfg | ||
../../component/dcron/buildout.cfg | ||
../../component/logrotate/buildout.cfg | ||
... | ... | @@ -36,6 +39,7 @@ parts = |
gitlab-shell/vendor | ||
gitlab/vendor/bundle | ||
gitlab-workhorse | ||
git-backup | ||
# for instance | ||
instance.cfg | ||
... | ... | @@ -44,13 +48,15 @@ parts = |
eggs | ||
bash | ||
coreutils | ||
curl | ||
watcher-sigkill | ||
grep | ||
gzip | ||
tar | ||
|
||
watcher-sigkill | ||
dcron-output | ||
logrotate | ||
############################ | ||
# Software compilation # | ||
############################ | ||
... | ... | @@ -65,7 +71,6 @@ recipe = z3c.recipe.scripts |
interpreter = python2 | ||
eggs = | ||
docutils | ||
# rubygemsrecipe with fixed url and this way pinned rubygems version | ||
[rubygemsrecipe] | ||
recipe = rubygemsrecipe | ||
... | ... | @@ -112,7 +117,7 @@ git-executable = ${git:location}/bin/git |
[gitlab-repository] | ||
<= git-repository | ||
#repository = https://gitlab.com/gitlab-org/gitlab-ce.git | ||
repository = https://lab.nexedi.com/nexedi/gitlab-ce.git | ||
repository = https://lab.nexedi.com/iv/gitlab-ce.git | ||
# 8.8.X + NXD patches: | ||
revision = v8.8.9-10-g967afbdc3a2d2bcc58ed31ca50d5293fa2a2e9ed | ||
location = ${buildout:parts-directory}/gitlab | ||
... | ... | @@ -135,8 +140,6 @@ repository = https://lab.nexedi.com/nexedi/gitlab-workhorse.git |
revision = v0.7.1-5-gd23a3247829fc3200e3dc784dcd57b5a0febac48 | ||
location = ${buildout:parts-directory}/gitlab-workhorse | ||
# build needed-by-gitlab gems via bundler | ||
[gitlab/vendor/bundle] | ||
recipe = slapos.recipe.cmmi | ||
... | ... | @@ -151,6 +154,51 @@ make-binary = |
make-targets= cd ${:path} && | ||
${:bundle} install --deployment --without development test mysql kerberos | ||
# directories and repositories required by gitlab-backup | ||
[gopath] | ||
directory = ${buildout:directory}/work | ||
src-directory = ${:directory}/src | ||
bin-directory = ${:directory}/bin | ||
[git2go-repository] | ||
<= git-repository | ||
git2go-path = github.com/libgit2/git2go | ||
|
||
repository = https://${:git2go-path}.git | ||
# branch 'next' is required by git-backup | ||
revision = next-g53594d7581617dbae7bb5960b4ac5f0ff513c184 | ||
location = ${gopath:src-directory}/${:git2go-path} | ||
[git-backup-repository] | ||
<= git-repository | ||
git-backup-path = lab.nexedi.com/kirr/git-backup | ||
repository = https://${:git-backup-path}.git | ||
revision = 3ba6cf73ba224c40f67f1fb87c855b915eb91f58 | ||
location = ${gopath:src-directory}/${:git-backup-path} | ||
[git-backup] | ||
recipe = slapos.recipe.cmmi | ||
path = ${git-backup-repository:location} | ||
configure-command = : | ||
make-binary = | ||
|
||
make-targets= cd ${git2go-repository:location} | ||
&& git submodule update --init | ||
|
||
&& make install | ||
&& cd ${git-backup-repository:location} | ||
&& install -d ${gopath:bin-directory} | ||
&& go build -o ${gopath:bin-directory}/git-backup . | ||
|
||
&& cp ${git-backup-repository:location}/contrib/gitlab-backup ${gopath:bin-directory} | ||
&& chmod +x ${gopath:bin-directory}/gitlab-backup | ||
|
||
environment = | ||
PATH=${cmake:location}/bin:${pkgconfig:location}/bin:${git:location}/bin:${golang16:location}/bin:${buildout:bin-directory}:%(PATH)s | ||
GOPATH=${gopath:directory} | ||
[xnice-repository] | ||
# to get kirr's misc repo containing xnice script for executing processes | ||
# with lower priority (used for backup script inside the cron) | ||
|
||
<= git-repository | ||
repository = https://lab.nexedi.com/kirr/misc.git | ||
revision = 4073572ea700bf1b115f3a135aebebe5b3b824e4 | ||
location = ${buildout:parts-directory}/misc | ||
# build needed-by-gitlab-shell gems via bundler | ||
# ( there is not vendor/ dir in gitlab-shell, so to avoid having buildout error | ||
... | ... | @@ -177,7 +225,6 @@ make-targets= ${:_buildout_section_name_} |
environment = | ||
PATH=${golang16:location}/bin:%(PATH)s | ||
############################### | ||
# Trampoline for instance # | ||
############################### | ||
... | ... | @@ -194,7 +241,7 @@ eggs = |
recipe = slapos.recipe.template | ||
url = ${:_profile_base_location_}/instance.cfg.in | ||
output = ${buildout:directory}/instance.cfg | ||
md5sum = ef85f02c4f6070c586d773b859a2f4e2 | ||
md5sum = 11d8a2628dd170169a334877968e0bcc | ||
[watcher-sigkill] | ||
recipe = slapos.recipe.template:jinja2 | ||
... | ... | @@ -222,6 +269,10 @@ destination = ${buildout:directory}/${:_buildout_section_name_} |
url = ${:_profile_base_location_}/template/${:_buildout_section_name_} | ||
[backup_script.bash.in] | ||
<= download-template | ||
md5sum = 272b05a7694b950cf3efa64ea14f8bbb | ||
[database.yml.in] | ||
<= download-template | ||
md5sum = 61d1d04b9347b3168a1ad7676e4681ef | ||
... | ... | @@ -248,7 +299,7 @@ md5sum = 176939a6428a7aca4767a36421b0af2b |
[instance-gitlab.cfg.in] | ||
<= download-file | ||
md5sum = 89914e4a225f6cdebfa196d46359f6f2 | ||
md5sum = bf3b277dcf32adb08fbb1deb18ab3cfd | ||
[macrolib.cfg.in] | ||
<= download-file | ||
... | ... |
-
@iv I think the patch should be more or less ok to go. My above comments are mostly about cosmetics / structure etc and seems like it shold generally work. Maybe I've missed something but imho after fixing the styling & other minor nits we can give the patch a try putting it into lab.nexedi.com .
While you do the fixups let's also give a chance for others to speak-up.
-
Maintainer
OK, thanks for the review :)