Skip to content

Commit

Permalink
Add new module shardingsphere-proxy-native-distribution and update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
linghengqian committed Oct 3, 2022
1 parent af6f813 commit a97c00e
Show file tree
Hide file tree
Showing 7 changed files with 277 additions and 229 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push docker image
run: ./mvnw -am -pl shardingsphere-distribution/shardingsphere-proxy-distribution -B -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotless.apply.skip=true -Drat.skip=true -Pnative,docker.buildx.push.native -Dproxy.image.repository=${{ env.PROXY }} -Dproxy.image.tag=${{ github.sha }} clean package
run: ./mvnw -am -pl shardingsphere-distribution/shardingsphere-proxy-native-distribution -B -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotless.apply.skip=true -Drat.skip=true -Pnative,docker.buildx.push.native -Dproxy.image.repository=${{ env.PROXY }} -Dproxy.image.tag=${{ github.sha }} clean package
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ weight = 2
- 在 Git Source 同级目录下执行如下命令, 直接完成 Native Image 的构建。

```bash
./mvnw -am -pl shardingsphere-distribution/shardingsphere-proxy-distribution -B -Pnative -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotless.apply.skip=true -Drat.skip=true clean package
./mvnw -am -pl shardingsphere-distribution/shardingsphere-proxy-native-distribution -B -Pnative -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotless.apply.skip=true -Drat.skip=true clean package
```

- 情形二:需要使用存在 SPI 实现的 JAR 或 GPL V2 等 LICENSE 的第三方依赖的 JAR。

-`shardingsphere-distribution/shardingsphere-proxy-distribution/pom.xml``dependencies` 加入存在 SPI 实现的 JAR
-`shardingsphere-distribution/shardingsphere-proxy-native-distribution/pom.xml``dependencies` 加入存在 SPI 实现的 JAR
或第三方依赖的 JAR。示例如下

```xml
Expand All @@ -73,16 +73,10 @@ weight = 2
</dependencies>
```

- 在 Git Source 同级目录下执行如下命令。

```bash
./mvnw -am -pl shardingsphere-distribution/shardingsphere-proxy-distribution -B -Pnative -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotless.apply.skip=true -Drat.skip=true clean package
```

- 通过命令行构建 GraalVM Native Image。

```bash
./mvnw org.graalvm.buildtools:native-maven-plugin:compile-no-fork -am -pl shardingsphere-distribution/shardingsphere-proxy-distribution -Pnative -DskipTests
./mvnw -am -pl shardingsphere-distribution/shardingsphere-proxy-native-distribution -B -Pnative -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotless.apply.skip=true -Drat.skip=true clean package
```

3. 通过命令行启动 Native Image, 需要带上两个参数,
Expand All @@ -96,7 +90,7 @@ weight = 2
4. 如果需要构建 Docker Image, 在添加后存在 SPI 实现的依赖或第三方依赖后, 在命令行执行如下命令。

```shell
./mvnw -am -pl shardingsphere-distribution/shardingsphere-proxy-distribution -B -Pnative,docker.native -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotless.apply.skip=true -Drat.skip=true clean package
./mvnw -am -pl shardingsphere-distribution/shardingsphere-proxy-native-distribution -B -Pnative,docker.native -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotless.apply.skip=true -Drat.skip=true clean package
```

