This article introduces Docker+Jenkins automatic build deployment and shares it with you. The details are as follows: environment
Run Jenkins Run the Jenkins container Create a directory on the host and add read and write permissions so that the Jenkins application can read and write files when it runs, such as: $ mkdir -p /var/jenkins_node $ chmod 777 /var/jenkins_node Pull the jenkins image: docker run -d --name myjenkins -p 8080:8080 -p 50000:50000 -v <your_jenkins_path>:/var/jenkins_home jenkins Mount the previous directory as a data volume. Replace Set up account and SSH login On the Getting Started interface, you will need the initial password Unlock Jenkins. docker logs myjenkins # Or enter the container docker exec -t myjenkins /bin/bash Once you have the password, enter it and install the suggested plugins. Install Publish Over SSH plugin Home page -> Click System Management -> Manage Plugins -> Optional Plugins -> Filter: ssh -> Select Publish Over SSH plugin and click Direct Installation. Set server SSH information First generate the RSA key in the container: # Enter the container from the host client. The current container name is myjenkins. You can also view it through docker ps $ docker exec -it myjenkins /bin/bash # After entering the container, create the .ssh directory and create the key files private key id_rsa and public key id_rsa.pub ~ mkdir ~/.ssh && cd ~/.ssh ~ ssh-keygen -t rsa # Just keep pressing Enter Add the public key to the host machine and add the string in id_rsa.pub to the end of the authorized_keys file. ssh-copy-id -i ~/.ssh/id_rsa.pub <username>@<host> You need to modify the ssh configuration file of the target server, the configuration file is /etc/ssh/sshd_config. Set ssh-server to allow login using private key and public key pair, and then restart the ssh service using the Add Private Key Advanced options can configure ssh server port and timeout. Test can be tested, showing Project Configuration First, create a new task. Enter the project name. Build environment: Select # Write according to your project needs sudo docker stop <node> || true \ && sudo docker rm <node> || true \ && cd /var/jenkins_node/workspace/<node> \ && sudo docker build --rm --no-cache=true -t <node> - < Dockerfile \ && sudo docker run -d --name <node> -p 3000:3000 -v /var/jenkins_node/workspace/node:/home/project <node> The port is set to 3000. You can also set Dockerfile # Write the FROM node according to your project needs RUN mkdir -p /var/www/html/ RUN npm install -g yarn WORKDIR /var/www/html EXPOSE 3000 CMD ["npm","start"] ps: Return to the home page, select the project, and build it now. After success, you can view the project through Configure webhook Configure webhook to automatically deploy and obtain API tonken: Home -> Users -> Select the current user -> Settings -> Click Add token: Return to home page -> Project -> Configuration -> Build trigger -> Select "Trigger remote build" -> Paste "API Token" content into "Authentication token" Setting up Jenkins security policy Home -> System Management -> Configure Global Security -> At this point, the automated construction and deployment are completed. When you push the code, it will be automatically built and deployed. Deployment Error Finding There are no major issues with code push and webhook, and you won't go wrong if you follow the examples.
This is the end of this article about using Docker+Jenkins to automatically build and deploy. For more information about Docker Jenkins automatic build and deployment, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: MYSQL 5.6 Deployment and monitoring of slave replication
>>: Implementing a simple web clock with JavaScript
Exposing network ports In fact, there are two par...
I like to pay attention to some news on weekdays a...
This article shares with you how to use Vue to ch...
Preface I watched web.dev's 2020 three-day li...
How PHP works First, let's understand the rel...
Linux environment variable configuration When cus...
1. Introduction Today a colleague asked me how to...
MySQL is an open source small relational database...
When doing DB benchmark testing, qps and tps are ...
1. Introduction Presto is an open source distribu...
This article shares the specific code of Vue3.0 h...
Table of contents environment: 1. Docker enables ...
Table of contents plan Install Dependencies Intro...
There are two ways to delete data in MySQL, one i...
1. The Chinese garbled characters appear in MySQL...