In this article, I decided to describe my experience with configuring gitlab CI and rented VPS.Background
At work, uv. DevOps'y configured to me a deploy of projects in kubernetes ( I work as the Go-developer ). I have my own pet project - and I wanted to automate, but there was no particular desire to raise my gitlab (VPS is not rubber anyway).Initial data
Create Repository
We create the repository that we want to automate.I decided for tests to raise docker with nginx and forwarding to the html page.Repository structure:DockerfileFROM nginx:latest
COPY html /var/www/html
COPY nginx.conf /etc/nginx/nginx.conf
nginx.confevents {}
http {
server {
listen 80;
location / {
root /var/www/html;
}
}
}
- html
index.html<html>
<h1>Hello, Runner!</h1>
</html>
.gitlab-ci.yml
image: docker:19.03.8
before_script:
- docker info
build:
stage: build
script:
- docker build -t hellorunner .
deploy:
stage: deploy
script:
- docker ps --filter name=hellorunner --quiet | xargs --no-run-if-empty docker stop | xargs --no-run-if-empty docker rm
- docker run -d --restart=always --name hellorunner -p 8090:80 hellorunner
after_script:
- docker system prune -f
Repository setup
Open settings -> CI
Then, click Runners, expand.
First, turn off the proposed runners - Disable shared runners
Then, we are interested in - “Set up a specific Runner manually”
We copy the token, in the future we will need it.VPS Preparation
Install docker .Install gitlab-runner .Register a new runner.! In the executor field, specify the docker version, as in the Dockerfile!
In the token field, specify the token that was remembered from gitlab
gitlab-runner register
Now, you need to make small changes to the runner’s config.nano /etc/gitlab-runner/config.toml
fieldvolumes = ["/cache"]
change tovolumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
Restarting the daemongitlab-runner restart
Back to gitlab / settings / CI / Runners again.An active runner should appear.
Edit the runner, by pressing.
Allow to perform tasks without tags.
Now execute push commits and follow the jobs.
And finally, open the browser.
Link to thePS repository : I met a problem - I had an inside image that didn’t have access to the external network, the solution is create the file /etc/docker/daemon.json :{
"dns": ["8.8.4.4", "8.8.8.8"]
}
service docker restart