From 2324b344476e14ce132ad9602dc0f6cc06a999f6 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Thu, 1 Oct 2015 19:11:49 +0200 Subject: [PATCH] added ebuilds for gitlab{hq,-ci}-8.0.3 --- www-apps/gitlab-ci/Manifest | 2 + www-apps/gitlab-ci/gitlab-ci-8.0.3.ebuild | 309 ++++++++++++++++++ www-apps/gitlabhq/Manifest | 2 + www-apps/gitlabhq/gitlabhq-8.0.3.ebuild | 367 ++++++++++++++++++++++ 4 files changed, 680 insertions(+) create mode 100644 www-apps/gitlab-ci/gitlab-ci-8.0.3.ebuild create mode 100644 www-apps/gitlabhq/gitlabhq-8.0.3.ebuild diff --git a/www-apps/gitlab-ci/Manifest b/www-apps/gitlab-ci/Manifest index 51d96b8..4e64d0e 100644 --- a/www-apps/gitlab-ci/Manifest +++ b/www-apps/gitlab-ci/Manifest @@ -1,5 +1,7 @@ AUX gitlab-ci-unicorn.init 1700 SHA256 ad75c1774db69d2ceae61983ba7227bb840c761d69eb387eaba120553fcd038a SHA512 fc2005db1523777f96867a3983efcb256ee8a3f62146dfc58af5536c0c869d665870b2f6710fe1d2f014fcb921ec3c79066b67b0189a6b525a7aea7f1afff78a WHIRLPOOL c80e72eb0c8f14c56662f91f2f1b51d1bbc83d956dcd3915c354e95ca5c1231c575b1fec91398c345fa71af61efe654e78f85e9d75be3b5624e65021e7102c28 DIST gitlab-ci-7.14.3.tar.gz 1103513 SHA256 89731e2338b08a811472e0e1b64966789021e1c88f880fea9c38e90cc807651b SHA512 74c96c36d892f88f204466e99020dcf1438605bf85714484cdac442b04e6590cd79af2e97c1f738a2c2d32f81e1007d5563e6a32f2f165c6f42e76f4f53da479 WHIRLPOOL 37f13ccfae347d3e67b8de2ebacedcd5ca18edc5149326dbc5a512d3f3531df6b4b87a8430fdfe7280ded1ea694da4898504786a1b157f967214cf52ca72a58b DIST gitlab-ci-8.0.2.tar.gz 1110587 SHA256 002b0df9c1adf8958626e86d965035c7cba33e2e0d9503f624c75f70d31aa306 SHA512 e32245e3ff54ed9b22d43e1164e0f5b289458c27f6993937ae7c30c9a22ba59d587925723822428e8a692cbd5c7542269fdc6db4d0906ab8a319975311fd2b25 WHIRLPOOL f0528f67d4fbe41449c41726d0f3c2bf7d26a2f218ddeb4eaa94f0845854d8684e0a74e63b1c6b65ccc1aeed5dc8e611e48d626329b4eec5ce02289ac16f8a2e +DIST gitlab-ci-8.0.3.tar.gz 1110721 SHA256 c5a6735462f180e89a18d2561a0754f3ee127c593768fad288f44482b8bd2b0c SHA512 c0fcaae82a36cd0f8b07c01ecd4bc2a7d1b0d736e34015b39260c56293465b356997f419d2c9c2636c8930898486da0036aadeb156d54232ead945fae2051754 WHIRLPOOL 81a7dcb223f2613472df242bf062ce22d24259eb5cc26c9c21c5d0e0f6d7b79cdf9948d2aa70b7253937f2c76406ee5a01d227491ae453e8061c9cf3ce8f48b0 EBUILD gitlab-ci-7.14.3.ebuild 8540 SHA256 82d924f02abdbd68a2b4bafc0b82232ebad5303bb9a9259ec2df70da662a9e40 SHA512 3a9fb89fde76f4e839cfbd23bff299a66d87ecd8e7943f87e4c69e1d25b9679a0fa7feae77264b9d0d5b1f39a529d208fa0d438d7f317b64f1a8b9b509e3e0da WHIRLPOOL 8c985119732f266ab75b901755d2c7f4f3d659767a840487b97fa25f084a136fe287540c0e4a3c19be90e0225561753da6f3979d24d47ca61e74f4ed8f36a67e EBUILD gitlab-ci-8.0.2.ebuild 8540 SHA256 82d924f02abdbd68a2b4bafc0b82232ebad5303bb9a9259ec2df70da662a9e40 SHA512 3a9fb89fde76f4e839cfbd23bff299a66d87ecd8e7943f87e4c69e1d25b9679a0fa7feae77264b9d0d5b1f39a529d208fa0d438d7f317b64f1a8b9b509e3e0da WHIRLPOOL 8c985119732f266ab75b901755d2c7f4f3d659767a840487b97fa25f084a136fe287540c0e4a3c19be90e0225561753da6f3979d24d47ca61e74f4ed8f36a67e +EBUILD gitlab-ci-8.0.3.ebuild 8540 SHA256 82d924f02abdbd68a2b4bafc0b82232ebad5303bb9a9259ec2df70da662a9e40 SHA512 3a9fb89fde76f4e839cfbd23bff299a66d87ecd8e7943f87e4c69e1d25b9679a0fa7feae77264b9d0d5b1f39a529d208fa0d438d7f317b64f1a8b9b509e3e0da WHIRLPOOL 8c985119732f266ab75b901755d2c7f4f3d659767a840487b97fa25f084a136fe287540c0e4a3c19be90e0225561753da6f3979d24d47ca61e74f4ed8f36a67e diff --git a/www-apps/gitlab-ci/gitlab-ci-8.0.3.ebuild b/www-apps/gitlab-ci/gitlab-ci-8.0.3.ebuild new file mode 100644 index 0000000..f8be13b --- /dev/null +++ b/www-apps/gitlab-ci/gitlab-ci-8.0.3.ebuild @@ -0,0 +1,309 @@ +# Copyright 1999-2014 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: $ + +EAPI="5" + +# Maintainer notes: +# - This ebuild uses Bundler to download and install all gems in deployment mode +# (i.e. into isolated directory inside application). That's not Gentoo way how +# it should be done, but GitLab has too many dependencies that it will be too +# difficult to maintain them via ebuilds. +# + +USE_RUBY="ruby21" +PYTHON_DEPEND="2:2.7" + +inherit eutils python ruby-ng user + +DESCRIPTION="GitLab CI is a continuous integration server that is tightly integrated with GitLab" +HOMEPAGE="https://gitlab.com/gitlab-org/gitlab-ci" +SRC_URI="https://github.com/gitlabhq/gitlab-ci/archive/v${PV}.tar.gz -> ${P}.tar.gz" + +RESTRICT="mirror" + +LICENSE="MIT" +SLOT="0" +KEYWORDS="~amd64 ~x86" +IUSE="mysql +postgres" + +## Gems dependencies: +# charlock_holmes dev-libs/icu +# grape, capybara dev-libs/libxml2, dev-libs/libxslt +# pg dev-db/postgresql +# mysql virtual/mysql +# + +GEMS_DEPEND=" + dev-libs/icu + dev-libs/libxml2 + dev-libs/libxslt + postgres? ( dev-db/postgresql ) + mysql? ( virtual/mysql )" +DEPEND="${GEMS_DEPEND} + dev-vcs/git" +RDEPEND="${DEPEND} + dev-db/redis + virtual/mta" +ruby_add_bdepend " + virtual/rubygems + >=dev-ruby/bundler-1.0" + +# no patches needed so far ... +#RUBY_PATCHES=( +#) + +MY_NAME="gitlab-ci" +MY_USER="gitlab_ci" + +DEST_DIR="/opt/${MY_NAME}" +CONF_DIR="/etc/${MY_NAME}" +LOGS_DIR="/var/log/${MY_NAME}" +TEMP_DIR="/var/tmp/${MY_NAME}" +RUN_DIR="/run/${MY_NAME}" + +# When updating ebuild to newer version, check list of the queues in +# https://gitlab.com/gitlab-org/gitlab-ci/blob/v${PV}/script/background_jobs +SIDEKIQ_QUEUES="runner,common,default" + +pkg_setup() { + enewgroup gitlab_ci + enewuser gitlab_ci -1 /bin/bash ${DEST_DIR} "gitlab_ci,cron,redis" +} + +all_ruby_prepare() { + + # fix paths + sed -i -E \ + -e "s|redis://redis.example.com:6379|unix:/run/redis/redis.sock|" \ + config/resque.yml.example || die "failed to filter resque.yml.example" + sed -i -E \ + -e "s|/home/gitlab_ci/gitlab-ci/tmp/(pids\|sockets)|${RUN_DIR}|" \ + -e "s|/home/gitlab_ci/gitlab-ci/log|${LOGS_DIR}|" \ + -e "s|/home/gitlab_ci/gitlab-ci|${DEST_DIR}|" \ + config/unicorn.rb.example || die "failed to filter unicorn.rb.example" + + sed -i \ + -e "s|/home/gitlab_ci/gitlab-ci/tmp/sockets|${RUN_DIR}|" \ + -e "s|/home/gitlab_ci/gitlab-ci/public|${DEST_DIR}/public|" \ + lib/support/nginx/gitlab_ci || die "failed to filter nginx/gitlab_ci" + + # modify default database settings for PostgreSQL + sed -i -E \ + -e 's|(username:).*|\1 gitlab|' \ + -e 's|(password:).*|\1 gitlab|' \ + -e 's|(socket:).*|/run/postgresql/.s.PGSQL.5432|' \ + config/database.yml.postgresql \ + || die "failed to filter database.yml.postgresql" + # modify default database settings for MySQL + sed -i -E \ + -e "s|/tmp/mysql.sock|/run/mysqld/mysqld.sock|" \ + config/database.yml.mysql || die "failed to filter database.yml.mysql" + + # rename config files + mv config/application.yml.example config/application.yml + mv config/unicorn.rb.example config/unicorn.rb + + local dbconf=config/database.yml + if use postgres && ! use mysql; then + mv ${dbconf}.postgresql ${dbconf} + rm ${dbconf}.mysql + elif use mysql && ! use postgres; then + mv ${dbconf}.mysql ${dbconf} + rm ${dbconf}.postgresql + fi + + # remove useless files + rm -r lib/support/init.d +} + +all_ruby_install() { + local dest=${DEST_DIR} + local conf=${CONF_DIR} + local logs=${LOGS_DIR} + local temp=${TEMP_DIR} + local runs=${RUN_DIR} + + # prepare directories + diropts -m750 + dodir ${logs} ${temp} + + diropts -m755 + dodir ${conf} ${dest}/public/uploads + + dosym ${temp} ${dest}/tmp + dosym ${logs} ${dest}/log + + # install configs + insinto ${conf} + doins -r config/* + dosym ${conf} ${dest}/config + + echo 'export RAILS_ENV=production' > "${D}/${dest}/.profile" + + # remove needless dirs + rm -Rf config tmp log + + # install the rest files + # using cp 'cause doins is slow + cp -Rl * "${D}/${dest}"/ + + # install logrotate config + dodir /etc/logrotate.d + cat > "${D}/etc/logrotate.d/${MY_NAME}" <<-EOF + ${logs}/*.log { + missingok + delaycompress + compress + copytruncate + } + EOF + + ## Install gems via bundler ## + + cd "${D}/${dest}" + + local without="development test aws" + local flag; for flag in mysql postgres; do + without+="$(use $flag || echo ' '$flag)" + done + local bundle_args="--deployment ${without:+--without ${without}}" + + einfo "Running bundle install ${bundle_args} ..." + ${RUBY} /usr/bin/bundle install ${bundle_args} || die "bundler failed" + + # clean gems cache + rm -Rf vendor/bundle/ruby/*/cache + + # fix permissions + fowners -R ${MY_USER}:${MY_USER} ${dest} ${temp} ${logs} + fowners ${MY_USER}:${MY_USER} ${conf}/database.yml + fperms 640 ${conf}/database.yml + + ## RC script ## + + local rcscript=gitlab-ci-unicorn.init + + cp "${FILESDIR}/${rcscript}" "${T}" || die + sed -i \ + -e "s|@USER@|${MY_USER}|" \ + -e "s|@GITLAB_CI_BASE@|${dest}|" \ + -e "s|@LOGS_DIR@|${logs}|" \ + -e "s|@RUN_DIR@|${runs}|" \ + -e "s|@QUEUES@|${SIDEKIQ_QUEUES}|" \ + "${T}/${rcscript}" \ + || die "failed to filter ${rcscript}" + + newinitd "${T}/${rcscript}" "${MY_NAME}" +} + +pkg_postinst() { + elog + elog "1. Configure your GitLab CI's settings in ${CONF_DIR}/application.yml." + elog + elog "2. Configure your database settings in ${CONF_DIR}/database.yml" + elog " for \"production\" environment." + elog + elog "3. Adjust the webserver settings in ${CONF_DIR}/unicorn.rb" + elog + elog "4. Then you should create a database for your GitLab CI instance, if you" + elog "haven't done so already." + elog + if use postgres; then + elog "If you have local PostgreSQL running, just copy&run:" + elog " su postgres" + elog " psql -c \"CREATE ROLE gitlab_ci PASSWORD 'gitlab_ci' \\" + elog " NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;\"" + elog " createdb -E UTF-8 -O gitlab_ci gitlab_ci_production" + elog " Note: You should change your password to something more random..." + elog + fi + elog "4. Finally execute the following command to initlize environment:" + elog " emerge --config \"=${CATEGORY}/${PF}\"" + elog " Note: Do not forget to start Redis server first!" + elog + elog "If this is an update from previous version, it's HIGHLY recommended" + elog "to backup your database before running the config phase!" +} + +pkg_config() { + einfo "Checking configuration files" + + if [ ! -r "${CONF_DIR}/database.yml" ]; then + eerror "Copy ${CONF_DIR}/database.yml.* to" + eerror "${CONF_DIR}/database.yml and edit this file in order to configure your" + eerror "database settings for \"production\" environment."; die + fi + + + local email_from="$(ryaml ${CONF_DIR}/application.yml production gitlab_ci email_from)" + local gitlab_ci_home="$(egethome ${MY_USER})" + + # configure Git global settings + if [ ! -e "${gitlab_ci_home}/.gitconfig" ]; then + einfo "Setting git user" + su -l ${MY_USER} -c " + git config --global user.email '${email_from}'; + git config --global user.name 'GitLab CI'" \ + || die "failed to setup git name and email" + fi + + if [ ! -d "${DEST_DIR}/.git" ]; then + # create dummy git repo as workaround for + # https://github.com/bundler/bundler/issues/2039 + einfo "Initializing dummy git repository to avoid false errors from bundler" + su -l ${MY_USER} -c " + cd ${DEST_DIR} + git init + git add README.md + git commit -m 'Dummy repository'" >/dev/null + fi + + ## Initialize app ## + + local RAILS_ENV="production" + local RUBY=${RUBY:-/usr/bin/ruby} + local BUNDLE="${RUBY} /usr/bin/bundle" + + local dbname="$(ryaml ${CONF_DIR}/database.yml production database)" + + if [ -f "${DEST_DIR}/.secret" ]; then + local update=true + + einfo "Migrating database ..." + exec_rake db:migrate + + else + local update=false + + einfo "Initializing database ..." + exec_rake setup + + einfo "Setting up cron schedules ..." + exec_rake whenever -w + fi + + if [ "${update}" = 'true' ]; then + ewarn + ewarn "This configuration script runs only common migration tasks." + ewarn "Please read guides on" + ewarn " https://gitlab.com/gitlab-org/gitlab-ci/tree/v${PV}/doc/update" + ewarn "for any additional migration tasks specific to your previous GitLab CI" + ewarn "version." + fi +} + +ryaml() { + ruby -ryaml -e 'puts ARGV[1..-1].inject(YAML.load(File.read(ARGV[0]))) {|acc, key| acc[key] }' "$@" +} + +exec_rake() { + local command="${BUNDLE} exec rake $@ RAILS_ENV=${RAILS_ENV}" + + echo " ${command}" + su -l ${MY_USER} -c " + export LANG=en_US.UTF-8; export LC_ALL=en_US.UTF-8 + cd ${DEST_DIR} + ${command}" \ + || die "failed to run rake $@" +} diff --git a/www-apps/gitlabhq/Manifest b/www-apps/gitlabhq/Manifest index 61b8a27..dd0a9d6 100644 --- a/www-apps/gitlabhq/Manifest +++ b/www-apps/gitlabhq/Manifest @@ -10,5 +10,7 @@ AUX gitlabhq-8.0.2-fix-gemfile.patch 1586 SHA256 c91945e0e639b1297519d7165a3aa03 AUX gitlabhq-fix-sendmail-config.patch 731 SHA256 51f0d0af2a7c048d7cff56cf27955632f340ca67f9d460af840cf34ed60ca574 SHA512 b10d5b8d89927404d25345e17ba37ca4e7848b04c2ca20c5eef14eaac43d9ba14b62ae4c0d532eefaf6f9a2944578e84eb65a3420335d32495855c4807eec356 WHIRLPOOL 66f6443f311f2355ffd4efaea914f462816a1966a715b3b5ffaaa26b41bdced928b9905b8606f06fac3c2ccf20741553cfed2615430287bede01cf376aae2a60 DIST gitlabhq-7.14.3.tar.gz 6393535 SHA256 3814a3bdff9610b269be15b8cf35701fcdd78a5a80fb1b366269acc49b23f5e4 SHA512 f2088c151b424cbca0fbc65073c1198ea9c3619570ca3543cf5f0ddd193a6105941608df418eeb506bde83f2c0bbd34cea267caaed70092afcca54219e84004d WHIRLPOOL 70574a135eb426e93086502ad7a0d5b73e1070a19c529852fe2aa60c2081d27bbb4289340b73b469ecfd489779cc409bb56de263e47aaa07859ed0a14dd51f44 DIST gitlabhq-8.0.2.tar.gz 8238940 SHA256 e17a889f33c85b86744ea7be7cabb69feb340b82a4f01706360a985ceb6fd0f3 SHA512 901d0841075514af6e5f1a5a1064f81347769d024b1d0a5527de069ba29de1746ec3c27045529acd7fd993ad53ea65a08d24f3fc3fcbb2fafebc4b7c75490f97 WHIRLPOOL 19e9c1f4ea7e0106dea552bc875e2bfd1f518fe6aeefa6934772ebb29ba388eaad0715e36fa53f22fdc7e90203eea380ae62fc0dc8b7ce999efb2ee05d0cc63b +DIST gitlabhq-8.0.3.tar.gz 8238927 SHA256 b299b100f8963f86aaeab01ad4ba49ac034cf77e803cff0fa710065e3464a049 SHA512 e247b3677ca86f43e665623c3a2602ab33843860537813fa64e3cd33b408698f0482e1ce437a4a30976b0656977f86890173ca044b7d07bfdfda3d269d311802 WHIRLPOOL 710f473d8b6c06fff9e72258102653f24035d5533f257d2d6d842ae0598fb048c6e76f9706e3662a93a9d1ec34ef67a67686fdee7439fb776de686eae19120ea EBUILD gitlabhq-7.14.3.ebuild 11046 SHA256 f9af41cfd01aaa0312323a6da4dea126f1bd0c7e88aee4e143c541829eb6fdbc SHA512 dd5d4a4495f46edf66b33126659dbf4c11da7274a069a02227f1404cbc7e07f2c7bd48dc019b3c3d7239e29000204be3fba57b27d27c7b06d84cbb16ef0e1ad2 WHIRLPOOL 1ce529cf76c7b712789c6c67619afc79e8ad0f99ac9354c3428733578fdc9842c75963a73803530c22634e8c1eb5267b24f7251133c82087d397a77e9eac3edf EBUILD gitlabhq-8.0.2.ebuild 11066 SHA256 cf03c063dfc12e120a960fb22201c4593341152b2a6df3c97dff29567a250c48 SHA512 c015f35603cf8401db46f638dc583c869a21e9cfe4c076fa1c43871b2fcdf0fb2c3ce08883461d4020062e5ee88ad737d178120c2a3c6cfc5367ad1ffa719818 WHIRLPOOL 6a20a1d9f2389d0b4b0710d536dcd3053a19f8165fbe8215202114d89e026640c021737a06496a13023b21aa741a5164da5cffa6d5df47d767eb4446aaa69365 +EBUILD gitlabhq-8.0.3.ebuild 11073 SHA256 44fc58f69308d0a37402e133e6b1624de3663b07d25f4d6cd516cc8516b13231 SHA512 df16434366f00a49335f04e91686d3bf9e2145dfb907b15b6e751d3f972cbbc3a23ce5b6883a29ebae216195cd2a377a3c8cfd06a4d44394d71ce14b5b73f5d2 WHIRLPOOL 23af35480b251a05892d4f46cfbfb7f9b970149d4a8fb48af7155832626752026373c5b6a8c9a48a8d4696780ef0006c29a993d9662fb8576820f9aeef643b15 diff --git a/www-apps/gitlabhq/gitlabhq-8.0.3.ebuild b/www-apps/gitlabhq/gitlabhq-8.0.3.ebuild new file mode 100644 index 0000000..2ffb2ca --- /dev/null +++ b/www-apps/gitlabhq/gitlabhq-8.0.3.ebuild @@ -0,0 +1,367 @@ +# Copyright 1999-2014 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: $ + +EAPI="5" + +# Maintainer notes: +# - This ebuild uses Bundler to download and install all gems in deployment mode +# (i.e. into isolated directory inside application). That's not Gentoo way how +# it should be done, but GitLab has too many dependencies that it will be too +# difficult to maintain them via ebuilds. +# + +USE_RUBY="ruby21" +PYTHON_DEPEND="2:2.7" + +inherit eutils python ruby-ng user systemd + +DESCRIPTION="GitLab is a free project and repository management application" +HOMEPAGE="https://github.com/gitlabhq/gitlabhq" +SRC_URI="https://github.com/gitlabhq/gitlabhq/archive/v${PV}.tar.gz -> ${P}.tar.gz" +#SRC_URI="https://github.com/gitlabhq/gitlabhq/archive/v8.0.0.rc1.tar.gz -> ${P}.tar.gz" +#RUBY_S="${PN}-8.0.0" + +RESTRICT="mirror" + +LICENSE="MIT" +SLOT="0" +KEYWORDS="~amd64 ~x86" +IUSE="kerberos mysql +postgres +unicorn systemd rugged_use_system_libraries" + +## Gems dependencies: +# charlock_holmes dev-libs/icu +# grape, capybara dev-libs/libxml2, dev-libs/libxslt +# rugged dev-util/cmake, virtual/pkgconfig +# json dev-util/ragel +# pygments.rb python 2.7+ +# execjs net-libs/nodejs, or any other JS runtime +# pg dev-db/postgresql +# mysql virtual/mysql +# +GEMS_DEPEND=" + dev-libs/icu + dev-libs/libxml2 + dev-libs/libxslt + dev-util/cmake + dev-util/ragel + net-libs/nodejs + postgres? ( dev-db/postgresql ) + mysql? ( virtual/mysql ) + kerberos? ( virtual/krb5 ) + virtual/pkgconfig" +DEPEND="${GEMS_DEPEND} + >=dev-vcs/gitlab-shell-2.6.5 + dev-vcs/git + >=dev-vcs/gitlab-git-http-server-0.2.10 + kerberos? ( !app-crypt/heimdal ) + rugged_use_system_libraries? ( net-libs/http-parser =dev-libs/libgit2-0.22* )" +RDEPEND="${DEPEND} + dev-db/redis + virtual/mta + systemd? ( sys-apps/systemd:0= )" +ruby_add_bdepend " + virtual/rubygems + >=dev-ruby/bundler-1.0" + +# +# fix-gemfile: +# Remove therubyracer that doesn't compile well on Gentoo (we're using +# nodejs instead that is faster and better). Also replace broken +# charlock_holmes version with fixed one. +# +# fix-sendmail-config: +# Fix default settings to work with ssmtp that doesn't know '-t' argument. +# +RUBY_PATCHES=( + "${PN}-8.0.2-fix-gemfile.patch" + "${PN}-fix-sendmail-config.patch" +) + +MY_NAME="gitlab" +MY_USER="git" # should be same as in gitlab-shell + +DEST_DIR="/opt/${MY_NAME}" +CONF_DIR="/etc/${MY_NAME}" +LOGS_DIR="/var/log/${MY_NAME}" +TEMP_DIR="/var/tmp/${MY_NAME}" + +# When updating ebuild to newer version, check list of the queues in +# https://gitlab.com/gitlab-org/gitlab-ce/blob/v${PV}/bin/background_jobs +SIDEKIQ_QUEUES="post_receive,mailer,archive_repo,system_hook,project_web_hook,gitlab_shell,common,default" + +all_ruby_prepare() { + # fix paths + local satellites_path="${TEMP_DIR}/repo_satellites" + local repos_path=/var/lib/git/repositories + local shell_path=/usr/share/gitlab-shell + sed -i -E \ + -e "/satellites:$/,/\w:$/ s|(\s*path:\s).*|\1${satellites_path}/|" \ + -e "/gitlab_shell:$/,/\w:$/ s|(\s*path:\s).*|\1${shell_path}/|" \ + -e "/gitlab_shell:$/,/\w:$/ s|(\s*repos_path:\s).*|\1${repos_path}/|" \ + -e "/gitlab_shell:$/,/\w:$/ s|(\s*hooks_path:\s).*|\1${shell_path}/hooks/|" \ + config/gitlab.yml.example || die "failed to filter gitlab.yml.example" + + local run_path=/run/${MY_NAME} + sed -i -E \ + -e "s|/home/git/gitlab/tmp/(pids\|sockets)|${run_path}|" \ + -e "s|/home/git/gitlab/log|${LOGS_DIR}|" \ + -e "s|/home/git/gitlab|${DEST_DIR}|" \ + config/unicorn.rb.example || die "failed to filter unicorn.rb.example" + + sed -i \ + -e "s|/home/git/gitlab/tmp/sockets|${run_path}|" \ + lib/support/nginx/gitlab || die "failed to filter nginx/gitlab" + + # modify default database settings for PostgreSQL + sed -i -E \ + -e 's|(username:).*|\1 gitlab|' \ + -e 's|(password:).*|\1 gitlab|' \ + -e 's|(socket:).*|\1 /run/postgresql/.s.PGSQL.5432|' \ + config/database.yml.postgresql \ + || die "failed to filter database.yml.postgresql" + + # rename config files + mv config/gitlab.yml.example config/gitlab.yml + mv config/unicorn.rb.example config/unicorn.rb + + local dbconf=config/database.yml + if use postgres && ! use mysql; then + mv ${dbconf}.postgresql ${dbconf} + rm ${dbconf}.mysql + elif use mysql && ! use postgres; then + mv ${dbconf}.mysql ${dbconf} + rm ${dbconf}.postgresql + fi + + # remove useless files + rm -r lib/support/{deploy,init.d} + use unicorn || rm config/unicorn.rb +} + +all_ruby_install() { + local dest=${DEST_DIR} + local conf=${CONF_DIR} + local logs=${LOGS_DIR} + local temp=${TEMP_DIR} + + # prepare directories + diropts -m750 + dodir ${logs} ${temp} ${temp}/repo_satellites + + diropts -m755 + dodir ${conf} ${dest}/public/uploads + + dosym ${temp} ${dest}/tmp + dosym ${logs} ${dest}/log + + # install configs + insinto ${conf} + doins -r config/* + dosym ${conf} ${dest}/config + + echo 'export RAILS_ENV=production' > "${D}/${dest}/.profile" + + # remove needless dirs + rm -Rf config tmp log + + # install the rest files + # using cp 'cause doins is slow + cp -Rl * "${D}/${dest}"/ + + # install logrotate config + dodir /etc/logrotate.d + cat > "${D}/etc/logrotate.d/${MY_NAME}" <<-EOF + ${logs}/*.log { + missingok + delaycompress + compress + copytruncate + } + EOF + + ## Install gems via bundler ## + + cd "${D}/${dest}" + + local without="development test aws" + local flag; for flag in mysql postgres unicorn kerberos; do + without+="$(use $flag || echo ' '$flag)" + done + local bundle_args="--deployment ${without:+--without ${without}}" + + use "rugged_use_system_libraries" && export RUGGED_USE_SYSTEM_LIBRARIES="YES" + + einfo "Running bundle install ${bundle_args} ..." + ${RUBY} /usr/bin/bundle install ${bundle_args} || die "bundler failed" + + # clean gems cache + rm -Rf vendor/bundle/ruby/*/cache + + # fix permissions + fowners -R ${MY_USER}:${MY_USER} ${dest} ${temp} ${logs} + + ## RC script ## + + if use systemd ; then + ewarn "Beware: systemd support has not been tested, use at your own risk!" + systemd_dounit "${FILESDIR}/gitlab-sidekiq.service" + systemd_dounit "${FILESDIR}/gitlab-unicorn.service" + systemd_dotmpfilesd "${FILESDIR}/gitlab.conf" + else + local rcscript=gitlab-sidekiq-8.init + use unicorn && rcscript=gitlab-unicorn-8.init + + cp "${FILESDIR}/${rcscript}" "${T}" || die + sed -i \ + -e "s|@USER@|${MY_USER}|" \ + -e "s|@GITLAB_BASE@|${dest}|" \ + -e "s|@LOGS_DIR@|${logs}|" \ + -e "s|@QUEUES@|${SIDEKIQ_QUEUES}|" \ + "${T}/${rcscript}" \ + || die "failed to filter ${rcscript}" + + newinitd "${T}/${rcscript}" "${MY_NAME}" + fi +} + +pkg_postinst() { + elog + elog "1. Configure your GitLab's settings in ${CONF_DIR}/gitlab.yml." + elog + elog "2. Configure your database settings in ${CONF_DIR}/database.yml" + elog " for \"production\" environment." + elog + elog "3. Then you should create a database for your GitLab instance, if you" + elog "haven't done so already." + elog + if use postgres; then + elog "If you have local PostgreSQL running, just copy&run:" + elog " su postgres" + elog " psql -c \"CREATE ROLE gitlab PASSWORD 'gitlab' \\" + elog " NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;\"" + elog " createdb -E UTF-8 -O gitlab gitlabhq_production" + elog " Note: You should change your password to something more random..." + elog + fi + elog "4. Finally execute the following command to initlize environment:" + elog " emerge --config \"=${CATEGORY}/${PF}\"" + elog " Note: Do not forget to start Redis server first!" + elog + elog "If this is an update from previous version, it's HIGHLY recommended" + elog "to backup your database before running the config phase!" + elog + elog "If you're running GitLab behind an SSL proxy such as nginx or Apache and" + elog "you can't login after the upgrade, be sure to read the section about the" + elog "verification of the CSRF token in GitLab's trouble-shooting guide at" + elog "http://goo.gl/5XGRGv." +} + +pkg_config() { + local shell_conf='/etc/gitlab-shell.yml' + + einfo "Checking configuration files" + + if [ ! -r "${CONF_DIR}/database.yml" ]; then + eerror "Copy ${CONF_DIR}/database.yml.* to" + eerror "${CONF_DIR}/database.yml and edit this file in order to configure your" + eerror "database settings for \"production\" environment."; die + fi + + # check gitlab-shell configuration + if [ -r ${shell_conf} ]; then + local shell_repos_path="$(ryaml ${shell_conf} repos_path)" + local gitlab_repos_path="$(ryaml ${CONF_DIR}/gitlab.yml \ + production gitlab_shell repos_path)" + + if [ ! "${shell_repos_path}" -ef "${gitlab_repos_path}" ]; then + eerror "repos_path in ${CONF_DIR}/gitlab.yml and ${shell_conf}" + eerror "must points to the same location! Fix the repos_path location and" + eerror "run this again."; die + fi + else + ewarn "GitLab Shell checks skipped, could not find config file at" + ewarn "${shell_conf}. Make sure that you have gitlab-shell properly" + ewarn "installed and that repos_path is the same as in GitLab." + fi + + local email_from="$(ryaml ${CONF_DIR}/gitlab.yml production gitlab email_from)" + local git_home="$(egethome ${MY_USER})" + + # configure Git global settings + if [ ! -e "${git_home}/.gitconfig" ]; then + einfo "Setting git user" + su -l ${MY_USER} -c " + git config --global user.email '${email_from}'; + git config --global user.name 'GitLab'" \ + || die "failed to setup git name and email" + fi + + if [ ! -d "${DEST_DIR}/.git" ]; then + # create dummy git repo as workaround for + # https://github.com/bundler/bundler/issues/2039 + einfo "Initializing dummy git repository to avoid false errors from bundler" + su -l ${MY_USER} -c " + cd ${DEST_DIR} + git init + git add README.md + git commit -m 'Dummy repository'" >/dev/null + fi + + ## Initialize app ## + + local RAILS_ENV="production" + local RUBY=${RUBY:-/usr/bin/ruby} + local BUNDLE="${RUBY} /usr/bin/bundle" + + local dbname="$(ryaml ${CONF_DIR}/database.yml production database)" + + if [ -f "${DEST_DIR}/.secret" ]; then + local update=true + + einfo "Migrating database ..." + exec_rake db:migrate + + # https://github.com/gitlabhq/gitlabhq/issues/5311#issuecomment-31656496 + einfo "Migrating iids ..." + exec_rake migrate_iids + + einfo "Cleaning old precompiled assets ..." + exec_rake assets:clean + + einfo "Cleaning cache ..." + exec_rake cache:clear + else + local update=false + + einfo "Initializing database ..." + exec_rake gitlab:setup + fi + + einfo "Precompiling assests ..." + exec_rake assets:precompile + + if [ "${update}" = 'true' ]; then + ewarn + ewarn "This configuration script runs only common migration tasks." + ewarn "Please read guides on" + ewarn " https://github.com/gitlabhq/gitlabhq/blob/master/doc/update/" + ewarn "for any additional migration tasks specific to your previous GitLab" + ewarn "version." + fi +} + +ryaml() { + ruby -ryaml -e 'puts ARGV[1..-1].inject(YAML.load(File.read(ARGV[0]))) {|acc, key| acc[key] }' "$@" +} + +exec_rake() { + local command="${BUNDLE} exec rake $@ RAILS_ENV=${RAILS_ENV}" + + echo " ${command}" + su -l ${MY_USER} -c " + export LANG=en_US.UTF-8; export LC_ALL=en_US.UTF-8 + cd ${DEST_DIR} + ${command}" \ + || die "failed to run rake $@" +}