2

I want to automate my deployment process using gitlab-ci. I'm doing so manually via ssh at the moment. The steps are:

Build:

  • dotnet restore
  • dotnet publish

This leaves me with a directory full of .dlls. I want to deploy these to a docker container, so I run:

  • docker build
  • docker stop
  • docker rm
  • docker run

However, I'm having a hard time finding the proper way to do both in the same .gitlab.ci.yml file.

I need the dotnet tooling from microsoft/dotnet:latest and the docker cli tools from docker:latest.

I tried having two stages based on each of these images, but the output is not shared. To solve this, I tried using artifact, but that fails to upload.

I can't find any examples of this online, so I wonder if I'm doing something that shouldn't be done.

1 Answer 1

1

Not quite sure why you're doing docker run in your build pipeline, nor why artifact doesn't work. We're doing this exact thing in to stages with artifact and dependencies.

It's anyway quite normal to have to customize build images in order to fit your needs. For your build image it seems like you need docker alongside dotnet. Create a Dockerfile which you'll use as your build image, and let it inherit from microsoft/dotnet. Then install docker in that image. Remember to mount in /var/run/docker.sock so that the container can use the docker daemon.

Your new Dockerfile will look like this:

FROM microsoft/dotnet

RUN echo deb http://apt.dockerproject.org/repo debian-jessie main > /etc/apt/sources.list.d/docker.list && \
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D && \
apt-get update && \
apt-get install -y docker-engine

To run the image on your computer you use

docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock yournewimage

You configure GitLab to mount /var/run/docker.sock in the runner configuration file, then you can use the new image in your gitlab-ci.yml.

Sign up to request clarification or add additional context in comments.

3 Comments

I'm actually not using docker run at the moment as I got stuck on the artifact problem. But eventually, I want my CI pipeline to deploy the image on each commit to master. I will definitely try your Dockerfile. Even with artifacts working, I think I might prefer this solution. I'm a bit busy at the moment, but I will get back to you (and accept your answer if it works) in a few days.
Thanks for the Dockerfile. That part worked like a charm. I had to alter my config as described here: gitlab.com/gitlab-org/gitlab-ci-multi-runner/issues/1905 I raised an issue with the artifacts. I mistakenly thought each step could continue where the last one left off as long as it were the same image.
Just getting back to this. I newer directly solved the issue as I found a workaround. I do however suspect that gitlab behind nginx is the problem with artifacts, and that increasing the request limit of nginx may solve this issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.