In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of the method of building using Docker+jenkins+python3 environment, the content is detailed and easy to understand, the operation is simple and fast, and it has certain reference value. I believe you will gain something after reading this article on the method of building using Docker+jenkins+python3 environment. Let's take a look at it.
Foreword:
After automatic writing, you need to run it regularly on the server every day. Such a problem is that the Jenkins container is installed in docker, and then the replacement code is pulled from git to find that the code is in the directory of the jenkins container, and the runtime prompts that the python environment is not installed and the third-party library is not installed.
There are three solutions:
First: when starting the jenkins container, mount the container directory to the host directory to execute Pass (method cannot be implemented)
The second: create a local node on jenkins, pull the code locally, and then run the local project (it is more convenient to use on this machine, but less limited)
Third: repackage the jenkins image, and the environment in which python3 is installed in the jenkins image executes the project in the container (troublesome steps, but later permanent use)
Both the first and second methods require docker and jenkins images to be installed on the server.
First, install docker II, install jenkisn image 1. Find the mirror docker search jenkins 2. 0 on docker. Download your own image docker pull jenkinsci/blueocean 3. Check to see if you successfully downloaded docker images 4. Start the downloaded image docker run-d-p 10240JAVA_OPTS=-Duser.timezone=Asia/Shanghai 8080-p 10241JAVA_OPTS=-Duser.timezone=Asia/Shanghai 50000-v / jenkins_autotest/jenkins_home:/var/jenkins_home-v / etc/localtime:/etc/localtime-e 8080-- name jenkint_test jenkinsci/blueocean # description: docker run operation-d: background operation container-p: specify the port mapping of the container-p 10240etc/localtime:/etc/localtime 8080 indicates that the 8080 end of the container The port is mapped to port 10240 of the host Map multiple ports using-p 8082 8080-p 8083VR 8081-v: Mount the host directory and the directory in the docker container / Users/songpeilun/jenkins_home local host absolute directory / var/jenkins_home container directory (mount the container directory locally)-v:/etc/localtime:/etc/localtime local time and container time synchronization-e JAVA_OPTS=-Duser.timezone=Asia/Shanghai sets container time to Shanghai time (otherwise the difference between container time and local time is 8 hours)-- name jenkint_test sets the name of the container jenkinsci/blueocean selector Such as the name startup container (the default image will be followed by latest. If you pull the self-created image, you need to add your own version number jenkinsci/blueocean: version number TAG) ⚠️ container directory must be given permission to chmod 777 jenkins_home when mounting the local directory.
Enter docker images to check whether the jenkins image is installed successfully
Docker images
Check to see if the container is running
Docker ps
You can see that there is already a container jenkins running in docker
This means that jenkins is installed and you can start jenkins now.
3. Start jenkins
The browser enters the ip+ port number of the server http://47.99.98.250:10240/. If you cannot access it, please turn off the system firewall.
There are two ways to check the password, the first is to view it in the server's container, and the second is to view it locally on the map (provided that you map the local directory)
All right, jenkins has been installed here.
View password in container: cat / var/jenkins_home/secrets/initialAdminPassword mapping local directory: cat / Users/songpeilun/jenkins_home/secrets/initialAdminPassword#/Users/songpeilun/jenkins_home local mapping directory address 3. Method 2: create a new local node
Talking about the specific logic of method 2, the local node of the new jenkins uses the new node to pull the code on the git to the local (host) to execute the code.
This method is mainly suitable for a set of local environments where there is already a set of python3, and you can directly run automation and use local continuous integration to achieve daily automated reporting (disadvantage: because the local node uses the host address as ip, it is necessary to turn on the computer and jenkins address every time, and there is little limitation that the external network cannot be accessed.)
Step 1: install the SSH Agent plug-in in jenkins
Install the ssh Agent plug-in system Settings-plug-in Management-optional plug-in and enter ssh agent search
Step 2: add new nodes
System Settings-Node Management-New Node (Node name cannot be duplicated)
Description:
Node name: try to use English and characters instead of Chinese characters (there will be a warning when you select a node when creating a project! )
Node description: can be filled in or not
Number of actuators: number of nodes running at the same time
Remote working directory: the local working directory (/ Users/songpeilun/jenkins), which requires users with root permissions to have all permissions on this file
Label: can be filled in or not
Usage: use this node as much as possible
Startup method: Launch agents via SSH
Host: the network ip address of this machine (network-network settings-IP)
Credentials: select the local account password that has been added
Host Key Verification Strategy:Non verifying Veriflication Strategy
Availability: try to keep agents online
Node attribute-the installation path of git:git
Then the startup node indicates that the startup is successful, and then check whether the local host directory folder has the files of the node.
Method 3: install the python3 environment in the container
Speaking of the specific logic of method 3, it is mainly to run the code in the container. Git pulls the code into the container by default and does not need mapping to execute the code directly in the container (pros: it does not take up the resource size of the server and starts at any time; it does not need the local startup service to directly use the server address to do harm: is it more troublesome to install?)
Step 1: you need to enter the jenkins container
Docker exec-itu root container id / bin/sh
There are two ways to install python3
1.weget installation (not recommended, basically similar to the current installation method, first install some dependent packages, such as gcc, etc.)
2.apk add installation (this version is alpine: apk add, which can be installed quickly)
Finally, pay attention to the issue of the system version:
If it's centos, it's yum; if it's ubuntu, it's apt-get; if it's alpine, it's apk.
Step 2: apk to install python3
Cd / etc/apk/echo "https://mirrors.ustc.edu.cn/alpine/v3.6/main/" > repositoriesecho" https://mirrors.ustc.edu.cn/alpine/v3.6/community/" > > repositories
Update the apk feed so that you can download it faster.
Apk update
Step 3: install the python3 environment using apk add
Apk add python3
Step 4: update pip3
Pip3 install-upgrade pip verifies python environment python-VPip3-V
After the above installation is successful, you can install the plug-in of the third-party library, which is half done.
The plug-in installation is based on the needs of your own project. Here is my project.
Step 5: install the python tripartite library
First create the requirements.txt file
Pip freeze > requirements.txt
Pip install-r requirements.txt
Then use vi requirements.txt to open the file for editing
Base64-test0926 = = 1.0.0 PyMySQL==1.0.2 pytest==6.2.3 python-jenkins==1.7.0 PyYAML==5.4.1 redis==3.5.3 requests==2.25.1 SQLAlchemy==1.4.10 urllib3==1.26.4 wheel==0.36.2 allure-pytest==2.8.40 allure-python-commons==2.8.40 the last two need to be installed after the Allure report configuration is complete, otherwise an error will be reported
⚠️ if something goes wrong, don't rush to find out the reason. I've been looking for it for a long time because of the lack of the greenlet plug-in (I'll provide you with methods later).
If there is no problem and the installation is successful, you can cp your own code into the container to test it. When there is no problem, you can pack the image.
Copy the local files to the container xx directory
Docker cp / Users/songpeilun/python_data/allure-2.13.0.zip jenkint_test:/xx directory
I use Allure reports here, so I want to install
Step 6: install the allure report
Allure is an unzipped package. Here is one that you can download and copy to the container to decompress.
Link: https://pan.baidu.com/s/1JbBXOfA0j6saZh7H8RMipw password: qfnv
# add: $PATH:/allure-2.13.0/bin (full path of allure) source / etc/profile after the decompression file unzip allure-2.13.0.zip# configuration environment variable vi / etc/profile in the container
Step 7: verify allure
This is the end of allure-version's article on "how to build a Docker+jenkins+python3 environment". Thank you for reading! I believe you all have a certain understanding of the knowledge of "using Docker+jenkins+python3 environment to build". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.