- 假设存在包含`server.yaml``conf` 文件夹为 `./custom/conf`,可通过如下的 `docker-compose.yml` 文件启动 GraalVM Native
Expand All @@ -114,11 +108,11 @@ services:
- "3307:3307"
```
- 如果您使用默认构建配置, 你当然可以为 `shardingsphere-distribution/shardingsphere-proxy-distribution/Dockerfile-Native`
- 如果您使用默认构建配置, 你当然可以为 `shardingsphere-distribution/shardingsphere-proxy-native-distribution/Dockerfile`
使用 `scratch` 作为 base docker image。
但如果您主动为`pom.xml`的`native profile`添加`jvmArgs`为`-H:+StaticExecutableWithDynamicLibC`,
以静态链接除 `glic` 之外的所有内容,您应该切换 base image 到 `busybox:glic`。
参考 https://www.graalvm.org/22.2/reference-manual/native-image/guides/build-static-executables/ 。
另请注意,某些第三方依赖将需要更多系统库,例如 `libdl`。
因此请确保根据您的使用情况调整 base docker image 和`shardingsphere-distribution/shardingsphere-proxy-distribution`
下的 `pom.xml` 和 `Dockerfile-Native` 的内容。
因此请确保根据您的使用情况调整 base docker image 和`shardingsphere-distribution/shardingsphere-proxy-native-distribution`
下的 `pom.xml` 和 `Dockerfile` 的内容。
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ corresponding `Docker Image` through the `native-image` component of `GraalVM`.
Image.

```bash
./mvnw -am -pl shardingsphere-distribution/shardingsphere-proxy-distribution -B -Pnative -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotless.apply.skip=true -Drat.skip=true clean package
./mvnw -am -pl shardingsphere-distribution/shardingsphere-proxy-native-distribution -B -Pnative -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotless.apply.skip=true -Drat.skip=true clean package
```

- Scenario 2: It is necessary to use a JAR that has an SPI implementation or a third-party dependent JAR of a LICENSE
such as GPL V2.

- Add SPI implementation JARs or third-party dependent JARs to `dependencies`
in `shardingsphere-distribution/shardingsphere-proxy-distribution/pom.xml`. Examples are as follows
in `shardingsphere-distribution/shardingsphere-proxy-native-distribution/pom.xml`. Examples are as follows

```xml

Expand All @@ -78,16 +78,10 @@ corresponding `Docker Image` through the `native-image` component of `GraalVM`.
</dependencies>
```

- Execute the following commands in the same directory as Git Source.

```bash
./mvnw -am -pl shardingsphere-distribution/shardingsphere-proxy-distribution -B -Pnative -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotless.apply.skip=true -Drat.skip=true clean package
```

- Build GraalVM Native Image via command line.

```bash
./mvnw org.graalvm.buildtools:native-maven-plugin:compile-no-fork -am -pl shardingsphere-distribution/shardingsphere-proxy-distribution -Pnative -DskipTests
./mvnw -am -pl shardingsphere-distribution/shardingsphere-proxy-native-distribution -B -Pnative -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotless.apply.skip=true -Drat.skip=true clean package
```

3. Start Native Image through the command line, you need to bring two parameters,
Expand All @@ -103,7 +97,7 @@ corresponding `Docker Image` through the `native-image` component of `GraalVM`.
dependencies, execute the following commands on the command line.

```shell
./mvnw -am -pl shardingsphere-distribution/shardingsphere-proxy-distribution -B -Pnative,docker.native -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotless.apply.skip=true -Drat .skip=true clean package
./mvnw -am -pl shardingsphere-distribution/shardingsphere-proxy-native-distribution -B -Pnative,docker.native -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotless.apply.skip=true -Drat .skip=true clean package
```

- Assuming that there is a `conf` folder containing `server.yaml` as `./custom/conf`, you can start the Docker Image
Expand All @@ -122,10 +116,10 @@ services:
```

- If you use the default build configuration, you can of course use `scratch` as the base docker image
for `shardingsphere-distribution/shardingsphere-proxy-distribution/Dockerfile-Native`.
for `shardingsphere-distribution/shardingsphere-proxy-native-distribution/Dockerfile`.
But if you actively add `jvmArgs` to `-H:+StaticExecutableWithDynamicLibC` for the `native profile` of `pom.xml`,
To statically link everything except `glic`, you should switch the base image to `busybox:glic`. Refer
to https://www.graalvm.org/22.2/reference-manual/native-image/guides/build-static-executables/.
Also note that some third-party dependencies will require more system libraries, such as `libdl`.
So make sure to adjust the base docker image and the content of `pom.xml` and `Dockerfile-Native`
under `shardingsphere-distribution/shardingsphere-proxy-distribution` according to your usage.
So make sure to adjust the base docker image and the content of `pom.xml` and `Dockerfile`
under `shardingsphere-distribution/shardingsphere-proxy-native-distribution` according to your usage.
1 change: 1 addition & 0 deletions shardingsphere-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<module>shardingsphere-src-distribution</module>
<module>shardingsphere-jdbc-distribution</module>
<module>shardingsphere-proxy-distribution</module>
<module>shardingsphere-proxy-native-distribution</module>
</modules>

