Skip to content

Commit 441e20b

Browse files
author
冯靖
committed
add Docker Support
1 parent d010aa5 commit 441e20b

File tree

23 files changed

+1337
-0
lines changed

23 files changed

+1337
-0
lines changed

apollo-adminservice/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@
7676
<executable>true</executable>
7777
</configuration>
7878
</plugin>
79+
<plugin>
80+
<groupId>com.spotify</groupId>
81+
<artifactId>docker-maven-plugin</artifactId>
82+
<version>0.4.13</version>
83+
<configuration>
84+
<imageName>${project.artifactId}</imageName>
85+
<dockerDirectory>src/main/docker</dockerDirectory>
86+
<resources>
87+
<resource>
88+
<targetPath>/</targetPath>
89+
<directory>${project.build.directory}</directory>
90+
<include>*.zip</include>
91+
</resource>
92+
</resources>
93+
</configuration>
94+
</plugin>
7995
<plugin>
8096
<artifactId>maven-assembly-plugin</artifactId>
8197
<executions>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Dockerfile for apollo-adminservice
2+
# Build with:
3+
# docker build -t apollo-adminservice .
4+
# Run with:
5+
# docker run -p 8090:8090 -d --name apollo-adminservice apollo-adminservice
6+
7+
FROM openjdk:8-jre-alpine
8+
MAINTAINER ameizi <sxyx2008@163.com>
9+
10+
ENV VERSION 0.8.0
11+
12+
RUN echo "http://mirrors.aliyun.com/alpine/v3.6/main" > /etc/apk/repositories \
13+
&& echo "http://mirrors.aliyun.com/alpine/v3.6/community" >> /etc/apk/repositories \
14+
&& apk update upgrade \
15+
&& apk add --no-cache unzip curl bash tzdata \
16+
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
17+
&& echo "Asia/Shanghai" > /etc/timezone
18+
19+
ADD apollo-adminservice-${VERSION}-github.zip /apollo-adminservice/apollo-adminservice-${VERSION}-github.zip
20+
21+
RUN unzip /apollo-adminservice/apollo-adminservice-${VERSION}-github.zip -d /apollo-adminservice \
22+
&& rm -rf /apollo-adminservice/apollo-adminservice-${VERSION}-github.zip \
23+
&& sed -i '$d' /apollo-adminservice/scripts/startup.sh \
24+
&& echo "tail -f /dev/null" >> /apollo-adminservice/scripts/startup.sh
25+
26+
EXPOSE 8090
27+
28+
CMD ["/apollo-adminservice/scripts/startup.sh"]

apollo-configservice/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@
8282
<executable>true</executable>
8383
</configuration>
8484
</plugin>
85+
<plugin>
86+
<groupId>com.spotify</groupId>
87+
<artifactId>docker-maven-plugin</artifactId>
88+
<version>0.4.13</version>
89+
<configuration>
90+
<imageName>${project.artifactId}</imageName>
91+
<dockerDirectory>src/main/docker</dockerDirectory>
92+
<resources>
93+
<resource>
94+
<targetPath>/</targetPath>
95+
<directory>${project.build.directory}</directory>
96+
<include>*.zip</include>
97+
</resource>
98+
</resources>
99+
</configuration>
100+
</plugin>
85101
<plugin>
86102
<artifactId>maven-assembly-plugin</artifactId>
87103
<executions>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Dockerfile for apollo-configservice
2+
# Build with:
3+
# docker build -t apollo-configservice .
4+
# Run with:
5+
# docker run -p 8080:8080 -d --name apollo-configservice apollo-configservice
6+
7+
FROM openjdk:8-jre-alpine
8+
MAINTAINER ameizi <sxyx2008@163.com>
9+
10+
ENV VERSION 0.8.0
11+
12+
RUN echo "http://mirrors.aliyun.com/alpine/v3.6/main" > /etc/apk/repositories \
13+
&& echo "http://mirrors.aliyun.com/alpine/v3.6/community" >> /etc/apk/repositories \
14+
&& apk update upgrade \
15+
&& apk add --no-cache unzip curl bash tzdata \
16+
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
17+
&& echo "Asia/Shanghai" > /etc/timezone
18+
19+
ADD apollo-configservice-${VERSION}-github.zip /apollo-configservice/apollo-configservice-${VERSION}-github.zip
20+
21+
RUN unzip /apollo-configservice/apollo-configservice-${VERSION}-github.zip -d /apollo-configservice \
22+
&& rm -rf /apollo-configservice/apollo-configservice-${VERSION}-github.zip \
23+
&& sed -i '$d' /apollo-configservice/scripts/startup.sh \
24+
&& echo "tail -f /dev/null" >> /apollo-configservice/scripts/startup.sh
25+
26+
EXPOSE 8080
27+
28+
CMD ["/apollo-configservice/scripts/startup.sh"]

