- catalog
- preface
-
1、 Configuration warehouse
- (1) Configure private service warehouse
-
2、 Create project
- (1) New code group
- (2) New code base
- (3) Pull code
- (4) Create Maven project
-
3、 Image file
- (1) Basic image
- (2) Write dockerfile
-
4、 Build deployment
- (1) Host management
- (2) Create pipeline
-
5、 Verification test
- (1) Publish demo domain
- (2) Deploy demo service
- (3) Visit demo service
- 6、 Finally
Limited by space, this article includes the first three sections. For the last three sections, please see “using docker to achieve continuous delivery based on cloud effect (Part 2)”
preface
Alibaba cloud has released its latest [cloud effect 2020] product. Cloud efficiency provides end-to-end collaborative services and R & D tools from “requirements → development → testing → release → operation and maintenance → operation”, supports multiple deployment forms of public cloud, proprietary cloud and hybrid cloud, and helps developers improve R & D efficiency through the application of artificial intelligence and automation technology, so as to continuously and rapidly deliver effective value.
Cloud effect 2020 products include multiple module functions, such as project collaboration, knowledge base, assembly line, code management, test environment, warehouse management and so on. This paper mainly introduces the use of docker for Java project construction and deployment, involving warehouse management, code management, pipeline and other functions.
Before reading the text, you need to be proficient in using Maven to build Java projects, and understand some basic concepts and commands related to docker.
Tips: there are many pictures in this article. It is recommended to read them in WiFi environment. Local tyrants are free to read them~
1、 Configuration warehouse
(1) Configure private service warehouse
1. When using Maven to build Java projects, Maven private service warehouse is usually used for mutual dependence and reference of internal two-party libraries. Here, we directly use the Maven private service warehouse provided by cloud effect.
2. Visit alicloud’s official website and select [free use of public cloud].
3. For the first visit, you need to fill in the name of the enterprise and open the service. After the service is successfully opened, the interface is as follows
4. Click the menu button in the upper left corner to find and click to enter the product warehouse
5. Click the snapshot warehouse address, you can see that the warehouse is empty at present, because the jar package has not been released to the warehouse.
6. Find the [guide] button in the upper left corner and click to switch the tab to see the Maven configuration guide.
7. Here, we directly use mode 1, direct download settings.xml File, and rename it to settings-zccoder-2020.xml, and put it in the conf directory of Maven.
8. In general, you need to configure the local warehouse address.
9. So far, Maven private service warehouse configuration is completed.
2、 Create project
Here we create two projectsdemo-domain
anddemo-service
It is used to simulate the scenario that the two-party libraries of internal projects depend on each other.
demo-domain
It is used to store some POJO domain model objects and release jar package separately for other projects.
demo-service
Depend ondemo-domain
, which is a project to realize business functions. Next, we will use docker for deployment.
(1) New code group
1. Click the menu button in the upper left corner to find and click to enter code management
2. To facilitate management, create a new demo code group
(2) New code base
1. After the demo code group is successfully created, create a new code groupdemo-domain
Code base
2. In the same way, create a newdemo-service
Code base. After creation, it is as follows
(3) Pull code
1. Click to enterdemo-domain
Project, you need to configure SSH key for the first time
2. After SSH key configuration, usegit clone
Command to download the empty code base to the local
(4) Create Maven project
1. Before creating Maven project, you need to set Maven configuration file of IDE
2. Createdemo-domain
The POM file is as follows
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zccoder</groupId>
<artifactId>demo-domain</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>rdc-releases</id>
<url>https://packages.aliyun.com/maven/repository/2001067-release-pF311P/</url>
</repository>
<snapshotRepository>
<id>rdc-snapshots</id>
<url>https://packages.aliyun.com/maven/repository/2001067-snapshot-MP1zHb/</url>
</snapshotRepository>
</distributionManagement>
</project>
3. PreparationUser
class
package com.zccoder.demo.domain;
import java.io.Serializable;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
*User entity
*
* @author zc
* @date 2020/04/30
*/
@Data
@NoArgsConstructor
public class User implements Serializable {
/**
*User number
*/
private Integer uid;
/**
*User name
*/
private String userName;
}
4. Implementationmvn -X -Dmaven.test.skip=true clean deploy
takedemo-domain
Publish to private service warehouse
5. Through the log, you can see that the package has been successfully published to the private service warehouse, and then confirmed by the private service warehouse
6. Createdemo-service
The POM file is as follows
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/>
</parent>
<groupId>com.zccoder</groupId>
<artifactId>demo-service</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
</dependency>
<dependency>
<groupId>com.zccoder</groupId>
<artifactId>demo-domain</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>demo-service</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
7. PreparationHelloApplication
class
package com.zccoder.demo.service;
import com.zccoder.demo.domain.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull;
/**
*Startup class
*
* @author zc
* @date 2020/04/30
*/
@RestController
@RequestMapping("/hello")
@SpringBootApplication
public class HelloApplication {
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class, args);
}
@GetMapping
public String say(@NotNull User user) {
return "Hello " + user.toString();
}
}
8. Configuration application.properties
server.port=8081
9. Start upHelloApplication
, and visithttp://127.0.0.1:8081/hello?uid=1&userName=Demo
, display success
10. Copy the previous settings-zccoder-2020.xml file todemo-domain
anddemo-service
Project root, rename to settings.xml
11. Finally, we willdemo-domain
anddemo-service
Submit code to remote code base
3、 Image file
(1) Basic image
1. Write the basic image dockerfile, and provide JDK environment, time zone and other basic environments
FROM centos:7
#Install WGet tools
RUN yum -y install wget
#Download and install JDK to set environment variables
COPY jdk-8u201-linux-x64.rpm jdk-8u201-linux-x64.rpm
RUN rpm -ivh jdk-8u201-linux-x64.rpm
ENV JAVA_HOME /usr/java/latest/
ENV PATH=$JAVA_HOME/bin:$PATH
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
RUN rm -rf jdk-8u201-linux-x64.rpm
#Time zone Chinese and other processing
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo 'Asia/Shanghai' >/etc/timezone
RUN yum -y install kde-l10n-Chinese
#Configure display Chinese
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LC_ALL zh_CN.utf8
RUN echo "export LC_ALL=zh_CN.utf8" >> /etc/profile
2. In the directory where the dockerfile file is located, execute the command
docker build -t registry.cn-shenzhen.aliyuncs.com/zccoder/zccoder-jdk1.8:v1 .
3. Build the basic image and use the following command to push it to alicloud container image service
docker push registry.cn-shenzhen.aliyuncs.com/zccoder/zccoder-jdk1.8:v1
4. Confirm with alicloud container image service, and you can see the basic image
(2) Write dockerfile
1. After the basic image is constructed, the service layer image is written.
2. Create a dockerfile file in the root directory of the project. The contents are as follows
#Rely on underlying image
FROM registry.cn-shenzhen.aliyuncs.com/zccoder/zccoder-jdk1.8:v1
COPY demo-service.jar /demo-service.jar
CMD ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/demo-service.jar"]