Sign inSign up

ubergarm/gitlab-ci-runner

By ubergarm

Updated almost 11 years ago

Gitlab CI Runner to build Docker images.

Image
0

1.2K

ubergarm/gitlab-ci-runner repository overview

You can use this Gitlab CI runner image to quickly register and start building Docker images and pushing build artifacts to your private registry.

Start Container:

Make sure to bind mount the docker.sock and docker binary at the actual location it is on your host machine and pass in the correct ENV variables. Optionally mount in a .dockercfg file containing credentials into the /root directory if you'd like to automate docker push to any registry.

docker run --name runner \                                           
          -d \
          -e CI_SERVER_URL=https://my.ciserver.com \
          -e REGISTRATION_TOKEN=12345678901234567890 \
          -v /var/run/docker.sock:/var/run/docker.sock \
          -v `which docker`:/usr/bin/docker \
          -v $HOME/.dockercfg:/root/.dockercfg \
          ubergarm/gitlab-ci-runner

Dockerfile:

FROM debian:jessie

# install packages
RUN DEBIAN_FRONTEND=noninteractive \
    apt-get update && apt-get install -y \
    wget \
    curl \
    gcc \
    libxml2-dev \
    libxslt-dev \
    libcurl4-openssl-dev \
    libreadline6-dev \
    libc6-dev \
    libssl-dev \
    make \
    build-essential \
    zlib1g-dev \
    openssh-server \
    git-core \
    libyaml-dev \
    postfix \
    libpq-dev \
    libicu-dev \
    vim-tiny \
    locales \
    sudo

# Configure preferences
RUN update-alternatives --set editor /usr/bin/vim.tiny

# Configure locale
RUN dpkg-reconfigure locales && \
    locale-gen C.UTF-8 && \
    /usr/sbin/update-locale LANG=C.UTF-8
ENV LC_ALL C.UTF-8

# Configure timezone
RUN echo "Etc/UTC" > /etc/timezone
RUN dpkg-reconfigure -f noninteractive tzdata

# Install Ruby
RUN mkdir /tmp/ruby && \
    cd /tmp/ruby && \
    curl --progress http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p481.tar.gz | tar xz && \
    cd ruby-2.0.0-p481 && \
    ./configure --disable-install-rdoc && \
    make && \
    make install && \
    gem install bundler

# Create user
RUN echo "gitlab_ci_runner ALL=(ALL) NOPASSWD: /usr/bin/docker"  >> /etc/sudoers
RUN adduser --disabled-login --gecos 'GitLab CI Runner' gitlab_ci_runner

# Become gitlab_ci_runner user
USER gitlab_ci_runner
ENV HOME /home/gitlab_ci_runner
WORKDIR /home/gitlab_ci_runner
RUN git clone http://gitlab.com/gitlab-org/gitlab-ci-runner.git
WORKDIR /home/gitlab_ci_runner/gitlab-ci-runner
RUN bundle install --deployment

CMD /bin/bash -c 'bundle exec ./bin/setup && \
                exec bundle exec ./bin/runner'

Gitlab-CI:

Setup a build script something along these lines to automate builds and push to your registry.

#!/bin/bash
# Assumes valid ~/.dockercfg with credentials for your registry to push.
set -e
set -x
echo "-----> Initializing variables..."
NAMESPACE=ubergarm
PROJECT_NAME=myapp
GIT_REF=`git rev-parse --short HEAD`
IMAGE_NAME=$NAMESPACE/$PROJECT_NAME:$GIT_REF
REG_URL=my.registry.com
echo "-----> Pulling upstream Docker images..."
sudo docker pull debian:jessie
echo "-----> Building Docker image..."
sudo docker build -t $IMAGE_NAME .
echo "-----> Inspecting resulting image..."
sudo docker inspect $IMAGE_NAME
echo "-----> Tagging image to private registry namespace..."
sudo docker tag $IMAGE_NAME $REG_URL/$PROJECT_NAME:$GIT_REF
echo "-----> Pushing image to private registry..."
sudo docker push $REG_URL/$PROJECT_NAME:$GIT_REF
echo "-----> Done!"

Pro-Tips:

Make sure your Gitlab settings correctly use https and not http or builds won't trigger on push.

You can manually trigger a build from Gitlabs->Project->Services->CI->Test Settings

If your runner is getting 4xx/500 response errors submitting build XXX to coordinator you may need to bump up your nginx config defaults to allow for big debug output logs e.g.

client_max_body_size 64M;
client_body_buffer_size 1M;
charset utf-8;

If you still have problems with large build traces, you might need to reconfigure the gitlabci-db:

#edit line in my.cnf
max_allowed_packet  = 64M

Finally adjust the trace field to allow for more text!

$ mysql -u USER -pPASS -h gitlabcidb.dev.docker
mysql> USE gitlabci;
mysql> DESCRIBE builds; # the trace field should be a longtext not just a text
mysql> ALTER TABLE builds MODIFY trace LONGTEXT;

A summary of gitlab ci / runner integration errors I ran into can be found here: gitlabhq/gitlab/ci#363.

Tag summary

Content type

Image

Digest

sha256:029ab01ca

Size

295 MB

Last updated

almost 11 years ago

docker pull ubergarm/gitlab-ci-runner