This article mainly introduces the Windows environment using docker client to locally deploy GitLab + Runner automatic compilation
1. Docker software download
Windows platform: Click download
MAC: Click to download
2. Download the image
Docker Hub is located at hub.docker.com/
3. Install the image
Take GITLab as an example:
https://hub.docker.com/r/gitlab/gitlab-ce
Use the shell window to download the image
docker pull gitlab/gitlab-ce
Copy the code
4. Container creation and running
docker run -d -p 3003:80 --name=gitlab-ce --restart=always gitlab/gitlab-ce
Copy the code
Ports in the container include HTTP port (80), HTTPS port (443), and SSH port (22)
Currently, only HTTP ports are mapped to host port 3003, which can be accessed by browsers
5. Change the clone IP address
1). Modify the HTTP clone address is relatively simple, directly through the administrator identity in the Admin Area (click the wrench symbol at the top of the background to enter) can be operated.
Settings ->
Genenal ->
Visibility and access controls ->
Custom Git clone URL for HTTP(S)
Copy the code
2). Enter the container and modify the configuration
docker exec -it gitlab-ce /bin/bash
vim /var/opt/gitlab/gitlab-rails/etc/gitlab.yml
Copy the code
Once in the file, modify gitlab’s host and port, and then execute the restart command
gitlab-ctl restart
Copy the code
Restart the execution command and manually operate on the Docker client
At this point, your GitLab is deployed locally!
Bug: Need to modify this file after reboot (no solution found yet)
6. Runner automatically compiles and installs
Pull runner image and start
docker run -d --name gitlab-runner --restart always -v /srv/gitlab-runner/config:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest
Copy the code
Enter runner container
docker exec -it gitlab-runner bash
Copy the code
Registered runner
gitlab-runner register
Copy the code
Then enter the gitLab instance address, token, description, tag, executor (Docker) and Docker version (alpine:latest)
After passing the above command, we can see the newly created Runner in Gitlab (divided into shared and single project).
Modify runner configuration files to improve automatic compilation efficiency
After installing the volumes configuration, you can add Maven to the docker and Maven cache
volumes = ["/cache","/var/run/docker.sock:/var/run/docker.sock","/data/.m2/:/.m2/"]
Copy the code
Add a line under the volumes configuration to prevent runners from pulling mirrors repeatedly
pull_policy = "if-not-present"
Copy the code
And then reboot runner
docker restart gitlab-runner
Copy the code
At this point, runner is configured
7. Practical application of the project
# dependency mirror
image: Node: 10.16.0
before_script:
- echo "before script"
- npm config set registry http://r.cnpmjs.org/
after_script:
- echo "after script"
# Define stages
stages:
- build
# define build
job-build:
You need to install dependencies before you start
stage: build
script:
- npm install
- npm run build
- echo "finish build stage"
only:
- master
tags:
- mirror
artifacts:
paths:
- dist/
Copy the code
The gitlab-ci.yml script is automatically compiled and packaged whenever the master branch changes
After running autocompile, you can download the package file!
8. Common File operation commands in Linux
I enter the insert mode and press Esc to exit the edit mode. Enter the command mode and exit directly. Exit wq Save the changes and exitCopy the code