apollo-portal/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@
3333
<executable>true</executable>
3434
</configuration>
3535
</plugin>
36+
<plugin>
37+
<groupId>com.spotify</groupId>
38+
<artifactId>docker-maven-plugin</artifactId>
39+
<version>0.4.13</version>
40+
<configuration>
41+
<imageName>${project.artifactId}</imageName>
42+
<dockerDirectory>src/main/docker</dockerDirectory>
43+
<resources>
44+
<resource>
45+
<targetPath>/</targetPath>
46+
<directory>${project.build.directory}</directory>
47+
<include>*.zip</include>
48+
</resource>
49+
</resources>
50+
</configuration>
51+
</plugin>
3652
<plugin>
3753
<artifactId>maven-assembly-plugin</artifactId>
3854
<executions>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Dockerfile for apollo-portal
2+
# Build with:
3+
# docker build -t apollo-portal .
4+
# Run with:
5+
# docker run -p 9090:8080 -d --name apollo-portal apollo-portal
6+
7+
FROM openjdk:8-jre-alpine
8+
MAINTAINER ameizi <sxyx2008@163.com>
9+
10+
ENV VERSION 0.8.0
11+
12+
RUN echo "http://mirrors.aliyun.com/alpine/v3.6/main" > /etc/apk/repositories \
13+
&& echo "http://mirrors.aliyun.com/alpine/v3.6/community" >> /etc/apk/repositories \
14+
&& apk update upgrade \
15+
&& apk add --no-cache unzip curl bash tzdata \
16+
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
17+
&& echo "Asia/Shanghai" > /etc/timezone
18+
19+
ADD apollo-portal-${VERSION}-github.zip /apollo-portal/apollo-portal-${VERSION}-github.zip
20+
21+
RUN unzip /apollo-portal/apollo-portal-${VERSION}-github.zip -d /apollo-portal \
22+
&& rm -rf /apollo-portal/apollo-portal-${VERSION}-github.zip \
23+
&& sed -i '$d' /apollo-portal/scripts/startup.sh \
24+
&& echo "tail -f /dev/null" >> /apollo-portal/scripts/startup.sh
25+
26+
EXPOSE 8080
27+
28+
CMD ["/apollo-portal/scripts/startup.sh"]

apollo-spring-boot-sample/.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
target/
2+
.mvn
3+
mvnw
4+
mvnw.cmd
5+
6+
### STS ###
7+
.apt_generated
8+
.classpath
9+
.factorypath
10+
.project
11+
.settings
12+
.springBeans
13+
14+
### IntelliJ IDEA ###
15+
.idea
16+
*.iws
17+
*.iml
18+
*.ipr
19+
20+
### NetBeans ###
21+
nbproject/private/
22+
build/
23+
nbbuild/
24+
dist/
25+
nbdist/
26+
.nb-gradle/

