In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
As a continuously integrated and continuously deployed software, Jenkins is an open source software written by java.
Work as a very popular CI (continuous Integration) for building and testing various projects
The main function of Jenkins is to monitor the execution of repetitive work, such as the construction of software projects or jobs set up under cron
DEV-> GIT-> CI (continuous Integration)-> CD (continuous deployment)
The process of use:
Dev client
1. Set up the git server, and use git add. + git commit-m 'project' upload to local file
2.Git tag v 1.0-tag git push,git push-tag push up
Git end
3. Log in to the github server, create a new project and group, and push the client's git repository to the project using http
Jenkins server
4. On the jenkins server, set up your own project, add git-parameter, and enter gitlab-related url to enable it to communicate with gitlab's project
5. You can see various versions uploaded to gitlab in build with parameter after the main menu. By starting to build, download the project on gitlab to jenkens, build web, and package the files on web for easy distribution.
6. Write script to realize automatic deployment and version update of files in Jenkins
This article focuses on the automatic management of step 5 and 6:
Step 5: deploy the files on Jenkins to the http share with one click
Http automatic distribution of Jenkins: add build steps in the project settings
Newcodes_$ {freetag}: the path is / var/lib/jenkins/workspace/freesttle
# put the version file from newcodes_$ {freetag} to deploy_dir
Shell code
Deploy_dir= / var/www/html/deploy/packages/
Cp-r newcodes_$ {freetag} $deploy_dir
Rm-rf $deploy_dir/newcodes_$ {freetag} / .git # delete the .git file in the original file after the copy is deleted
Cd $deploy_dir
Package the copied version file under the new path
Tar czf newcodes_$ {freetag} .tar.gz newcodes_$ {freetag}
Rm-rf newcodes_$ {freetag} # Delete the copied source file, leaving only the tar package
Md5sum newcodes_$ {freetag} .tar.gz | awk'{print $1}'> newcodes_$ {freetag} .tar.gz.md5
# calculate the tar package check value with md5 and store it in the corresponding file
Create a new mp_live_version version update function
# New version (live_version), previous version (lastest_version)
# [- e exists this path] & & writes live_version content to lastest_version
# write the new input as the new version
[- e / var/www/html/deploy/live_version] & & cat / var/www/html/deploy/live_version > / var/www/html/deploy/last_version
Echo ${mp_live_ver} > / var/www/html/deploy/live_version
Step 6: download the latest version file from jenkins and automatically complete the deployment (web web deployment)
# live_version (latest version) and lastest_version (previous version) version files are available under the server / var/www/html. Provide packages/XXX_1.tar.gz files
Import requests
From urllib import request
Import hashlib
Import os
Import tarfile
Def get_data (url): # responsible for opening remote files in text format
R = requests.get (url) # download local address
Return r.text # returns text format
Def download (url,fname): # download file, previous download script
Html = request.urlopen (url) # download the latest tar package
With open (fname, 'wb') as fobj:
While True:
Data = html.read (1024)
If not data:
Break
Fobj.write (data)
Def check_md5 (fname): # check the md5 value and calculate the md5 value of the fname file
M = hashlib.md5 ()
With open (fname, 'rb') as fobj:# opens the file and reads it step by step
While True:
Data = fobj.read (1024)
If not data:
Break
M.update (data) # updates each md5 value
Return m.hexdigest () # converts md5 values into readable form
Def deploy (app): # deployment, first cut to the directory, extract the tar, and create a shortcut
Os.chdir ('/ var/www/packages') # cd to this path
Tar = tarfile.open (app, 'rblogz') # unpack the files in the app path
Tar.extractall ()
Tar.close ()
Src = app.replace ('.tar.gz','') # replace .tar.gz with''fetch / var/www/html/packages
Dst ='/ var/www/html/mysite' # the path to create the shortcut
If os.path.exists (dst): # whether the created path already exists. If so, delete the path and create it again.
Os.unlink (dst)
Os.symlink (src,dst) # create a shortcut
If _ _ name__ = ='_ _ main__':
Ver = get_data ('http://192.168.122.59/deploy/live_version') # version information is under / var/www/html/
App_name = 'myproject_%s.tar.gz'% ver # File name of the package
App_url = 'http://192.168.122.59/packages/' + app_name # network file path of the package
App_path = os.path.join ('/ var/www/packages',app_name) # complete download path to the local machine
Download (app_url,app_path) # downloaded to this
Locals_md5 = check_md5 (app_path)
Remote_md5 = get_data (app_url+'.md5'). Strip () # download the remote md5 file and remove the / n after the content
If locals_md5 = = remote_md5:
Deploy (app_path) # if there is no problem with md5 verification, extract this version of the file and create a shortcut
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.