The goal of this paper is to implement ASP NET core-based practices
Operating Environment
- Cent OS 7
- VS Code
- . NET Core
- Cmder
- Run Docker, set up the Docker image Accelerator, or the internal download image will be slow. To learn how to get started with Docker, you can refer to Docker entry and combat
- Create a docker network that allows containers to access each other
sudo Docker network create-d Bridge docker-net
-D parameter indicates the Docker network type
- Docker running Jenkins
sudo Docker Run 8080:808050000:50000 --name Jenkins --network docker-Net -v/var/docker/jenkins:/var/jenkins_home-D --restart always Jenkins
The-p parameter represents a port mapping so that you can access the container through the port number on your local machine
-D container runs in the background
-V Container Data map
Enter http://localhost:8080 in the browser to initialize the administrator password for the first entry. Wait for Jenkins to run and install the recommended plugin.
Install the Jenkins plug-in, Manage Plugins, Available, Manage Jenkins, find Blue Ocean, GitLab Plugin and restart Jenkins after installation
- Docker Run Gitlab
$sudoDocker Run--Detach--publish10443:443--publish8098: the--publish10022: A --name Gitlab--Restart always--network docker-Net--Envgitlab_omnibus_config="gitlab_rails[' gitlab_shell_ssh_port ']=10022;external_url ' http://{ip}:8098 '" --volume/var/docker/gitlab/config:/etc/Gitlab--volume/var/docker/gitlab/logs:/var/log/Gitlab--volume/var/docker/gitlab/data:/var/opt/Gitlab Gitlab/gitlab-ce:latest
External_url needs to be changed to your own IP address.
Run
Ps
Can view to the running container, first boot Gitlab will have a long time, waiting for Gitlab container status is healthy, browser open http://localhost:8098/, reset password, log in with root account
- Docker Run Registry
8097:--restart=always----network docker--v /var/docker/ docker-registry:/var/lib/Registry registry:2
Open the http://localhost:8097/v2/in the browser to see if it runs successfully.
- Create a project on-premises ASPNET core project, create Dockerfile
$ dotnet New WEBAPI-
Open Http://localhost:5000/api/values in browser to see if it runs successfully
Create Dockerfile
From Microsoft/aspnetcore:2.0As Baseworkdir/Appexpose theFrom Microsoft/aspnetcore-build:2.0As Buildworkdir/srccopy. RUN dotnet Restoreworkdir/Srcrun dotnet Build-C Release-o/Appfrom Build as Publishrun dotnet publish-C Release-o/Appfrom Base as Finalworkdir/appcopy--from=publish/app. entrypoint ["dotnet","CIDemo.dll"]
Creating mirrors
127.0. 0.1:8097/cidemo:1 .
Run the image you just created
5001:127.0. 0.1:8097/cidemo:1
Open the http://localhost:5001/api/values in the browser to see if it is working properly
Create Jenkinsfile
Pipeline {Agent any stages {stage ('Build') {steps {SH " "Docker Build-t Registry:8097/Cidemo:${build_number}. Docker Push registry:8097/Cidemo:${build_number}" "}} stage ('Run') {steps {SH " " Echo "Stop runing Container"Docker Stop $ (DockerPS-q) DockerRM$ (DockerPS-q) Docker run-d-p5001: the--network Docker-net Registry:8097/Cidemo:${build_number}" " } } }}
Jenkinsfile Use tutorial https://www.w3cschool.cn/jenkins/jenkins-qc8a28op.html
- Set Gitlab API Token, configure Jenkins Gitlab
In Gitlab Personal Center, Settings, Acess Tokens, create a token that scopes contains the API.
Configure Gitlab in Configure System, Manage Jenkins, Jenkins. Gitlab host URL and API token.
In the Open Blue Ocean of Jenkins, create a pipeline, select the Git repository, and create a project that we just created.
In the Gitlab project, set Webhook, Projects-Settings, integrations, add a webhook, Url adds a Jenkins project address created in the previous step, e.g. http:// Jenkins:8080/project/cidemo, Secret token does not fill, tick the push events, do not tick enable SSL verification.
- Push code into the remote repository to see if the Jenkins task will be triggered, and if successful you can see the execution status of each step of Jenkins.
End, thank you, have a study of net core can add me ZJL_JX
Docker combined with Jenkins, gitlab implementation. Continuous integration practice of Netcore