<properties>
Expand Down
203 changes: 1 addition & 202 deletions shardingsphere-distribution/shardingsphere-proxy-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@
<packaging>pom</packaging>
<name>${project.artifactId}</name>

<properties>
<native.image.name>apache-shardingsphere-proxy</native.image.name>
<exec-maven-plugin.version>3.0.0</exec-maven-plugin.version>
<maven-antrun-plugin.version>3.1.0</maven-antrun-plugin.version>
<native.maven.plugin.version>0.9.14</native.maven.plugin.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
Expand Down Expand Up @@ -139,7 +132,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
<version>3.0.0</version>
<executions>
<execution>
<id>create builder</id>
Expand Down Expand Up @@ -226,199 +219,5 @@
</plugins>
</build>
</profile>
<profile>
<id>native</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>17</source>
<target>17</target>
<compilerArgument>--enable-preview</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>${native.maven.plugin.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<id>build-native</id>
<goals>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
<execution>
<id>test-native</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
<configuration>
<imageName>${native.image.name}</imageName>
<mainClass>org.apache.shardingsphere.proxy.Bootstrap</mainClass>
<fallback>false</fallback>
<verbose>true</verbose>
<buildArgs>
<arg>--report-unsupported-elements-at-runtime</arg>
</buildArgs>
<jvmArgs>
<arg>--enable-preview</arg>
</jvmArgs>
<metadataRepository>
<enabled>true</enabled>
</metadataRepository>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>docker.native</id>
<properties>
<proxy.image.repository>apache/shardingsphere-proxy-native</proxy.image.repository>
<proxy.image.tag>${project.version}</proxy.image.tag>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
<executions>
<execution>
<id>build</id>
<goals>
<goal>exec</goal>
</goals>
<phase>package</phase>
<configuration>
<executable>docker</executable>
<arguments>
<argument>build</argument>
<argument>--pull</argument>
<argument>--build-arg</argument>
<argument>APP_NAME=${native.image.name}</argument>
<argument>-f</argument>
<argument>./Dockerfile-Native</argument>
<argument>.</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>docker.buildx.push.native</id>
<properties>
<proxy.image.platform>linux/amd64,linux/arm64</proxy.image.platform>
<proxy.image.repository>apache/shardingsphere-proxy</proxy.image.repository>
<proxy.image.tag>${project.version}</proxy.image.tag>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
<executions>
<execution>
<id>create builder</id>
<goals>
<goal>exec</goal>
</goals>
<phase>package</phase>
<configuration>
<executable>docker</executable>
<arguments>
<argument>buildx</argument>
<argument>create</argument>
<argument>--use</argument>
<argument>--driver</argument>
<argument>docker-container</argument>
<argument>--name</argument>
<argument>shardingsphere-builder</argument>
<argument>--platform</argument>
<argument>${proxy.image.platform}</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>build</id>
<goals>
<goal>exec</goal>
</goals>
<phase>package</phase>
<configuration>
<executable>docker</executable>
<arguments>
<argument>buildx</argument>
<argument>build</argument>
<argument>-f</argument>
<argument>./Dockerfile-Native</argument>
<argument>--pull</argument>
<argument>--platform</argument>
<argument>${proxy.image.platform}</argument>
<argument>--build-arg</argument>
<argument>APP_NAME=${native.image.name}</argument>
<argument>.</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>push</id>
<goals>
<goal>exec</goal>
</goals>
<phase>package</phase>
<configuration>
<executable>docker</executable>
<arguments>
<argument>buildx</argument>
<argument>build</argument>
<argument>-f</argument>
<argument>./Dockerfile-Native</argument>
<argument>--push</argument>
<argument>--platform</argument>
<argument>${proxy.image.platform}</argument>
<argument>--build-arg</argument>
<argument>APP_NAME=${native.image.name}</argument>
<argument>.</argument>
<argument>-t</argument>
<argument>${proxy.image.repository}:${proxy.image.tag}</argument>
<argument>-t</argument>
<argument>${proxy.image.repository}:latest</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>cleanup builder</id>
<goals>
<goal>exec</goal>
</goals>
<phase>package</phase>
<configuration>
<executable>docker</executable>
<arguments>
<argument>buildx</argument>
<argument>rm</argument>
<argument>shardingsphere-builder</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Loading

0 comments on commit a97c00e

Please sign in to comment.