apollo-spring-boot-sample/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# apollo-spring-boot-sample
2+
Demo project for Spring Boot Apollo
3+
4+
Spring Boot整合携程Apollo配置中心
5+
6+
## 客户端maven配置
7+
8+
* apollo-client(必须)
9+
10+
```xml
11+
<dependency>
12+
<groupId>com.ctrip.framework.apollo</groupId>
13+
<artifactId>apollo-client</artifactId>
14+
<version>0.8.0</version>
15+
</dependency>
16+
```
17+
* spring-boot-starter-actuator 和 spring-cloud-context
18+
19+
```xml
20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter-actuator</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.springframework.cloud</groupId>
26+
<artifactId>spring-cloud-context</artifactId>
27+
<version>1.2.2.RELEASE</version>
28+
</dependency>
29+
```
30+
31+
注意:
32+
33+
1、`apollo-client`为必须配置
34+
35+
2、`spring-boot-starter-actuator``spring-cloud-context`为可选配置。仅在使用`Spring Cloud``@RefreshScope`时所需
36+
37+
# 参考文档
38+
39+
https://github.com/ctripcorp/apollo/wiki/

apollo-spring-boot-sample/pom.xml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>net.ameizi</groupId>
7+
<artifactId>apollo-spring-boot-sample</artifactId>
8+
<version>1.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>Apollo Spring Boot Sample</name>
12+
<description>Demo project for Spring Boot Apollo</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.4.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-web</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-configuration-processor</artifactId>
35+
<optional>true</optional>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springframework.boot</groupId>
39+
<artifactId>spring-boot-starter-actuator</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.springframework.cloud</groupId>
43+
<artifactId>spring-cloud-context</artifactId>
44+
<version>1.2.2.RELEASE</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>com.ctrip.framework.apollo</groupId>
48+
<artifactId>apollo-client</artifactId>
49+
<version>0.8.0</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.projectlombok</groupId>
53+
<artifactId>lombok</artifactId>
54+
<optional>true</optional>
55+
</dependency>
56+
</dependencies>
57+
58+
<build>
59+
<plugins>
60+
<plugin>
61+
<groupId>org.springframework.boot</groupId>
62+
<artifactId>spring-boot-maven-plugin</artifactId>
63+
</plugin>
64+
<plugin>
65+
<groupId>com.spotify</groupId>
66+
<artifactId>docker-maven-plugin</artifactId>
67+
<version>0.4.13</version>
68+
<configuration>
69+
<imageName>${project.artifactId}</imageName>
70+
<dockerDirectory>src/main/docker</dockerDirectory>
71+
<resources>
72+
<resource>
73+
<targetPath>/</targetPath>
74+
<directory>${project.build.directory}</directory>
75+
<include>${project.build.finalName}.jar</include>
76+
</resource>
77+
</resources>
78+
</configuration>
79+
</plugin>
80+
</plugins>
81+
</build>
82+
83+
84+
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM openjdk:8-jre-alpine
2+
MAINTAINER ameizi <sxyx2008@163.com>
3+
VOLUME /tmp
4+
RUN echo "http://mirrors.aliyun.com/alpine/v3.6/main" > /etc/apk/repositories \
5+
&& echo "http://mirrors.aliyun.com/alpine/v3.6/community" >> /etc/apk/repositories \
6+
&& apk update upgrade \
7+
&& apk add --no-cache tzdata \
8+
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
9+
&& echo "Asia/Shanghai" > /etc/timezone
10+
ADD *.jar app.jar
11+
RUN sh -c 'touch /app.jar' \
12+
&& mkdir -p /opt/settings \
13+
&& echo "env=DEV" > /opt/settings/server.properties
14+
ENV JAVA_OPTS=""
15+
EXPOSE 9090
16+
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package net.ameizi;
2+
3+
import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
/**
8+
* @EnableApolloConfig要和@Configuration一起使用,不然不会生效。
9+
*/
10+
@Configuration
11+
@EnableApolloConfig
12+
public class ApolloConfigSample {
13+
14+
@Bean
15+
public JavaConfigSample javaConfigSample(){
16+
return new JavaConfigSample();
17+
}
18+
19+
@Bean
20+
public ConfigurationPropertiesSample configurationPropertiesSample() {
21+
return new ConfigurationPropertiesSample();
22+
}
23+
24+
}

0 commit comments

Comments
 (0)