This is an automated email from the ASF dual-hosted git repository.

sunnianjun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 68e43592918 Supports building ShardingSphere Agent's Docker Image 
locally (#32945)
68e43592918 is described below

commit 68e435929187a4688145cd1a77439db4b366064f
Author: Ling Hengqian <[email protected]>
AuthorDate: Sat Sep 21 13:16:29 2024 +0800

    Supports building ShardingSphere Agent's Docker Image locally (#32945)
---
 .github/workflows/nightly-build.yml                |  2 +-
 distribution/agent/pom.xml                         | 51 ++++++++++---
 .../shardingsphere-jdbc/observability/_index.cn.md | 83 +++++++++++++++++-----
 .../shardingsphere-jdbc/observability/_index.en.md | 81 ++++++++++++++++-----
 4 files changed, 173 insertions(+), 44 deletions(-)

diff --git a/.github/workflows/nightly-build.yml 
b/.github/workflows/nightly-build.yml
index 32abb2eafdc..bde4aa03bcb 100644
--- a/.github/workflows/nightly-build.yml
+++ b/.github/workflows/nightly-build.yml
@@ -159,7 +159,7 @@ jobs:
           password: ${{ secrets.GITHUB_TOKEN }}
       - name: Push Docker Image
         run: |
-          ./mvnw -am -pl distribution/agent -Prelease,docker.buildx.push -B 
-T1C -DskipTests -Dproxy.image.repository=${{ env.AGENT }} 
-Dproxy.image.tag=${{ github.sha }} clean package
+          ./mvnw -am -pl distribution/agent -Prelease,docker.buildx.push -B 
-T1C -DskipTests -Dagent.image.repository=${{ env.AGENT }} 
-Dagent.image.tag=${{ github.sha }} clean package
   build-cache:
     if: ${{ needs.global-environment.outputs.GLOBAL_IS_NIGHTLY_JOB_EXECUTABLE 
== 'true' }}
     name: Build Project
diff --git a/distribution/agent/pom.xml b/distribution/agent/pom.xml
index 03236f46152..a35b9fc5dec 100644
--- a/distribution/agent/pom.xml
+++ b/distribution/agent/pom.xml
@@ -100,12 +100,45 @@
                 </plugins>
             </build>
         </profile>
+        <profile>
+            <id>docker</id>
+            <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>--build-arg</argument>
+                                        
<argument>APP_NAME=apache-shardingsphere-${project.version}-shardingsphere-agent-bin</argument>
+                                        <argument>.</argument>
+                                        <argument>-t</argument>
+                                        
<argument>apache/shardingsphere-agent:${project.version}</argument>
+                                        <argument>-t</argument>
+                                        
<argument>apache/shardingsphere-agent:latest</argument>
+                                    </arguments>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
         <profile>
             <id>docker.buildx.push</id>
             <properties>
-                
<proxy.image.platform>linux/amd64,linux/arm64</proxy.image.platform>
-                
<proxy.image.repository>apache/shardingsphere-agent</proxy.image.repository>
-                <proxy.image.tag>${project.version}</proxy.image.tag>
+                
<agent.image.repository>apache/shardingsphere-agent</agent.image.repository>
+                <agent.image.tag>${project.version}</agent.image.tag>
             </properties>
             <build>
                 <plugins>
@@ -125,13 +158,12 @@
                                     <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>
+                                        
<argument>linux/amd64,linux/arm64</argument>
                                     </arguments>
                                 </configuration>
                             </execution>
@@ -146,17 +178,18 @@
                                     <arguments>
                                         <argument>buildx</argument>
                                         <argument>build</argument>
-                                        <argument>--pull</argument>
                                         <argument>--push</argument>
+                                        <argument>--builder</argument>
+                                        
<argument>shardingsphere-builder</argument>
                                         <argument>--platform</argument>
-                                        
<argument>${proxy.image.platform}</argument>
+                                        
<argument>linux/amd64,linux/arm64</argument>
                                         <argument>--build-arg</argument>
                                         
<argument>APP_NAME=apache-shardingsphere-${project.version}-shardingsphere-agent-bin</argument>
                                         <argument>.</argument>
                                         <argument>-t</argument>
-                                        
<argument>${proxy.image.repository}:${proxy.image.tag}</argument>
+                                        
<argument>${agent.image.repository}:${agent.image.tag}</argument>
                                         <argument>-t</argument>
-                                        
<argument>${proxy.image.repository}:latest</argument>
+                                        
<argument>${agent.image.repository}:latest</argument>
                                     </arguments>
                                 </configuration>
                             </execution>
diff --git 
a/docs/document/content/user-manual/shardingsphere-jdbc/observability/_index.cn.md
 
b/docs/document/content/user-manual/shardingsphere-jdbc/observability/_index.cn.md
index 96cc268049b..4a122526227 100644
--- 
a/docs/document/content/user-manual/shardingsphere-jdbc/observability/_index.cn.md
+++ 
b/docs/document/content/user-manual/shardingsphere-jdbc/observability/_index.cn.md
@@ -110,25 +110,54 @@ java 
-javaagent:/agent/shardingsphere-agent-${latest.release.version}.jar -jar t
 + 3 访问启动的服务
 + 4 查看对应的插件是否生效
 
-### 夜间构建
+### Docker
 
-ShardingSphere Agent 在 
https://github.com/orgs/apache/packages?repo_name=shardingsphere 存在夜间构建的 Docker 
Image。
-可通过类似如下的 `Dockerfile` 来为类似 `example.jar` 的 JAR 使用此 Docker Image 中的 
ShardingSphere Agent。
-假设 `example.jar` 是一个即将使用 ShardingSphere Agent 的 Spring Boot 的 Uber JAR,
-且 `custom-agent.yaml` 包含 ShardingSphere Agent 的配置。
+####  本地构建
+
+ShardingSphere Agent 存在可用的 `Dockerfile` 用于方便分发。可执行如下命令以构建 Docker Image,
+
+```shell
+git clone [email protected]:apache/shardingsphere.git
+cd ./shardingsphere/
+./mvnw -am -pl distribution/agent -Prelease,docker -T1C -DskipTests clean 
package
+```
+
+此后若在自定义 `Dockerfile` 中添加以下语句,这会将 ShardingSphere Agent 的目录复制到 
`/shardingsphere-agent/` 。
 
 ```dockerfile
-FROM ghcr.io/apache/shardingsphere-agent:latest
-COPY ./example.jar /example.jar
-COPY ./custom-agent.yaml /usr/agent/conf/agent.yaml
-ENTRYPOINT java \
-    -javaagent:/usr/agent/shardingsphere-agent-5.5.1-SNAPSHOT.jar
-    -jar \
-    /example.jar
+COPY --from=apache/shardingsphere-agent:latest /usr/agent/ 
/shardingsphere-agent/
+```
+
+#### 夜间构建
+
+ShardingSphere Agent 在 
https://github.com/apache/shardingsphere/pkgs/container/shardingsphere-agent 
存在夜间构建的 Docker Image。
+
+若在自定义 `Dockerfile` 中添加以下语句,这会将 ShardingSphere Agent 的目录复制到 
`/shardingsphere-agent/` 。
+
+```dockerfile
+COPY --from=ghcr.io/apache/shardingsphere-agent:latest /usr/agent/ 
/shardingsphere-agent/
+```
+
+#### 通过 Dockerfile 使用
+
+引入一个典型场景,
+
+1. 假设通过如下的 Bash 命令部署了 Jaeger All in One 的 Docker Container,
+
+```shell
+docker network create example-net
+docker run --rm -d \
+  --name jaeger \
+  -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
+  -p 16686:16686 \
+  -p 4317:4317 \
+  -p 4318:4318 \
+  -p 9411:9411 \
+  --network example-net \
+  jaegertracing/all-in-one:1.60.0
 ```
 
-`custom-agent.yaml` 的内容可能如下,
-`http://localhost:4318` 指向本地部署的 `otel/opentelemetry-collector-contrib:0.108.0` 
的 Docker Container。
+2. 假设 `./custom-agent.yaml` 包含 ShardingSphere Agent 的配置,内容可能如下,
 
 ```yaml
 plugins:
@@ -136,13 +165,33 @@ plugins:
     OpenTelemetry:
       props:
         otel.service.name: "example"
-        otel.exporter.otlp.traces.endpoint: "http://localhost:4318";
+        otel.exporter.otlp.traces.endpoint: "http://jaeger:4318";
 ```
 
-或者在 `Dockerfile` 中添加以下语句,这会将 Agent 的目录复制到 `/shardingsphere-agent/` 。
+3. 假设`./target/example.jar` 是一个即将使用 ShardingSphere Agent 的 Spring Boot 的 Uber 
JAR,
+可通过类似如下的 `Dockerfile` 来为类似 `example.jar` 的 JAR 使用夜间构建的 Docker Image 中的 
ShardingSphere Agent。
 
 ```dockerfile
-COPY --from=ghcr.io/apache/shardingsphere-agent:latest /usr/agent/ 
/shardingsphere-agent/
+FROM ghcr.io/apache/shardingsphere-agent:latest
+COPY ./target/example.jar /app.jar
+COPY ./custom-agent.yaml /usr/agent/conf/agent.yaml
+ENTRYPOINT 
["java","-javaagent:/usr/agent/shardingsphere-agent-5.5.1-SNAPSHOT.jar","-jar","/app.jar"]
+```
+
+如果是通过本地构建 `apache/shardingsphere-agent:latest` 的 Docker Image,`Dockerfile` 
可能如下,
+
+```dockerfile
+FROM apache/shardingsphere-agent:latest
+COPY ./target/example.jar /app.jar
+COPY ./custom-agent.yaml /usr/agent/conf/agent.yaml
+ENTRYPOINT 
["java","-javaagent:/usr/agent/shardingsphere-agent-5.5.1-SNAPSHOT.jar","-jar","/app.jar"]
+```
+
+4. 享受它,
+
+```shell
+docker build -t example/gs-spring-boot-docker:latest .
+docker run --network example-net example/gs-spring-boot-docker:latest
 ```
 
 ## Metrics
diff --git 
a/docs/document/content/user-manual/shardingsphere-jdbc/observability/_index.en.md
 
b/docs/document/content/user-manual/shardingsphere-jdbc/observability/_index.en.md
index 06959469c2b..0e7b2d3e4d4 100644
--- 
a/docs/document/content/user-manual/shardingsphere-jdbc/observability/_index.en.md
+++ 
b/docs/document/content/user-manual/shardingsphere-jdbc/observability/_index.en.md
@@ -112,27 +112,54 @@ java 
-javaagent:/agent/shardingsphere-agent-${latest.release.version}.jar -jar t
 + 3 Access to started service
 + 4 Check whether the corresponding plug-in is effective
 
-### Nightly Builds
+### Docker
 
-A nightly built Docker Image of ShardingSphere Agent exists at 
https://github.com/orgs/apache/packages?repo_name=shardingsphere .
+#### Local Build
 
-You can use ShardingSphere Agent in this Docker Image for a JAR like 
`example.jar` by using a `Dockerfile` like the following.
+ShardingSphere Agent has a `Dockerfile` available for easy distribution. You 
can execute the following command to build a Docker Image,
 
-Assume `example.jar` is an Uber JAR of Spring Boot that will use 
ShardingSphere Agent,
-and `custom-agent.yaml` contains the configuration of ShardingSphere Agent.
+```shell
+git clone [email protected]:apache/shardingsphere.git
+cd ./shardingsphere/
+./mvnw -am -pl distribution/agent -Prelease,docker -T1C -DskipTests clean 
package
+```
+
+If you add the following statement in your custom `Dockerfile`, it will copy 
the ShardingSphere Agent directory to `/shardingsphere-agent/`.
 
 ```dockerfile
-FROM ghcr.io/apache/shardingsphere-agent:latest
-COPY ./example.jar /example.jar
-COPY ./custom-agent.yaml /usr/agent/conf/agent.yaml
-ENTRYPOINT java \
-    -javaagent:/usr/agent/shardingsphere-agent-5.5.1-SNAPSHOT.jar
-    -jar \
-    /example.jar
+COPY --from=apache/shardingsphere-agent:latest /usr/agent/ 
/shardingsphere-agent/
 ```
 
-The content of `custom-agent.yaml` may be as follows,
-`http://localhost:4318` points to the locally deployed 
`otel/opentelemetry-collector-contrib:0.108.0` Docker Container.
+#### Nightly Build
+
+ShardingSphere Agent has a nightly built Docker Image at 
https://github.com/apache/shardingsphere/pkgs/container/shardingsphere-agent .
+
+If you add the following statement in your custom `Dockerfile`, it will copy 
the ShardingSphere Agent directory to `/shardingsphere-agent/`.
+
+```dockerfile
+COPY --from=ghcr.io/apache/shardingsphere-agent:latest /usr/agent/ 
/shardingsphere-agent/
+```
+
+#### Using Dockerfile
+
+Introduce a typical scenario,
+
+1. Assume that the Jaeger All in One Docker Container is deployed through the 
following Bash command,
+
+```shell
+docker network create example-net
+docker run --rm -d \
+  --name jaeger \
+  -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
+  -p 16686:16686 \
+  -p 4317:4317 \
+  -p 4318:4318 \
+  -p 9411:9411 \
+  --network example-net \
+  jaegertracing/all-in-one:1.60.0
+```
+
+2. Assume `./custom-agent.yaml` contains the configuration of ShardingSphere 
Agent, and the content may be as follows,
 
 ```yaml
 plugins:
@@ -140,13 +167,33 @@ plugins:
     OpenTelemetry:
       props:
         otel.service.name: "example"
-        otel.exporter.otlp.traces.endpoint: "http://localhost:4318";
+        otel.exporter.otlp.traces.endpoint: "http://jaeger:4318";
+```
+
+3. Assuming `./target/example.jar` is an Uber JAR of Spring Boot that will use 
ShardingSphere Agent, 
+you can use the ShardingSphere Agent in the nightly built Docker Image for a 
JAR like `example.jar` through a `Dockerfile` like the following.
+
+```dockerfile 
+FROM ghcr.io/apache/shardingsphere-agent:latest 
+COPY ./target/example.jar /app.jar 
+COPY ./custom-agent.yaml /usr/agent/conf/agent.yaml 
+ENTRYPOINT 
["java","-javaagent:/usr/agent/shardingsphere-agent-5.5.1-SNAPSHOT.jar","-jar","/app.jar
 "] 
 ```
 
-Or add the following statement in `Dockerfile`, which will copy the Agent 
directory to `/shardingsphere-agent/`.
+If you build the Docker Image of `apache/shardingsphere-agent:latest` locally, 
the `Dockerfile` may be as follows,
 
 ```dockerfile
-COPY --from=ghcr.io/apache/shardingsphere-agent:latest /usr/agent/ 
/shardingsphere-agent/
+FROM apache/shardingsphere-agent:latest
+COPY ./target/example.jar /app.jar
+COPY ./custom-agent.yaml /usr/agent/conf/agent.yaml
+ENTRYPOINT 
["java","-javaagent:/usr/agent/shardingsphere-agent-5.5.1-SNAPSHOT.jar","-jar","/app.jar"]
+```
+
+4. Enjoy it, 
+
+```shell 
+docker build -t example/gs-spring-boot-docker:latest . 
+docker run --network example-net example/gs-spring-boot-docker:latest 
 ```
 
 ## Metrics

Reply via email to