diff --git a/Changelog.md b/Changelog.md deleted file mode 100644 index 3fdf98c..0000000 --- a/Changelog.md +++ /dev/null @@ -1,29 +0,0 @@ -# Changelog - -**1.1.4** - - gitlab-ci-multi-runner: upgrade to 1.1.4 - -**1.1.3** - - gitlab-ci-multi-runner: upgrade to 1.1.3 - -**1.1.2** - - gitlab-ci-multi-runner: upgrade to 1.1.2 - -**1.1.1** - - gitlab-ci-multi-runner: upgrade to 1.1.1 - -**1.1.0** - - gitlab-ci-multi-runner: upgrade to 1.1.0 - -**1.0.4** - - gitlab-ci-multi-runner: upgrade to 1.0.4 - -**1.0.0** - - gitlab-ci-multi-runner: upgrade to 1.0.0 - -**0.7.2** - - gitlab-ci-multi-runner: upgrade to 0.7.2 - -**0.5.5-1** - - initial creation, adapted from https://github.com/sameersbn/docker-gitlab-ci-runner - - support `docker` executor. Fixes #5 diff --git a/Dockerfile b/Dockerfile index e69fada..bb4203f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,36 @@ -FROM sameersbn/ubuntu:14.04.20170110 -MAINTAINER sameer@damagehead.com - -ENV GITLAB_CI_MULTI_RUNNER_VERSION=1.1.4 \ - GITLAB_CI_MULTI_RUNNER_USER=gitlab_ci_multi_runner \ - GITLAB_CI_MULTI_RUNNER_HOME_DIR="/home/gitlab_ci_multi_runner" -ENV GITLAB_CI_MULTI_RUNNER_DATA_DIR="${GITLAB_CI_MULTI_RUNNER_HOME_DIR}/data" - -RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E1DD270288B4E6030699E45FA1715D88E1DF1F24 \ - && echo "deb http://ppa.launchpad.net/git-core/ppa/ubuntu trusty main" >> /etc/apt/sources.list \ - && apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y \ - git-core openssh-client curl libapparmor1 \ - && wget -O /usr/local/bin/gitlab-ci-multi-runner \ - https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/v${GITLAB_CI_MULTI_RUNNER_VERSION}/binaries/gitlab-ci-multi-runner-linux-amd64 \ - && chmod 0755 /usr/local/bin/gitlab-ci-multi-runner \ - && adduser --disabled-login --gecos 'GitLab CI Runner' ${GITLAB_CI_MULTI_RUNNER_USER} \ - && sudo -HEu ${GITLAB_CI_MULTI_RUNNER_USER} ln -sf ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh ${GITLAB_CI_MULTI_RUNNER_HOME_DIR}/.ssh \ - && rm -rf /var/lib/apt/lists/* +#FROM alpine:3.8 +FROM docker:18.06 +LABEL author="xiaobo " version="0.0.1" \ + description="This is a base image for gitlab-runner for docker" + +ENV GITLAB_RUNNER_USER=gitlab-runner +ENV GITLAB_RUNNER_HOME_DIR="/home/${GITLAB_RUNNER_USER}" +ENV GITLAB_RUNNER_DATA_DIR="${GITLAB_RUNNER_HOME_DIR}/data" + +RUN apk add --update --no-cache sudo bash shadow ca-certificates git openssl tzdata wget && \ + rm -rf /var/cache/apk/* + +RUN addgroup -S ${GITLAB_RUNNER_USER} && adduser -D -S -G ${GITLAB_RUNNER_USER} -h ${GITLAB_RUNNER_HOME_DIR} ${GITLAB_RUNNER_USER} +RUN sudo -HEu ${GITLAB_RUNNER_USER} ln -sf ${GITLAB_RUNNER_DATA_DIR}/.ssh ${GITLAB_RUNNER_HOME_DIR}/.ssh + +ENV DOCKER_MACHINE_VERSION=0.15.0 +RUN wget -O /usr/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64 && \ + chmod +x /usr/bin/gitlab-runner && \ + ln -s /usr/bin/gitlab-runner /usr/bin/gitlab-ci-multi-runner && \ + gitlab-runner --version && \ + wget -q https://github.com/docker/machine/releases/download/v${DOCKER_MACHINE_VERSION}/docker-machine-Linux-x86_64 -O /usr/bin/docker-machine && \ + chmod +x /usr/bin/docker-machine && \ + docker-machine --version + +ENV DUMB_INIT_VERSION=1.2.2 +RUN wget -q https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_amd64 -O /usr/bin/dumb-init && \ + chmod +x /usr/bin/dumb-init && \ + dumb-init --version COPY entrypoint.sh /sbin/entrypoint.sh -RUN chmod 755 /sbin/entrypoint.sh +RUN chmod +x /sbin/entrypoint.sh + +VOLUME ["${GITLAB_RUNNER_DATA_DIR}"] +WORKDIR "${GITLAB_RUNNER_HOME_DIR}" -VOLUME ["${GITLAB_CI_MULTI_RUNNER_DATA_DIR}"] -WORKDIR "${GITLAB_CI_MULTI_RUNNER_HOME_DIR}" -ENTRYPOINT ["/sbin/entrypoint.sh"] +ENTRYPOINT ["/usr/bin/dumb-init", "/sbin/entrypoint.sh"] diff --git a/LICENSE b/LICENSE deleted file mode 100644 index c8476ac..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2014 Sameer Naik - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/Makefile b/Makefile deleted file mode 100644 index ead943e..0000000 --- a/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -all: build - -build: - @docker build --tag=sameersbn/gitlab-ci-multi-runner . - -release: build - @docker build --tag=sameersbn/gitlab-ci-multi-runner:$(shell cat VERSION) . diff --git a/README.md b/README.md index 10f8fbe..dfac021 100644 --- a/README.md +++ b/README.md @@ -1,167 +1,36 @@ -[![Docker Repository on Quay.io](https://quay.io/repository/sameersbn/gitlab-ci-multi-runner/status "Docker Repository on Quay.io")](https://quay.io/repository/sameersbn/gitlab-ci-multi-runner) - -# sameersbn/gitlab-ci-multi-runner:1.1.4-7 - -- [Introduction](#introduction) - - [Contributing](#contributing) - - [Issues](#issues) - - [Changelog](Changelog.md) -- [Getting started](#getting-started) - - [Installation](#installation) - - [Quickstart](#quickstart) - - [Command-line arguments](#command-line-arguments) - - [Persistence](#persistence) - - [Deploy Keys](#deploy-keys) - - [Trusting SSL Server Certificates](#trusting-ssl-server-certificates) -- [Maintenance](#maintenance) - - [Upgrading](#upgrading) - - [Shell Access](#shell-access) -- [List of runners using this image](#list-of-runners-using-this-image) +# gitlab-runner-docker # Introduction -`Dockerfile` to create a [Docker](https://www.docker.com/) container base image for [gitlab-ci-multi-runner](https://gitlab.com/gitlab-org/gitlab-ci-multi-runner). Use this image to build your CI runner images. +`Dockerfile` to create a [Docker](https://www.docker.com/) container base image for [gitlab-runner](https://gitlab.com/gitlab-org/gitlab-ci-runner). Use this image to build your docker CI runner images. ## Contributing If you find this image useful here's how you can help: - Send a pull request with your awesome features and bug fixes -- Help users resolve their [issues](../../issues?q=is%3Aopen+is%3Aissue). -- Support the development of this image with a [donation](http://www.damagehead.com/donate/) - -## Issues - -Before reporting your issue please try updating Docker to the latest version and check if it resolves the issue. Refer to the Docker [installation guide](https://docs.docker.com/installation) for instructions. - -SELinux users should try disabling SELinux using the command `setenforce 0` to see if it resolves the issue. - -If the above recommendations do not help then [report your issue](../../issues/new) along with the following information: - -- Output of the `docker version` and `docker info` commands -- The `docker run` command or `docker-compose.yml` used to start the image. Mask out the sensitive bits. -- Please state if you are using [Boot2Docker](http://www.boot2docker.io), [VirtualBox](https://www.virtualbox.org), etc. - -# Getting started ## Installation - -Automated builds of the image are available on [Dockerhub](https://hub.docker.com/r/sameersbn/gitlab-ci-multi-runner) and is the recommended method of installation. - -> **Note**: Builds are also available on [Quay.io](https://quay.io/repository/sameersbn/gitlab-ci-multi-runner) +Automated builds of the image are available on [Dockerhub](https://hub.docker.com/r/peterwillcn/gitlab-runner-docker) and is the recommended method of installation. ```bash -docker pull sameersbn/gitlab-ci-multi-runner:1.1.4-7 +docker pull peterwillcn/gitlab-runner-docker ``` - Alternatively you can build the image yourself. ```bash -docker build -t sameersbn/gitlab-ci-multi-runner github.com/sameersbn/docker-gitlab-ci-multi-runner +docker build -t gitlab-runner-docker github.com/peterwillcn/gitlab-runner-docker ``` ## Quickstart Before a runner can process your CI jobs, it needs to be authorized to access the the GitLab CI server. The `CI_SERVER_URL`, `RUNNER_TOKEN`, `RUNNER_DESCRIPTION` and `RUNNER_EXECUTOR` environment variables are used to register the runner on GitLab CI. -```bash -docker run --name gitlab-ci-multi-runner -d --restart=always \ - --volume /srv/docker/gitlab-runner:/home/gitlab_ci_multi_runner/data \ - --env='CI_SERVER_URL=http://git.example.com/ci' --env='RUNNER_TOKEN=xxxxxxxxx' \ - --env='RUNNER_DESCRIPTION=myrunner' --env='RUNNER_EXECUTOR=shell' \ - sameersbn/gitlab-ci-multi-runner:1.1.4-7 -``` - -*Alternatively, you can use the sample [docker-compose.yml](docker-compose.yml) file to start the container using [Docker Compose](https://docs.docker.com/compose/)* - Update the values of `CI_SERVER_URL`, `RUNNER_TOKEN` and `RUNNER_DESCRIPTION` in the above command. If these enviroment variables are not specified, you will be prompted to enter these details interactively on first run. -## Command-line arguments - -You can customize the launch command by specifying arguments to `gitlab-ci-multi-runner` on the `docker run` command. For example the following command prints the help menu of `gitlab-ci-multi-runner` command: - ```bash -docker run --name gitlab-ci-multi-runner -it --rm \ - --volume /srv/docker/gitlab-runner:/home/gitlab_ci_multi_runner/data \ - sameersbn/gitlab-ci-multi-runner:1.1.4-7 --help -``` - -## Persistence - -For the image to preserve its state across container shutdown and startup you should mount a volume at `/home/gitlab_ci_multi_runner/data`. - -> *The [Quickstart](#quickstart) command already mounts a volume for persistence.* - -SELinux users should update the security context of the host mountpoint so that it plays nicely with Docker: - -```bash -mkdir -p /srv/docker/gitlab-runner -chcon -Rt svirt_sandbox_file_t /srv/docker/gitlab-runner -``` +docker-compose up -d -## Deploy Keys - -At first run the image automatically generates SSH deploy keys which are installed at `/home/gitlab_ci_multi_runner/data/.ssh` of the persistent data store. You can replace these keys with your own if you wish to do so. - -You can use these keys to allow the runner to gain access to your private git repositories over the SSH protocol. - -> **NOTE** -> -> - The deploy keys are generated without a passphrase. -> - If your CI jobs clone repositories over SSH, you will need to build the ssh known hosts file which can be done in the build steps using, for example, `ssh-keyscan github.com | sort -u - ~/.ssh/known_hosts -o ~/.ssh/known_hosts`. - -## Trusting SSL Server Certificates - -If your GitLab server is using self-signed SSL certificates then you should make sure the GitLab server's SSL certificate is trusted on the runner for the git clone operations to work. - -The runner is configured to look for trusted SSL certificates at `/home/gitlab_ci_multi_runner/data/certs/ca.crt`. This path can be changed using the `CA_CERTIFICATES_PATH` enviroment variable. - -Create a file named `ca.crt` in a `certs` folder at the root of your persistent data volume. The `ca.crt` file should contain the root certificates of all the servers you want to trust. - -With respect to GitLab, append the contents of the `gitlab.crt` file to `ca.crt`. For more information on the `gitlab.crt` file please refer the [README](https://github.com/sameersbn/docker-gitlab/blob/master/README.md#ssl) of the [docker-gitlab](https://github.com/sameersbn/docker-gitlab) container. - -Similarly you should also trust the SSL certificate of the GitLab CI server by appending the contents of the `gitlab-ci.crt` file to `ca.crt`. - -# Maintenance - -## Upgrading - -To upgrade to newer releases: - - 1. Download the updated Docker image: - - ```bash - docker pull sameersbn/gitlab-ci-multi-runner:1.1.4-7 - ``` - - 2. Stop the currently running image: - - ```bash - docker stop gitlab-ci-multi-runner - ``` - - 3. Remove the stopped container - - ```bash - docker rm -v gitlab-ci-multi-runner - ``` - - 4. Start the updated image - - ```bash - docker run -name gitlab-ci-multi-runner -d \ - [OPTIONS] \ - sameersbn/gitlab-ci-multi-runner:1.1.4-7 - ``` - -## Shell Access - -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 by starting `bash` using `docker exec`: - -```bash -docker exec -it gitlab-ci-multi-runner bash ``` +*Alternatively, you can use the sample [docker-compose.yml](docker-compose.yml) file to start the container using [Docker Compose](https://docs.docker.com/compose/)* -# List of runners using this image - -* [docker-gitlab-ci-multi-runner-ruby](https://github.com/outcoldman/docker-gitlab-ci-multi-runner-ruby) to run ruby builds diff --git a/VERSION b/VERSION deleted file mode 100644 index 8bc74c6..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -1.1.4-7 diff --git a/docker-compose.yml b/docker-compose.yml index fb20df5..849a376 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,18 @@ -GitlabCIMultiRunner: - image: sameersbn/gitlab-ci-multi-runner:1.1.4-7 - volumes: - - /srv/docker/gitlab-runner:/home/gitlab_ci_multi_runner/data - environment: - - CI_SERVER_URL= - - RUNNER_TOKEN= - - RUNNER_DESCRIPTION= - - RUNNER_EXECUTOR=shell - restart: always +version: "3" +# Register and configure ci runner for gitlab +# author="xiaobo " +services: + runner: + image: gitlab-runer-docker:latest + restart: always + environment: + - CI_SERVER_URL= + - RUNNER_TOKEN= + - RUNNER_DESCRIPTION= + - RUNNER_EXECUTOR=docker + - DOCKER_IMAGE=alpine:latest + - TLS_VERIFY=false + - RUN_UNTAGGED=false + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - /opt/docker/gitlab-runner:/home/gitlab-runner/data diff --git a/entrypoint.sh b/entrypoint.sh index 3e2c19c..3b1eb81 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,30 +1,30 @@ #!/bin/bash set -e -CA_CERTIFICATES_PATH=${CA_CERTIFICATES_PATH:-$GITLAB_CI_MULTI_RUNNER_DATA_DIR/certs/ca.crt} +CA_CERTIFICATES_PATH=${CA_CERTIFICATES_PATH:-$GITLAB_RUNNER_DATA_DIR/certs/ca.crt} create_data_dir() { - mkdir -p ${GITLAB_CI_MULTI_RUNNER_DATA_DIR} - chown ${GITLAB_CI_MULTI_RUNNER_USER}:${GITLAB_CI_MULTI_RUNNER_USER} ${GITLAB_CI_MULTI_RUNNER_DATA_DIR} + mkdir -p ${GITLAB_RUNNER_DATA_DIR} + chown ${GITLAB_RUNNER_USER}:${GITLAB_RUNNER_USER} ${GITLAB_RUNNER_DATA_DIR} } generate_ssh_deploy_keys() { - sudo -HEu ${GITLAB_CI_MULTI_RUNNER_USER} mkdir -p ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/ + sudo -HEu ${GITLAB_RUNNER_USER} mkdir -p ${GITLAB_RUNNER_DATA_DIR}/.ssh/ - if [[ ! -e ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/id_rsa || ! -e ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/id_rsa.pub ]]; then + if [[ ! -e ${GITLAB_RUNNER_DATA_DIR}/.ssh/id_rsa || ! -e ${GITLAB_RUNNER_DATA_DIR}/.ssh/id_rsa.pub ]]; then echo "Generating SSH deploy keys..." - rm -rf ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/id_rsa ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/id_rsa.pub - sudo -HEu ${GITLAB_CI_MULTI_RUNNER_USER} ssh-keygen -t rsa -N "" -f ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/id_rsa + rm -rf ${GITLAB_RUNNER_DATA_DIR}/.ssh/id_rsa ${GITLAB_RUNNER_DATA_DIR}/.ssh/id_rsa.pub + sudo -HEu ${GITLAB_RUNNER_USER} ssh-keygen -t rsa -N "" -f ${GITLAB_RUNNER_DATA_DIR}/.ssh/id_rsa echo "" echo -n "Your SSH deploy key is: " - cat ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/id_rsa.pub + cat ${GITLAB_RUNNER_DATA_DIR}/.ssh/id_rsa.pub echo "" fi - chmod 600 ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/id_rsa ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/id_rsa.pub - chmod 700 ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh - chown -R ${GITLAB_CI_MULTI_RUNNER_USER}:${GITLAB_CI_MULTI_RUNNER_USER} ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/.ssh/ + chmod 600 ${GITLAB_RUNNER_DATA_DIR}/.ssh/id_rsa ${GITLAB_RUNNER_DATA_DIR}/.ssh/id_rsa.pub + chmod 700 ${GITLAB_RUNNER_DATA_DIR}/.ssh + chown -R ${GITLAB_RUNNER_USER}:${GITLAB_RUNNER_USER} ${GITLAB_RUNNER_DATA_DIR}/.ssh/ } update_ca_certificates() { @@ -41,23 +41,24 @@ grant_access_to_docker_socket() { DOCKER_SOCKET_GROUP=$(stat -c %G /run/docker.sock) if [[ ${DOCKER_SOCKET_GROUP} == "UNKNOWN" ]]; then DOCKER_SOCKET_GROUP=docker - groupadd -g ${DOCKER_SOCKET_GID} ${DOCKER_SOCKET_GROUP} + addgroup -g ${DOCKER_SOCKET_GID} ${DOCKER_SOCKET_GROUP} fi - usermod -a -G ${DOCKER_SOCKET_GROUP} ${GITLAB_CI_MULTI_RUNNER_USER} + usermod -a -G ${DOCKER_SOCKET_GROUP} ${GITLAB_RUNNER_USER} fi } configure_ci_runner() { - if [[ ! -e ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/config.toml ]]; then + #if [[ ! -e ${GITLAB_RUNNER_DATA_DIR}/config.toml ]]; then if [[ -n ${CI_SERVER_URL} && -n ${RUNNER_TOKEN} && -n ${RUNNER_DESCRIPTION} && -n ${RUNNER_EXECUTOR} ]]; then - sudo -HEu ${GITLAB_CI_MULTI_RUNNER_USER} \ - gitlab-ci-multi-runner register --config ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/config.toml \ - -n -u "${CI_SERVER_URL}" -r "${RUNNER_TOKEN}" --name "${RUNNER_DESCRIPTION}" --executor "${RUNNER_EXECUTOR}" - else - sudo -HEu ${GITLAB_CI_MULTI_RUNNER_USER} \ - gitlab-ci-multi-runner register --config ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/config.toml + sudo -HEu ${GITLAB_RUNNER_USER} \ + gitlab-ci-multi-runner register --config ${GITLAB_RUNNER_DATA_DIR}/config.toml \ + -n -u "${CI_SERVER_URL}" -r "${RUNNER_TOKEN}" --name "${RUNNER_DESCRIPTION}" --executor "${RUNNER_EXECUTOR}" \ + --docker-tlsverify "${TLS_VERIFY}" --run-untagged "${RUN_UNTAGGED}" --docker-image "${DOCKER_IMAGE}" + #else + # sudo -HEu ${GITLAB_RUNNER_USER} \ + # gitlab-ci-multi-runner register --config ${GITLAB_RUNNER_DATA_DIR}/config.toml fi - fi + #fi } # allow arguments to be passed to gitlab-ci-multi-runner @@ -77,11 +78,11 @@ if [[ -z ${1} ]]; then grant_access_to_docker_socket configure_ci_runner - start-stop-daemon --start \ - --chuid ${GITLAB_CI_MULTI_RUNNER_USER}:${GITLAB_CI_MULTI_RUNNER_USER} \ - --exec $(which gitlab-ci-multi-runner) -- run \ - --working-directory ${GITLAB_CI_MULTI_RUNNER_DATA_DIR} \ - --config ${GITLAB_CI_MULTI_RUNNER_DATA_DIR}/config.toml ${EXTRA_ARGS} + sudo -HEu ${GITLAB_RUNNER_USER} \ + $(which gitlab-ci-multi-runner) run \ + --user ${GITLAB_RUNNER_USER} \ + --working-directory ${GITLAB_RUNNER_DATA_DIR} \ + --config ${GITLAB_RUNNER_DATA_DIR}/config.toml ${EXTRA_ARGS} else exec "$@" fi