Skip to content

Commit

Permalink
添加docker打包(#62)
Browse files Browse the repository at this point in the history
* add docker file
  • Loading branch information
xzchaoo authored and luyiisme committed Jun 5, 2019
1 parent 3bfaa52 commit f2ed170
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 68 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
@@ -0,0 +1,4 @@
.idea/
.git/
target/
logs/
29 changes: 29 additions & 0 deletions Dockerfile
@@ -0,0 +1,29 @@
FROM maven:3.6.1-jdk-8
LABEL MAINTAINER kevin.luy@antfin.com,xiangfeng.xzc@antfin.com

ENV deploy_path /home/admin/deploy


COPY . $deploy_path/source


RUN mkdir -p /root/.m2 && \
cd $deploy_path/source && \
mv docker/settings-aliyun.xml /root/.m2/settings.xml && \
mv docker/entrypoint.sh $deploy_path/entrypoint.sh && \
chmod a+x $deploy_path/entrypoint.sh && \
mvn clean package -Psofaark -B -e -T 1C -Dsun.jnu.encoding=UTF-8 -Dfile.encoding=UTF-8 -Dmaven.test.skip=true -am -pl boot/all-in-one-bootstrap && \
mv $deploy_path/source/boot/all-in-one-bootstrap/target/allinone-executable.jar $deploy_path/app.jar && \
cd ~ && \
rm -rf /root/.m2 $deploy_path/source && \
useradd admin && \
chown -R admin:admin /home/admin

EXPOSE 6200 7200 9090

VOLUME /home/admin/logs /home/admin/lookout_gateway_queue_cache

USER admin
WORKDIR /home/admin

ENTRYPOINT ["/home/admin/deploy/entrypoint.sh"]
4 changes: 2 additions & 2 deletions boot/all-in-one-bootstrap/README-old.md
Expand Up @@ -17,7 +17,7 @@ java -Dcom.alipay.sofa.ark.master.biz=lookoutall \
-Dlookoutall.config-file=abc.properties \
-Dlookoutgateway.foo=bar \
-Dlookoutserver.bar=baz \
-jar lookout-all-in-one-bootstrap-1.2.0-executable-ark.jar
-jar allinone-executable.jar
```

> 注意 -Dcom.alipay.sofa.ark.master.biz=lookoutall 是必须的, 用于设置sofa-ark的master biz.
Expand Down Expand Up @@ -78,7 +78,7 @@ lookoutserver.server.port=7100
```
java -Dcom.alipay.sofa.ark.master.biz=lookoutall \
-Dlookoutall.config-file=abc.properties \
-jar lookout-all-in-one-bootstrap-1.2.0-executable-ark.jar
-jar allinone-executable.jar
```

`server.port=7300`会作用于`lookoutgateway`子应用, `server.port=7100`会作用于`lookoutserver`子应用.
2 changes: 1 addition & 1 deletion boot/all-in-one-bootstrap/README.md
Expand Up @@ -18,7 +18,7 @@ metrics-server.spring.data.jest.uri=http://localhost:9200
```
java -Dcom.alipay.sofa.ark.master.biz=lookoutall \
-Dlookoutall.config-file=abc.properties \
-jar lookout-all-in-one-bootstrap-1.6.0-executable-ark.jar
-jar allineone-executable.jar
```

> 注意 -Dcom.alipay.sofa.ark.master.biz=lookoutall 是必须的, 用于设置sofa-ark的master biz.
Expand Down
6 changes: 2 additions & 4 deletions boot/all-in-one-bootstrap/build.sh
@@ -1,7 +1,5 @@
#!/usr/bin/env bash

# all in one 打包方式
current_dir=$( dirname $0)
cd $current_dir/../..
mvn clean install -T 1C -Psofaark -Dmaven.test.skip=true -am -pl boot/all-in-one-bootstrap


# 单独打包方式, 需要排除all-in-one模块, 否则会报错
4 changes: 2 additions & 2 deletions boot/all-in-one-bootstrap/pom.xml
Expand Up @@ -70,7 +70,6 @@
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>com.alipay.sofa</groupId>
Expand All @@ -85,8 +84,9 @@
</execution>
</executions>
<configuration>
<finalName>allinone</finalName>
<bizName>lookoutall</bizName>
<arkClassifier>executable-ark</arkClassifier>
<arkClassifier>executable</arkClassifier>
<attach>true</attach>
<!--使用priority来调整优先级-->
<priority>1</priority>
Expand Down
1 change: 0 additions & 1 deletion boot/gateway-bootstrap/pom.xml
Expand Up @@ -49,7 +49,6 @@
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</build>
Expand Down
1 change: 0 additions & 1 deletion boot/metrics-server-bootstrap/pom.xml
Expand Up @@ -45,7 +45,6 @@
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</build>
Expand Down
46 changes: 46 additions & 0 deletions docker/README.md
@@ -0,0 +1,46 @@
# 介绍 #
使用docker的方式来部署all-in-one-bootstrap.

# 构建镜像 #

在项目根目录执行
```bash
docker build -t lookout/allinone:1.0.0 .
```

> 为了在国内获得较好的构建速度, 构建时使用了aliyun的maven仓库.
## docker方式运行 ##
先运行ES
```
docker run -d --name es -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:5.6
```

服务端默认会连接到`localhost:9200`的ES实例, 而我所用的开发机器是MacOS, 无法使用`--net=host`模式启动容器, 因此在容器内无法通过`localhost:9200`连接ES, 需要使用如下方式绕过去:

编辑一个配置文件, 比如foo.properties
```properties
gateway.metrics.exporter.es.host=es
metrics-server.spring.data.jest.uri=http://es:9200
```

在foo.properties所在的目录下运行all-in-one镜像
```bash
docker run -it \
--name allinone \
--link es:es \
-v $PWD/foo.properties:/home/admin/deploy/foo.properties \
-e JAVA_OPTS="-Dlookoutall.config-file=/home/admin/deploy/foo.properties" \
lookout/allinone:1.0.0
```

> 这里利用了docker的--link参数使得应用可以访问到ES实例
> 这里做测试用, 所以不用-d参数在后台运行

如果在linux上启动则quickstart例子无需上述设置, 直接执行如下语句即可:
```bash
docker run -it \
--name allinone \
lookout/allinone:1.0.0
```
13 changes: 13 additions & 0 deletions docker/entrypoint.sh
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# all in one entry point

java_bin=java
app_jar=/home/admin/deploy/app.jar

# 构建 JVM 系统属性
java_opts="-Dcom.alipay.sofa.ark.master.biz=lookoutall"
java_opts="$java_opts $JAVA_OPTS"

echo $java_bin -server $java_opts $app_jar
$java_bin -server $java_opts -jar $app_jar
43 changes: 43 additions & 0 deletions docker/settings-aliyun.xml
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>aliyun</id>
<repositories>
<repository>
<id>aliyun</id>
<url>https://maven.aliyun.com/repository/central</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>aliyun</id>
<url>https://maven.aliyun.com/repository/central</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>

</profiles>

<activeProfiles>
<activeProfile>aliyun</activeProfile>
</activeProfiles>

</settings>
138 changes: 81 additions & 57 deletions pom.xml
@@ -1,62 +1,86 @@
<?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.alipay.sofa.lookout</groupId>
<artifactId>lookout-parent</artifactId>
<version>1.6.0</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<name>kevin.luy</name>
<email>kevin.luy@antfin.com</email>
<organization>Ant Financial</organization>
<organizationUrl>https://www.alipay.com/</organizationUrl>
</developer>
</developers>
<modules>
<module>client</module>
<!--gateway modules-->
<module>gateway</module>
<module>gateway/core</module>
<module>gateway/metrics/pipeline</module>
<module>gateway/metrics/starter</module>
<module>gateway/metrics/importer/standard</module>
<module>gateway/metrics/importer/opentsdb</module>
<module>gateway/metrics/importer/prometheus</module>
<module>gateway/metrics/importer/metricbeat</module>
<module>gateway/metrics/exporter/elasticsearch</module>
<module>gateway/metrics/exporter/standard</module>
<!--server modules-->
<module>server</module>
<module>server/common</module>
<module>server/metrics/promql</module>
<module>server/metrics/storage-ext-es</module>
<module>server/metrics/interfaces</module>
<module>server/metrics/starter</module>
<module>server/metrics/web-ui</module>
<module>server/server-test</module>
<!-- boot modules-->
<module>boot/gateway-bootstrap</module>
<module>boot/metrics-server-bootstrap</module>
<module>boot/sofa-ark-support</module>
</modules>
<modelVersion>4.0.0</modelVersion>
<groupId>com.alipay.sofa.lookout</groupId>
<artifactId>lookout-parent</artifactId>
<version>1.6.0</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<name>kevin.luy</name>
<email>kevin.luy@antfin.com</email>
<organization>Ant Financial</organization>
<organizationUrl>https://www.alipay.com/</organizationUrl>
</developer>
</developers>
<modules>
<module>client</module>
<!--gateway modules-->
<module>gateway</module>
<module>gateway/core</module>
<module>gateway/metrics/pipeline</module>
<module>gateway/metrics/starter</module>
<module>gateway/metrics/importer/standard</module>
<module>gateway/metrics/importer/opentsdb</module>
<module>gateway/metrics/importer/prometheus</module>
<module>gateway/metrics/importer/metricbeat</module>
<module>gateway/metrics/exporter/elasticsearch</module>
<module>gateway/metrics/exporter/standard</module>
<!--server modules-->
<module>server</module>
<module>server/common</module>
<module>server/metrics/promql</module>
<module>server/metrics/storage-ext-es</module>
<module>server/metrics/interfaces</module>
<module>server/metrics/starter</module>
<module>server/metrics/web-ui</module>
<module>server/server-test</module>
<!-- boot modules-->
<module>boot/gateway-bootstrap</module>
<module>boot/metrics-server-bootstrap</module>
<module>boot/sofa-ark-support</module>
</modules>

<profiles>
<profile>
<id>sofaark</id>
<modules>
<module>boot/all-in-one-bootstrap</module>
</modules>
</profile>
</profiles>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

<profiles>
<profile>
<id>sofaark</id>
<modules>
<module>boot/all-in-one-bootstrap</module>
</modules>
</profile>
</profiles>
</project>

0 comments on commit f2ed170

Please sign in to comment.