Deploying cointainers from Gitlab-ci

Hi there,

I am experimenting about a full Continous integration/Continous deployment workflow just using Gitlab (with pipelines and docker registry) and Rancher. Actually Gitlab is really cool platform providing everything very well integrated.

I am in the last phase: using rancher-compose to deploy the container in my Rancher infrastructure. I am using a Gitlab-Runner to execute the CI/CD pipelines and now I need to have the rancher-compose-cli inside the container where is been everything executed. Any suggestion to have the cli inside the runner? Should I use an ubuntu base image, then download an install the debian package?

I have seen there is a docker version of docker-compose. Because inside the runner I have docker, I could use it to lunch the deployment, but I am passing a lot of private information (keys) through a third-person container.

Thanks for suggestions.,

Hi! We are doing a similar thing to test out gitlab ci. I kind of hacked a working system together for this. I created a custom gitlab runner image from gitlab-runner that has docker, docker-compose and rancher-compose installed and they are running and registered with gitlab.

Our current pipeline is defined in 3 stages in .gitlab-ci.yml. The publish stage pushes the built images into the private repo, tagged propertly. The deploy stage is set to manual so if you push the button in Gitlab it runs the deployment phase for that version. The script is just a wrapper around make that issues announcement of start and end and result to slack using curl posting to a webhook. In a previous version, the gozer script also just installed the compose tools that it needed in the runner if they were missing, which can avoid the need for a custom runner image.

image: docker:git

  - build
  - publish
  - deploy

.shared: &template
    - docker
    - BRANCH

  <<: *template
  stage: build

  <<: *template
  stage: publish

  <<: *template
  stage: deploy
    - cd envs && ./ REDACTED
  when: manual
  environment: REDACTED

Maybe some of that will help :wink:

@sra please, could you provide me any point with information about how to create these customs runners? or, do you know if we could use some docker image as base including rancher-compose?

In any case, very useful information with you pipeline, thank you very much.

Are you trying to start new services in Rancher or upgrade existing ones?

If you are upgrading, which is what I do, then I can help you.

Hi - here is most of the Dockerfile that I build our runners with.

FROM gitlab/gitlab-runner:latest

RUN curl -s | sudo bash

RUN apt-get update && \
    apt-get -y install \
            make \
            rsync \
            curl \
            nano \
            sshpass \
            git-lfs \
            awscli \
            zip \
        --no-install-recommends && \
    rm -r /var/lib/apt/lists/* # 150901

RUN git lfs install

# add missing SSL certificate
RUN curl -o /usr/local/share/ca-certificates/como.crt \ \
 && update-ca-certificates

RUN curl -L > /usr/local/bin/docker-1.10.3 && \
    chmod +x /usr/local/bin/docker-1.10.3 && \
    ln -s /usr/local/bin/docker-1.10.3 /usr/local/bin/docker

#RUN curl -L > /tmp/docker-1.11.0.tgz && \
#    cd /tmp && tar -xzf ./docker-1.11.0.tgz && \
#    rm /tmp/docker-1.11.0.tgz && \
#    mv /tmp/docker/docker /usr/local/bin/docker && \
#    chmod +x /usr/local/bin/docker

RUN curl -L`uname -s`-`uname -m` > /usr/local/bin/docker-compose && \
    chmod +x /usr/local/bin/docker-compose

ENV TERM=linux

RUN wget
RUN dpkg -i dumb-init_*.deb
ENTRYPOINT ["/usr/bin/dumb-init", "/entrypoint"]
CMD ["run", "--user=root", "--working-directory=/usr/local/gitlab-runner"]

COPY auth.json /root/.docker/config.json
RUN chmod 700 /root/.docker
RUN chmod 600 /root/.docker/config.json

The auth.json file is what is saved when you docker login to a private repository.
I run it with:

docker run -d  --restart always -v /var/run/docker.sock:/var/run/docker.sock \
            -v /usr/local/gitlab-runner/config:/etc/gitlab-runner \
            -v /usr/local/gitlab-runner/builds:/usr/local/gitlab-runner/builds \
            --name gitlab-runner PRIVATEREPO/gitlab-runner

You have to one-time register it with gitlab like a normal runner

docker exec -it gitlab-runner gitlab-runner register

Not sure if that was what you were asking about, but there it is. I think I got most of that docker file from a docker-in-docker setup somewhere.

1 Like

Yeaah thank you, that is exactly what I need it :slight_smile:

I’ve written a tool to make upgrading Rancher services from gitlab-ci.yml files a lot easier (if you don’t keep your rancher-compose.yml files in the repo)

If you add a RANCHER_URL, RANCHER_ACCESS_KEY and RANCHER_SECRET_KEY secret variables to your project, you just need to add a new stage to your .gitlab-ci.yml file to have it upgrade the service in Rancher:

  stage: deploy
  image: cdrx/rancher-gitlab-deploy
  script: upgrade

No further configuration is necessary if the group and project name in GitLab match the stack and service name in Rancher. If your stack or service name is different, you can pass --stack abc and/or --service xyz to the script: upgrade line.

Docs are on GitHub here


We’ve built a small solution that does not make assumptions about project or service names, but uses a configurable service URL instead:

Maybe useful for some? It’s just a NodeJS package, so quite lightweight.

We also built a solution, check it out at:

here how we do it:

Is there any way i can ask you some questions about the gitlab runner in detail? @sra

I sent a private message

1 Like

After some help from @sra and others i finally came to this solution:

  stage: deploy_qa_environment
  image: badouralix/rancher-cli
    - "rancher env ls"
    - "rancher stacks create mytestbranchname -f rancher/docker-compose.yml -r rancher/rancher-compose.yml"
    - master
  when: manual

Its not perfect, but it is a good way to start from


Love to suggest JSON tool which saved my lot of time to debug JSON data.