├── .gitignore ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md └── assets └── setup └── install /.gitignore: -------------------------------------------------------------------------------- 1 | *.bz2 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM sameersbn/gitlab-ci-runner:latest 2 | MAINTAINER sameer@damagehead.com 3 | 4 | RUN apt-get update && \ 5 | apt-get install -y build-essential cmake openssh-server \ 6 | ruby2.1-dev libmysqlclient-dev zlib1g-dev libyaml-dev libssl-dev \ 7 | libgdbm-dev libreadline-dev libncurses5-dev libffi-dev \ 8 | libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev \ 9 | mysql-server mysql-client redis-server fontconfig && \ 10 | gem install --no-document bundler && \ 11 | rm -rf /var/lib/apt/lists/* # 20150613 12 | 13 | ADD assets/ /app/ 14 | RUN chmod 755 /app/setup/install 15 | RUN /app/setup/install 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Sameer Naik 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: build 2 | 3 | build: 4 | @docker build --tag=${USER}/runner-gitlab . 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > **NOTICE**: 2 | > 3 | > End-Of-Life. 4 | 5 | # Table of Contents 6 | - [Introduction](#introduction) 7 | - [Contributing](#contributing) 8 | - [Installation](#installation) 9 | - [Quick Start](#quick-start) 10 | - [Data Store](#data-store) 11 | - [Shell Access](#shell-access) 12 | - [Upgrading](#upgrading) 13 | 14 | # Introduction 15 | 16 | A CI runner for gitlab-ce. 17 | 18 | Built on top of the [sameersbn/gitlab-ci-runner](https://github.com/sameersbn/docker-gitlab-ci-runner) base image, this repo demonstrates the use of sameersbn/gitlab-ci-runner to build a runner for your project. 19 | 20 | Since we inherit the [sameersbn/gitlab-ci-runner](https://github.com/sameersbn/docker-gitlab-ci-runner) base image, we also inherit its runtime. This means we only have to setup the image to satisfy your projects build requirements which in this case is gitlab-ce. 21 | 22 | All package installations are performed in the [Dockerfile](https://github.com/sameersbn/docker-runner-gitlab/blob/master/Dockerfile) while the system configuration, such as mysql and redis setup, are performed in the [install](https://github.com/sameersbn/docker-runner-gitlab/blob/master/assets/setup/install) script. 23 | 24 | Rest of this document describes use of the runner to perform continuous integration of gitlab-ce. 25 | 26 | # Contributing 27 | 28 | If you find this image useful here's how you can help: 29 | 30 | - Send a Pull Request with your awesome new features and bug fixes 31 | - Help new users with [Issues](https://github.com/sameersbn/docker-runner-gitlab/issues) they may encounter 32 | - Support the development of this image with a [donation](http://www.damagehead.com/donate/) 33 | 34 | # Installation 35 | 36 | Pull the latest version of the image from the docker index. 37 | 38 | ```bash 39 | docker pull sameersbn/runner-gitlab:latest 40 | ``` 41 | 42 | Alternately you can build the image yourself. 43 | 44 | ```bash 45 | git clone https://github.com/sameersbn/docker-runner-gitlab.git 46 | cd docker-runner-gitlab 47 | docker build --tag="$USER/runner-gitlab" . 48 | ``` 49 | 50 | # Quick Start 51 | For a runner to do its trick, it has to first be registered/authorized on the GitLab CI server. This can be done by running the image with the **app:setup** command. 52 | 53 | ```bash 54 | mkdir -p /opt/runner-gitlab 55 | docker run --name runner-gitlab -i -t --rm \ 56 | -v /opt/runner-gitlab:/home/gitlab_ci_runner/data \ 57 | sameersbn/runner-gitlab:latest app:setup 58 | ``` 59 | 60 | The command will prompt you to specify the location of the GitLab CI server and provide the registration token to access the server. With this out of the way the image is ready, lets get is started. 61 | 62 | ```bash 63 | docker run --name runner-gitlab -d \ 64 | -v /opt/runner-gitlab:/home/gitlab_ci_runner/data \ 65 | sameersbn/runner-gitlab:latest 66 | ``` 67 | 68 | You now have the runner to perform continous integration of GitLab CE. 69 | 70 | Login to your GitLab CI server and add a CI build for gitlab-ce with the following build settings 71 | 72 | ```bash 73 | ruby -v 74 | cp config/database.yml.mysql config/database.yml 75 | cp config/gitlab.yml.example config/gitlab.yml 76 | sed "s/username\:.*$/username\: runner/" -i config/database.yml 77 | sed "s/password\:.*$/password\: 'password'/" -i config/database.yml 78 | sed "s/gitlabhq_test/gitlabhq_test_$((RANDOM/5000))/" -i config/database.yml 79 | touch log/application.log 80 | touch log/test.log 81 | bundle --without postgres 82 | bundle exec rake db:create RAILS_ENV=test 83 | bundle exec rake gitlab:test RAILS_ENV=test 84 | ``` 85 | 86 | # Data Store 87 | GitLab CI Runner saves the configuration for connection and access to the GitLab CI server. In addition, SSH keys are generated as well. To make sure this configuration is not lost when when the container is stopped/deleted, we should mount a data store volume at 88 | 89 | * /home/gitlab_ci_runner/data 90 | 91 | Volumes can be mounted in docker by specifying the **'-v'** option in the docker run command. 92 | 93 | ```bash 94 | mkdir /opt/runner-gitlab 95 | docker run --name runner-gitlab -d -h runner-gitlab.local.host \ 96 | -v /opt/runner-gitlab:/home/gitlab_ci_runner/data \ 97 | sameersbn/runner-gitlab:latest 98 | ``` 99 | 100 | # Shell Access 101 | 102 | For debugging and maintenance purposes you may want access the containers shell. If you are using docker version `1.3.0` or higher you can access a running containers shell using `docker exec` command. 103 | 104 | ```bash 105 | docker exec -it runner-gitlab bash 106 | ``` 107 | 108 | If you are using an older version of docker, you can use the [nsenter](http://man7.org/linux/man-pages/man1/nsenter.1.html) linux tool (part of the util-linux package) to access the container shell. 109 | 110 | Some linux distros (e.g. ubuntu) use older versions of the util-linux which do not include the `nsenter` tool. To get around this @jpetazzo has created a nice docker image that allows you to install the `nsenter` utility and a helper script named `docker-enter` on these distros. 111 | 112 | To install `nsenter` execute the following command on your host, 113 | 114 | ```bash 115 | docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter 116 | ``` 117 | 118 | Now you can access the container shell using the command 119 | 120 | ```bash 121 | sudo docker-enter runner-gitlab 122 | ``` 123 | 124 | For more information refer https://github.com/jpetazzo/nsenter 125 | 126 | ## Upgrading 127 | 128 | To update the runner, simply stop the image and pull the latest version from the docker index. 129 | 130 | ```bash 131 | docker stop runner-gitlab 132 | docker pull sameersbn/runner-gitlab:latest 133 | docker run --name runner-gitlab -d [OPTIONS] sameersbn/runner-gitlab:latest 134 | ``` 135 | -------------------------------------------------------------------------------- /assets/setup/install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | adduser --disabled-login --gecos 'GitLab' git 5 | 6 | # disable pam authentication for sshd 7 | sed 's/UsePAM yes/UsePAM no/' -i /etc/ssh/sshd_config 8 | sed 's/UsePrivilegeSeparation yes/UsePrivilegeSeparation no/' -i /etc/ssh/sshd_config 9 | echo "UseDNS no" >> /etc/ssh/sshd_config 10 | 11 | # configure supervisor to start sshd 12 | mkdir -p /var/run/sshd 13 | cat > /etc/supervisor/conf.d/sshd.conf < /etc/supervisor/conf.d/mysqld.conf < /etc/supervisor/conf.d/redis-server.conf </dev/null 2>&1 55 | do 56 | timeout=$(($timeout - 1)) 57 | if [ $timeout -eq 0 ]; then 58 | echo "Could not connect to mysql server. Aborting..." 59 | exit 1 60 | fi 61 | echo "Waiting for database server to accept connections..." 62 | sleep 1 63 | done 64 | 65 | # create user for the runner 66 | mysql -uroot -e "CREATE USER 'runner'@'localhost' IDENTIFIED BY 'password';" 67 | mysql -uroot -e "GRANT ALL PRIVILEGES ON * . * TO 'runner'@'localhost';" 68 | mysql -uroot -e "FLUSH PRIVILEGES;" 69 | 70 | # install phantomjs at /app prefix 71 | mkdir -p /app/phantomjs 72 | PHANTOMJS_VERSION=1.8.1 73 | if [ -f /app/setup/phantomjs-${PHANTOMJS_VERSION}-linux-x86_64.tar.bz2 ]; then 74 | tar -jvxf /app/setup/phantomjs-${PHANTOMJS_VERSION}-linux-x86_64.tar.bz2 --strip=1 -C /app/phantomjs/ 75 | else 76 | wget "http://phantomjs.googlecode.com/files/phantomjs-${PHANTOMJS_VERSION}-linux-x86_64.tar.bz2" -O - | tar -jvxf - --strip=1 -C /app/phantomjs/ 77 | fi 78 | ln -s /app/phantomjs/bin/phantomjs /usr/bin/phantomjs 79 | phantomjs --version 80 | --------------------------------------------------------------------------------