Skip to content

Instantly share code, notes, and snippets.

@blind-coder
Last active December 13, 2015 17:29
Show Gist options
  • Save blind-coder/4948038 to your computer and use it in GitHub Desktop.
Save blind-coder/4948038 to your computer and use it in GitHub Desktop.
Quick'n'dirty howto on getting gitlab up and running in a smartos zone.
# Install necessary packages
pkgin up
pkgin -y install \
bash \
coreutils-8.13nb4 \
curl \
gcc47-4.7.0nb2 \
gcc47-runtime-4.7.0nb2 \
gmake-3.82nb5 \
icu-49.1.1nb1 \
libxml2-2.8.0nb3 \
libxslt-1.1.26nb3 \
patch \
redis-2.6.7 \
scmgit-1.7.10.5 \
scons-1.3.1nb2
# Enable redis server, needed for gitlab later
svcadm enable redis
# Disable cURLs HTTPS Certificate checking. DANGER! BE CAREFUL!
echo insecure >> ~/.curlrc
# Install RVM, Ruby and rails
curl -L get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
rvm install ruby
rvm use 1.9.3 --default
# Create users
groupadd git
useradd -s /bin/sh -c 'Git Version Control' -g git -d /home/git -m git
passwd git # supermegaultralongpasswordthatnoonewilleverrememberyetaloneguess
useradd -s /bin/false -d /home/git -m -c GitLab gitlab
usermod -G git gitlab
sudo -u gitlab -H ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa
# Clone gitlab
cd /home/git
sudo -u git -H git clone -b gl-v320 https://github.com/gitlabhq/gitolite.git /home/git/gitolite
# Add Gitolite scripts to $PATH
sudo -u git -H mkdir /home/git/bin
sudo -u git -H sh -c 'printf "%b\n%b\n" "PATH=\$PATH:/home/git/bin" "export PATH" >> /home/git/.profile'
sudo -u git -H sh -c 'gitolite/install -ln /home/git/bin'
# Copy the gitlab user's (public) SSH key ...
sudo cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub
sudo chmod 0444 /home/git/gitlab.pub
# ... and use it as the admin key for the Gitolite setup
sudo -u git -H sh -c "PATH=/home/git/bin:$PATH; gitolite setup -pk /home/git/gitlab.pub"
# Make sure the Gitolite config dir is owned by git
sudo chmod 750 /home/git/.gitolite/
sudo chown -R git:git /home/git/.gitolite/
# Make sure the repositories dir is owned by git and it stays that way
sudo chmod -R ug+rwXs,o-rwx /home/git/repositories/
sudo chown -R git:git /home/git/repositories/
sudo -u gitlab -H ssh git@localhost
sudo -u gitlab -H ssh git@<NODENAME>
sudo -u gitlab -H ssh git@<FQDN>
# Clone the admin repo so SSH adds localhost to known_hosts ...
# ... and to be sure your users have access to Gitolite
sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin
# IF THIS DOESN'T WORK, FIND OUT WHY BEFORE CONTINUEING!
rm -r /tmp/gitolite-admin/
# Here you set up a MySQL or postgreSQL Database
# I'll give the example for a local MySQL
# Install client and server
pkgin -y install mysql-client-5.5.25 mysql-server-5.5.25
# Setup MySQL
svcadm enable mysql
mysqladmin -u root -p password
mysql -u root -p
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '$password';
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
mysql> \q
# Try connecting to the new database with the new user
sudo -u gitlab -H mysql -u gitlab -p -D gitlabhq_production
# GitLab
cd /home/gitlab
# Clone GitLab repository
sudo -u gitlab -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab
# Go to gitlab dir
cd /home/gitlab/gitlab
# Checkout to stable release
sudo -u gitlab -H git checkout 4-1-stable
# Copy the example GitLab config
sudo -u gitlab -H cp config/gitlab.yml.example config/gitlab.yml
# Make sure to change "localhost" to the fully-qualified domain name of your
# host serving GitLab where necessary
# Also change /usr/bin/git to /opt/local/bin/git
sudo -u gitlab -H vim config/gitlab.yml
# Make sure GitLab can write to the log/ and tmp/ directories
sudo chown -R gitlab log/
sudo chown -R gitlab tmp/
sudo chmod -R u+rwX log/
sudo chmod -R u+rwX tmp/
# Make directory for satellites
sudo -u gitlab -H mkdir /home/gitlab/gitlab-satellites
# Copy the example Unicorn config
sudo -u gitlab -H cp config/unicorn.rb.example config/unicorn.rb
# Mysql
sudo -u gitlab cp config/database.yml.mysql config/database.yml
vim config/database.yml
# Adapt Gemfile
# Change version of grape from "~> 0.2.1" to "0.2.1"
vim Gemfile
# The next command will FAIL on therubyracer.
# If you use MySQL
bundle install --without development test postgres
# If you use postgreSQL
bundle install --without development test mysql
# Let's fix this
gem install libv8 -v 3.11.8.13
# This command will ALSO fail. Don't worry!
gem install therubyracer -v 0.11.3
# Let's fix some more:
cd /usr/local/rvm/gems/ruby-1.9.3-p385/gems/therubyracer-0.11.3/ext/v8
vim Makefile
# Search for DLDFLAGS and append -mimpure-text
DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG) -mimpure-text
# Save and close
make
cd ../..
gem build therubyracer.gemspec
mkdir /home/gitlab/gems
cp therubyracer-0.11.3.gem /home/gitlab/gems
cd /home/gitlab/gems
gem unpack therubyracer-0.11.3.gem
# Finally, update Gemfile again
cd /home/gitlab/gitlab
vim Gemfile
# Search for therubyracer and add the version number and :path
gem "therubyracer", "0.11.3", :path => "/home/gitlab/gems/therubyracer-0.11.3"
# Run bundle again
bundle install --without development test postgres
# Install the bundler, otherwise the gitlab user won't find it.
# Yes, there's always one illogical step in any HowTo :-(
gem install bundler
chown gitlab:other .bundle -R
# Now run as gitlab
sudo -u gitlab -H bundle install --deployment --without development test postgres
# Configure git as necessary:
sudo -u gitlab -H git config --global user.name "GitLab"
sudo -u gitlab -H git config --global user.email "gitlab@localhost"
# Setup hooks
sudo cp ./lib/hooks/post-receive /home/git/.gitolite/hooks/common/post-receive
sudo chown git:git /home/git/.gitolite/hooks/common/post-receive
# Setup database
sudo -u gitlab -H bundle exec rake gitlab:setup RAILS_ENV=production
# Install initscript
sudo curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/4-1-stable/init.d/gitlab
sudo chmod +x /etc/init.d/gitlab
# Create init script
sudo curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/4-1-stable/init.d/gitlab
cd /etc/rc2.d/
ln -s ../init.d/gitlab S99gitlab
# Add the following lines at the beginning of /etc/init.d/gitlab
. /etc/profile
export PATH=/usr/local/rvm/gems/ruby-1.9.3-p385/bin:/usr/local/rvm/gems/ruby-1.9.3-p385@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p385/bin:/usr/local/rvm/bin:/opt/local/gnu/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/usr/sbin
# Check gitlab status:
sudo -u gitlab -H bundle exec rake gitlab:env:info RAILS_ENV=production
# More thorough check:
sudo -u gitlab -H bundle exec rake gitlab:check RAILS_ENV=production
# Install nginx
sudo apt-get install nginx
sudo curl --output /tmp/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/4-1-stable/nginx/gitlab
# Merge the /tmp/gitlab with the /opt/local/etc/nginx/httpd.conf file
# Start nginx
svcadm enable nginx
# You should now be able to log in to gitlab on http://<your.IP.add.ress>/
# Username: admin@local.host
# Password: 5iveL!fe
# Have a lot of fun!
# More information at: https://github.com/gitlabhq/gitlabhq/blob/stable/doc/install/installation.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment