gitlab集成gitlab_runner
环境准备
- 创建工作目录
/usr/local/docker/runner
- 创建构建目录
/usr/local/docker/runner/environment
- 下载
jdk-8u152-linux-x64.tar.gz
并复制到/usr/local/docker/runner/environment
- 下载
apache-maven-3.5.3-bin.tar.gz
并复制到/usr/local/docker/runner/environmen
daemon.json
在 /usr/local/docker/runner/environment
目录下创建 daemon.json
,用于配置加速器和仓库地址
{ "registry-mirrors": [ "https://registry.docker-cn.com" ], "insecure-registries": [ "192.168.186.132:5000" #镜像私服地址 ] }
Dockerfile
在 /usr/local/docker/runner/environment
目录下创建 Dockerfile
FROM gitlab/gitlab-runner MAINTAINER Lusifer pengtao # 修改软件源 RUN echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse' >> /etc/apt/sources.list && \ echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse' >> /etc/apt/sources.list && \ echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse' >> /etc/apt/sources.list && \ echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse' >> /etc/apt/sources.list && \ echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse' >> /etc/apt/sources.list && \ echo 'deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse' >> /etc/apt/sources.list && \ echo 'deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse' >> /etc/apt/sources.list && \ echo 'deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse' >> /etc/apt/sources.list && \ echo 'deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse' >> /etc/apt/sources.list && \ echo 'deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse' >> /etc/apt/sources.list && \ apt-get update -y && \ apt-get clean # 安装 Docker-ce RUN apt-get -y install apt-transport-https ca-certificates curl software-properties-common && \ apt-get update && apt-get install -y gnupg2 && \ 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 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-8u201-linux-x64.tar.gz /usr/local/java RUN tar -zxvf jdk-8u201-linux-x64.tar.gz && \ rm -fr jdk-8u201-linux-x64.tar.gz # 安装 Maven RUN mkdir -p /usr/local/maven WORKDIR /usr/local/maven 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.5.3-bin.tar.gz && \ rm -fr apache-maven-3.5.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.5.3 ENV PATH $PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin WORKDIR /
在 /usr/local/docker/runner
下创建docker-compose.yml
version: '3.1' services: gitlab-runner: build: environment restart: always container_name: gitlab-runner privileged: true volumes: - ./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 地址 Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/): http://192.168.10.132/ # 输入 GitLab Token Please enter the gitlab-ci token for this runner: 1Lxq_f1NRfCfeNbE5WRh # 输入 Runner 的说明 Please enter the gitlab-ci description for this runner: 可以为空 # 设置 Tag,可以用于指定在构建规定的 tag 时触发 ci Please enter the gitlab-ci tags for this runner (comma separated): deploy # 这里选择 true ,可以用于代码上传后直接执行 Whether to run untagged builds [true/false]: true # 这里选择 false,可以直接回车,默认为 false Whether to lock Runner to current project [true/false]: false # 选择 runner 执行器,这里我们选择的是 shell Please enter the executor: virtualbox, docker+machine, parallels, shell, ssh, docker-ssh+machine, kubernetes, docker, docker-ssh: shell
1.查看gitlab 刷新,当前项目已经有可用的runner即安装完成