Jenkins using a key packaged application deployment SpringBoot, is so 6!

SpringBoot actual electricity supplier item mall (25k + star) Address: github.com/macrozheng/...

Summary

Any behind the simple operation, there is a fairly complex mechanism. This will be SpringBoot packaged applications deployed in Docker environment, for example, explain in detail how to use a key package Jenkins SpringBoot deploy applications.

Jenkins Profile

Jenkins CI & CD open source software leader, providing over 1000 plug-in to support the construction, deployment, automation, meet the needs of any project. We can use Jenkins to build and deploy our project, for example, get the code from our code repository, and then pack our code into an executable file to run after our project through ssh tool execute scripts remotely.

Jenkins installation and configuration

Installation of Docker environment

  • Download Jenkins of Docker image:
docker pull jenkins/jenkins:lts
复制代码
  • Run Docker containers Jenkins:
docker run -p 8080:8080 -p 50000:5000 --name jenkins \
-u root \
-v /mydata/jenkins_home:/var/jenkins_home \
-d jenkins/jenkins:lts
复制代码

Jenkins configuration

  • After running a successful visit to the address registration Jenkins, the first time you log in to enter the administrator password: http://192.168.6.132:8080/

  • Using the administrator password to log in, you can use the following command to obtain administrative password to start from the container log:
docker logs jenkins
复制代码
  • Obtain Administrator password from the log:

  • Choose to install plug-ins, here we recommend the installation of a direct plug-in:

  • Plug into the installation interface, networking wait for plug-in installed:

  • After installation is complete, create an administrator account:

  • Instantiate configuration, the configuration of Jenkins URL:

  • Click System Administration -> Plugin Manager, make some custom plug-in installed:

  • Ensure that the following plug-in is installed correctly:

    • According plug-role management privileges: Role-based Authorization Strategy
    • Remote use ssh plugin: SSH plugin
  • By System Management -> Global Configuration tool to configure global tools, such as maven configuration:

  • New maven installation configuration:

  • Adding Global ssh configuration> system configuration, so Jenkins can perform using the ssh remote linux script - Systems Management:

The role of rights management

We can use the plug-in management roles Jenkins Jenkins to manage users, for example, we can give all authority to the administrator, operation and maintenance personnel given permissions to perform tasks, others only given permission to view.

  • Enable role-based privilege management> Global security configuration - Systems Management:

  • Go to System -> Manage and Assign Roles interface:

  • Add relationship roles and permissions:

  • Assigning Roles to Users:

Packaged application deployment SpringBoot

Here we use mall-learningthe project mall-tiny-jenkinsmodule code to demonstrate how to make Jenkins at a key packaged application deployment SpringBoot.

The code is uploaded to the Git repository

  • There is little need 注意, dockerHost To address the pom.xml into your own mirror Docker warehouse address:

Execute scripts ready

  • The mall-tiny-jenkins.shscript file uploaded to the /mydata/shdirectory, the script reads as follows:
#!/usr/bin/env bash
app_name='mall-tiny-jenkins'
docker stop ${app_name}
echo '----stop container----'
docker rm ${app_name}
echo '----rm container----'
docker run -p 8088:8088 --name ${app_name} \
--link mysql:db \
-v /etc/localtime:/etc/localtime \
-v /mydata/app/${app_name}/logs:/var/logs \
-d mall-tiny/${app_name}:1.0-SNAPSHOT
echo '----start container----'
复制代码
  • .Sh script to add executable permissions:
chmod +x ./mall-tiny-jenkins.sh  
复制代码
  • windows .sh script uploaded to the use linux, need to change the file format, or because of the existence of a special format can not be performed:
#使用vim编辑器来修改
vi mall-tiny-jenkins.sh
# 查看文件格式,windows上传上来的默认为dos
:set ff 
#修改文件格式为unix
:set ff=unix 
#保存并退出
:wq
复制代码
  • .Sh script execution, test use, you can not perform:
./mall-tiny-jenkins.sh
复制代码

Jenkins created to perform tasks in the

  • First we need to create a new task:

  • Select the software project to build a free-style name after setup tasks:

  • At this point you need to add a credential, which is our git repository account password:

  • Filling is completed select the credentials, you can normally connect git repositories;

  • Then we need to add a build, choose to call the top maven goal, which is mainly used in the construction of our source code packaged into Docker image and upload it to our warehouse to Docker image:

  • Choose our maven version, and then set the command and specify maven pom file location:

  • After adding a building to perform remote shell script for .sh script execution start Docker containers after our mirrors complete package:

  • We need to set execute shell commands as follows: /mydata/sh/mall-tiny-jenkins.sh

  • After clicking the save operation, our task is now created in the task list we can click Run to perform the task;

  • We can view the entire execution of tasks through the console output:

Project Source Address

github.com/macrozheng/…

the public

mall project a full tutorial serialized in public concern number the first time to obtain.

No public picture

Guess you like

Origin juejin.im/post/5df780d3e51d4557ff140b30