安装runner
创建工作目录:
/usr/local/docker/runner
创建构建目录
/usr/local/docker/runner/environment
复制jdk到environmet
cp /downloads/jdk-8u152-linux-x64.tar.gz .
在environment下创建Dockerfile文件
FROM gitlab/gitlab-runner:v11.0.2 MAINTAINER Lusifer <topsale@vip.qq.com> # 修改软件源 RUN echo 'deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse' > /etc/apt/sources.list && \ echo 'deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse' >> /etc/apt/sources.list && \ echo 'deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse' >> /etc/apt/sources.list && \ echo 'deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse' >> /etc/apt/sources.list && \ apt-get update -y && \ apt-get clean # 安装 Docker RUN apt-get -y install apt-transport-https ca-certificates curl software-properties-common && \ curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add - && \ add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" && \ apt-get update -y && \ apt-get install -y docker-ce COPY daemon.json /etc/docker/daemon.json # 安装 Docker Compose WORKDIR /usr/local/bin RUN curl -L https://github.com/docker/compose/releases/download/1.25.4/docker-compose-Linux-x86_64 -o /usr/local/bin/docker-compose # RUN wget https://raw.githubusercontent.com/topsale/resources/master/docker/docker-compose RUN chmod +x docker-compose # 安装 Java RUN mkdir -p /usr/local/java WORKDIR /usr/local/java COPY jdk-8u152-linux-x64.tar.gz /usr/local/java RUN tar -zxvf jdk-8u152-linux-x64.tar.gz && \ rm -fr jdk-8u152-linux-x64.tar.gz # 安装 Maven RUN mkdir -p /usr/local/maven WORKDIR /usr/local/maven RUN wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz # RUN wget https://raw.githubusercontent.com/topsale/resources/master/maven/apache-maven-3.5.3-bin.tar.gz # COPY apache-maven-3.5.3-bin.tar.gz /usr/local/maven RUN tar -zxvf apache-maven-3.6.3-bin.tar.gz && \ rm -fr apache-maven-3.6.3-bin.tar.gz # COPY settings.xml /usr/local/maven/apache-maven-3.5.3/conf/settings.xml # 配置环境变量 ENV JAVA_HOME /usr/local/java/jdk1.8.0_152 ENV MAVEN_HOME /usr/local/maven/apache-maven-3.6.3 ENV PATH $PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin WORKD
创建daemon.json文件
{ "registry-mirrors": [ "https://m3dz4myl.mirror.aliyuncs.com" ], "insecure-registries": [ "192.168.91.134:5000" ] }
在/usr/local/docker/runner目录下新建docker-compose.yml文件
version: '3.1' services: gitlab-runner: build: environment restart: always container_name: gitlab-runner privileged: true volumes: - /usr/local/docker/runner/config:/etc/gitlab-runner - /var/run/docker.sock:/var/run/docker.sock
执行docker-compose
docker-compose up -d
注册runner
docker exec -it gitlab-runner gitlab-runner register
进入gitlab网站中的项目
复制地址,粘贴
复制令牌,粘贴