1.Dockerfile 如下,以便安装java8和maven3:
FROM gitlab/gitlab-runner
RUN echo "deb http://ppa.launchpad.net/natecarlson/maven3/ubuntu precise main" >>/etc/apt/sources.list
RUN echo "deb-src http://ppa.launchpad.net/natecarlson/maven3/ubuntu precise main">>/etc/apt/sources.list
RUN apt-get -y update && \
apt-get install -y libltdl-dev && \
apt-get install -y software-properties-common
RUN add-apt-repository ppa:webupd8team/java -y
RUN echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
RUN echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
RUN apt-get -y update && \
sudo apt-get -y install oracle-java8-installer && \
sudo apt-get install --force-yes -y maven3 && \
rm -rf /var/lib/apt/lists/*
#optinal(sudo apt-get install oracle-java8-set-default)
RUN ln -s /usr/share/maven3/bin/mvn /usr/bin/mvn
RUN mv /usr/share/maven3/conf/settings.xml /usr/share/maven3/conf/settings.xml.default
ADD settings.xml /usr/share/maven3/conf/settings.xml
2.build image:
docker build -t gitlab-runner:maven .
3.更改宿主机docker.sock用户组:
vi /usr/lib/systemd/system/docker.service
更改以下这行,添加-G root,使其以root用户启动:
ExecStart=/usr/bin/dockerd --registry-mirror=http://3cda3ca9.m.daocloud.io -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 -G root
重启docker service:
service docker restart
4.运行gitlab-runner image:
docker run -d --name gitlab-runner --restart always -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab-runner:maven
5.将新启动的容器中的gitlab-runner用户加入root组以可以调用docker:
docker exec -it gitlab-runner usermod -aG root gitlab-runner
6.注册新的gitlabrunner:
docker exec -it gitlab-runner gitlab-runner register
7.接下来按照http://www.cnblogs.com/flasheryu/p/6183573.html中流程注册即可,executor选择shell!