Series column statement : Comparative flow , Mainly write some points of stepping on the pit , And where there is a big gap with the document in practice . The typical feature of this column may be Second best practice
, Strive to survive in a large number of best practices .
One 、 utilize Cloud effect Flow
Pull the code
About how to open Cloud effect
as well as CodeUp
and Flow
see Official documents Well .
Flow
The benchmark is Jenkins / Pipeline / CICD
, Look at the document The old version has configuration files So you can IaC Of , This feature is not found in the new version . New version of the ClickOps Will be enough , And my scenario is almost one-time configuration , Not often , So that's enough .
The first pit is , The source code supports GitHub Of , But it doesn't really support . First, pull the code outside the wall , Compare the image warehouse ACR
The built-in function allows you to select an overseas server to build ,Flow
There is no such option . Secondly, even if it is connected , The speed will also be very slow , The assembly line is charged according to time rather than times , So the code source , In fact, all sources including the third-party libraries must be on Alibaba cloud . And when building the image FROM
, The official document also suggests uploading the basic image to your own... In advance ACR In a private warehouse , To improve the efficiency of pulling . Cross ecology does not exist ,vender lockin 了 .
Therefore, the second pit is naturally led out , The self built third-party library of cloud effect only has Maven and NPM, So in this ecology, we can only use Java and JavaScript. Although in theory, self built Nexus, But the purpose of my cloud effect is not to build it by myself . About how to develop and configure locally .m2/settings.xml
To use the Maven
, And upload some private packages , Reference resources Documents that can only be viewed by logging in to cloud effect , The regular documents that can be found are old versions , It hasn't been updated yet .Flow
Inside settings.xml It's all configured , It is recommended to use the system without modification .
The third thing to note is working directory
The concept of . Code can come from multiple sources , Theoretically, the code from different upstream can be pulled separately , And mix it up , The subcontracting of wechat applet seems to be the logic ? In terms of experience monorepo It will be more intuitive , But the support for multi-source may fall to the ground It is better to support the chaotic organizational structure within the enterprise , It is easier to help party a transform . You can put the source A The working directory of is specified as /path/to/app-a, Source B The working directory of is specified as /oath/to/app-b, Then use something like cd app-b To operate .
above , Although the cloud effect is ClickOps
But there are no screenshots and code snippets with cloud effect deliberately , One is that there is no IaC
Don't want to post scripts , Update this section when you find it ; Second, the interaction is surprisingly good , Follow the prompts and click everywhere to get started quickly .
Two 、 Use a custom image to build
The assembly line has many steps ,Flow The default recommendation is code scanning 、 structure 、 Deployment and so on , Here we mainly discuss the construction process .
Flow There are many ready build environments , Such as Java structure ,Go Build and so on , among Java Construction is divided into JDK 1.8,OPENJDK 11,Maven 2.x,3.x wait . These seem to bring an easy-to-use unpacking experience , But in practice, it is very uncontrollable . For example, you can only use the supported JDK major Select... In the version , In case of special circumstances, it should be assigned to minor The version is even more impossible .
In practice, what we need is Drone Runner That plan , The user prepares the image by himself , Each step uses the image to hang the working directory to perform the construction , stay Flow This one is called Custom environment build .
What is lacking in beauty at present is Only public warehouses are supported
Mirror image ( It supports self built private warehouses, but I haven't settled the service link mode here ), I don't know why it doesn't support ACR Private warehouse
. So here's the problem , If you use unpacked Java structure
, The platform will settings.xml
It's all configured , Using a custom image obviously does not have this . meanwhile , Because the custom image must be placed on the public network , Therefore, it is impossible to With user name and password settings.xml
Into the mirror .
At present, the scheme I have adopted is to open another CodeUp Warehouse secrets, In plain text settings.xml Put it in the warehouse , And specify it as the code source /root/workspace/secrets
working directory . As mentioned above , The first step is to pull the code source to support multiple sources and multiple working directories , So the script to build this step is like :
cd /root/workspace/app
mvn -s /root/workspace/secrets/settings.xml clean package
Flipped through the documents , Find out secrets/settings.xml
Other download methods should also be supported , For instance from OSS download , perhaps CodeUp Encrypted warehouse, etc , I don't want to go into it . The main ideas provided above are to use different working directory
, Will not be sensitive and sensitive content , Store separately , And then mixed .
3、 ... and 、 Publish to Mirror warehouse ACR
This is an easy step , Use the... Provided by the platform The image is built and pushed to Alibaba cloud image warehouse personal edition
that will do . Because the actual complex construction work is completed in the previous steps , Here, just put /root/workspace/app
Mount it ,Dockerfile You just need to write a few lines COPY fromxx toxx
Just fine .
There will be a wizard to help you build up to ACR
Service links for , In fact, the implementation should be docker run build & push
, Remember in tag Mark the version on the , I'm using release-${BUILD_NUMBER}
, Therefore, the image pushed into the warehouse is like registry.cn-hangzhou.aliyun/lisitede/app:release-8
. This image is ultimately used to start the container .