Skip to content

Instantly share code, notes, and snippets.

@LiberQuack
Last active August 24, 2017 17:18
Show Gist options
  • Save LiberQuack/3a41773cb6e3e0d6b3f8440498c6186e to your computer and use it in GitHub Desktop.
Save LiberQuack/3a41773cb6e3e0d6b3f8440498c6186e to your computer and use it in GitHub Desktop.
## TODO
## Change default artifact expiration to 1 year
#Official installation instructions https://goo.gl/P6BFtf
#Requires Docker
GIT_LAB_HOSTNAME=gitlab.coddera.com
GIT_LAB_CE_VERSION=9.5.0-ce.0
GIT_LAB_RUNNER_VERSION=v9.5.0
GIT_LAB_NET=gitlab-net
#Create gitlab network
docker network create $GIT_LAB_NET
#Run Gitlab Container
#Admin login: root
sudo docker run --detach \
--hostname ${GIT_LAB_HOSTNAME} \
--net=${GIT_LAB_NET} \
-p 443:443 -p 80:80 -p 10022:22 \
--name ${GIT_LAB_HOSTNAME} \
--volume /srv/gitlab/config:/etc/gitlab \
--volume /srv/gitlab/logs:/var/log/gitlab \
--volume /srv/gitlab/data:/var/opt/gitlab \
--memory="1g" \
--restart always \
gitlab/gitlab-ce:$GIT_LAB_CE_VERSION
#Custom ssh port
cat <<EOF >> /srv/gitlab/config/gitlab.rb
gitlab_rails['gitlab_shell_ssh_port'] = 10022
EOF
#Decrease a little gitlab memory consumption problem
#Hope future versions of gitlab docker image get fixed
#See more https://goo.gl/8qBB29
cat <<EOF >> /srv/gitlab/config/gitlab.rb
sidekiq['concurrency'] = 1
unicorn['worker_processes'] = 1
EOF
#Get Bitbucket OAuth... https://goo.gl/SBES58
BB_APP_KEY=wGJTqUchVsesMxqkUt
BB_APP_SECRET=xtsEJwYFeL5UtCvDC5PgqzgMsrhRPuee
cat <<EOF >> /srv/gitlab/config/gitlab.rb
gitlab_rails['omniauth_providers'] = [{
"name" => "bitbucket",
"app_id" => "${BB_APP_KEY}",
"app_secret" => "${BB_APP_SECRET}",
"url" => "https://bitbucket.org/"
}]
EOF
##Config gitlab proxy
#cat <<EOF >> /srv/gitlab/config/gitlab.rb
#gitlab_rails['env'] = {
# "http_proxy" => "http://tmartins:Roguetr!p1@10.25.4.5:3128",
# "https_proxy"=> "http://tmartins:Roguetr!p1@10.25.4.5:3128",
# "HTTP_PROXY" => "http://tmartins:Roguetr!p1@10.25.4.5:3128",
# "HTTPS_PROXY"=> "http://tmartins:Roguetr!p1@10.25.4.5:3128"
#}
#EOF
#####################################
## RUNNERS ##
#####################################
#Get token from http://host/admin/runners
RUNNER_TOKEN=sw4xsoQHv2CWcPed1jRo
#GitLab Runner with docker client... See https://goo.gl/dz4pir
docker run -d --name gitlab-runner \
--restart always \
--name gitlab-runner \
--net=$GIT_LAB_NET \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /srv/gitlab-runner/config:/etc/gitlab-runner \
gitlab/gitlab-runner:$GIT_LAB_RUNNER_VERSION
#Register Docker Runner
#TODO: "--run-untagged true" seems to be not working
docker exec -t gitlab-runner bash -c "
gitlab-runner register --non-interactive \
--url http://${GIT_LAB_HOSTNAME} \
--executor docker \
--registration-token ${RUNNER_TOKEN} \
--tag-list docker \
--docker-network-mode ${GIT_LAB_NET} \
--docker-image ubuntu:16 \
--run-untagged true
"
#Full host (See runner install inscrutions here https://docs.gitlab.com/runner/install/linux-manually.html)
perl -pi -e "s/localhost/localhost ${GIT_LAB_HOSTNAME}/g" /etc/hosts &&
wget -O /usr/local/bin/gitlab-runner https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-ci-multi-runner-linux-amd64 &&
chmod +x /usr/local/bin/gitlab-runner &&
useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash &&
gitlab-runner register --non-interactive \
--url http://localhost \
--executor shell \
--registration-token ${RUNNER_TOKEN} \
--tag-list docker-full \
--run-untagged false &&
gpasswd -a gitlab-runner docker &&
gitlab-runner install --user=root --working-directory=/home/gitlab-runner &&
gitlab-runner start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment