Background: In the last article, you completed a crude Spring Cloud + K8S application, which would have required five services to be packaged, five images to be installed, and five services to be deployed manually. Let tools do all the hard work.

Then I made a simple visual deployment tool, entered the repository git address, and golang was responsible for clone Repository -> Build Docker images -> helm Install

Code positions:chintensakai/learn-spring-cloud (gitee.com)

1. The train of thought

  • Why golang? Because I will add the display kanban of K8S-related resources and docker resource kanban of each node later, golang has the client SDK officially provided by K8S and Docker, which is convenient for me.
  • The process is divided into three steps:
    1. Input the git repository log, step bar button to display clone, click call /git/clone interface, background GIN receives the request, use the go git library to clone the project, after clone, traverse the project directory to find the project containing package directory, These are the projects that helm will need to install later; Also look for the Dependencies aggregation project, MVN Clean Package to package.
    2. After the end of step 1, the button changes to Build, and click to call /docker/ Build interface. The front end carries the list of projects to be installed returned in Step 1 to the back end, which uses docker SDK to the corresponding directory, builds the image according to Dockerfile, and pushes it to the local Registry. This step is the most time-consuming, after some known methods of optimization, we plan to use Goroutine to rewrite the build and push process, theoretically can save another 4/5 time
    3. At the end of step 2, the button changes to Helm Install, and the interface /helm/install is called after clicking it. The GO SDK of Helm is a little complicated, and the work of this step is very simple, so it is more convenient to directly call the system command.

2. Final Results:

2.1 /git/ Clone Interface:

2.2 /docker/build interface

2.3 /helm/install Interface:

2.4 Installation Complete:

3. Some optimization points:

The previous base image was too big to handle the push and pull process, and the build and push of a single image took 11 minutes

With alpine + springboot layered build + local image repository, 5 images build&push in a minute or two, faster and faster as some image layers can be reused. And the real use would be my own private warehouse, so this step is a known method, not my own invention.