From 0d0faeb9d034c4ea0ba737b976943884fa586f5f Mon Sep 17 00:00:00 2001 From: luoxiner Date: Sun, 7 Jul 2024 15:07:09 +0800 Subject: [PATCH 1/2] support build docker image when build project --- README.md | 42 ++++++++++--- nacossync-distribution/bin/startup.sh | 8 +++ nacossync-distribution/pom.xml | 61 +++++++++++++++++++ .../src/main/resources/application.properties | 8 +-- pom.xml | 4 +- 5 files changed, 107 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 604cb5e1..7abfb0dc 100644 --- a/README.md +++ b/README.md @@ -64,24 +64,46 @@ Info | +------------+ ^ | Eureka | Nacos | Yes | Only support registery center of **Spring Cloud** | - - - ## Manual Goal - Start the NacosSync service - Use a simple example to demonstrate how to migrate a Dubbo client registered in the Zookeeper Registry to the Nacos Registry -## Prerequisites +## Quick start with docker [Recommend] +if you already have a mysql server, just run following command with your db configs +```bash +docker run -it --rm -eSERVER_PORT=${YOUR_CUSTOM_PORT} \ + -e "DATASOURCE_URL=jdbc:mysql://127.0.0.1:3306/nacos_sync?characterEncoding=utf8" \ + -e DATASOURCE_USERNAME=${YOUR_USER_NAME} \ + -e DATASOURCE_PASSWORD=${YOUR_PASSWORD} \ + nacos-sync +``` + +### Supported Envs +1. SERVER_PORT +admin server port, default is 8083 + +2. DATASOURCE_URL +datasource url, e.g. jdbc:mysql://127.0.0.1:3306/nacos_sync?characterEncoding=utf8 + +3. DATASOURCE_USERNAME +datasource user name + +4. DATASOURCE_PASSWORD +datasource password + +## Manually build and deploy + +### Prerequisites Before you begin, install the following: - 64bit OS: Linux/Unix/Mac/Windows supported, Linux/Unix/Mac recommended. -- 64bit JDK 1.8+: downloads, JAVA_HOME settings. +- 64bit JDK 11+: downloads, JAVA_HOME settings. - Maven 3.5.2+: [downloads](https://maven.apache.org/download.cgi), [settings](https://maven.apache.org/settings.html). - MySql 5.6.+ -## Download & Build From Release +### Download & Build From Release There are two ways to get NacosSync. @@ -122,7 +144,7 @@ nacos-sync ``` -## Initialize The DB +### Initialize The DB The default is Mysql database, which can support other relational databases @@ -130,7 +152,7 @@ The default is Mysql database, which can support other relational databases - Tables do not need to be created separately, which is conducive to hibernate's automatic table creation function. - If the automatic table creation fails, you can build the table nacosSync.sql, the table statement is in the bin folder. -## DB Configuration +### DB Configuration In the bin folder, application.properties: @@ -142,7 +164,7 @@ spring.datasource.password=root ``` -## Start Server +### Start Server ``` xml @@ -151,7 +173,7 @@ sh startup.sh start ``` -## Admin Console +### Admin Console ``` xml diff --git a/nacossync-distribution/bin/startup.sh b/nacossync-distribution/bin/startup.sh index caed1e8e..51912a65 100644 --- a/nacossync-distribution/bin/startup.sh +++ b/nacossync-distribution/bin/startup.sh @@ -84,11 +84,19 @@ echo "nacos-sync is starting,you can check the ${BASE_DIR}/logs/nacos-sync-sta } +start_hung(){ +echo "$JAVA ${JAVA_OPT}" > ${BASE_DIR}/logs/nacos-sync-start.out 2>&1 & +$JAVA ${JAVA_OPT} +} + case "$ACTION" in start) start ;; + start_hup) + start_hung + ;; *) usage ;; diff --git a/nacossync-distribution/pom.xml b/nacossync-distribution/pom.xml index e1447d31..2d3225ca 100644 --- a/nacossync-distribution/pom.xml +++ b/nacossync-distribution/pom.xml @@ -11,6 +11,12 @@ pom nacossync-distribution + + ${env.DOCKER_HOST} + ${env.DOCKER_USER_NAME} + ${env.DOCKER_PASSWORD} + + nacos-sync-${project.version} @@ -33,6 +39,61 @@ + + io.fabric8 + docker-maven-plugin + 0.40.2 + true + + ${env.docker.host} + + ${env.docker.username} + ${env.docker.password} + + + + nacos-sync + + + ${revision} + + openjdk:11 + [ "/bin/bash", "/nacos-sync/bin/startup.sh", "start_hup"] + + dir + / + dir + + nacossync- + + + ${project.build.directory}/nacos-sync-${project.version} + ./ + + ** + + + + + + + + + + + + + build-docker-image + package + + build + + + + + + + \ No newline at end of file diff --git a/nacossync-worker/src/main/resources/application.properties b/nacossync-worker/src/main/resources/application.properties index 0644087c..4b429113 100644 --- a/nacossync-worker/src/main/resources/application.properties +++ b/nacossync-worker/src/main/resources/application.properties @@ -1,4 +1,4 @@ -server.port=8083 +server.port=${SERVER_PORT:8083} server.servlet.context-path=/ spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect @@ -8,8 +8,8 @@ spring.jpa.properties.hibernate.show_sql=false spring.cloud.discovery.enabled=false -spring.datasource.url=jdbc:mysql://127.0.0.1:3306/nacos_sync?characterEncoding=utf8 -spring.datasource.username=root -spring.datasource.password=root +spring.datasource.url=${DATASOURCE_URL} +spring.datasource.username=${DATASOURCE_USERNAME} +spring.datasource.password=${DATASOURCE_PASSWORD} management.endpoints.web.exposure.include=* management.endpoint.health.show-details=always diff --git a/pom.xml b/pom.xml index 824aa8ff..d48dfd88 100644 --- a/pom.xml +++ b/pom.xml @@ -38,8 +38,8 @@ 3.12.0 33.2.0-jre 2.2 - 11 - 11 + 8 + 8 3.2.0 1.4.1 3.0.1 From 2fb457450fe97128e7bd7ebfa687451f50cd0c14 Mon Sep 17 00:00:00 2001 From: Xin Luo <65529035+luoxiner@users.noreply.github.com> Date: Mon, 8 Jul 2024 11:44:41 +0800 Subject: [PATCH 2/2] fix image name --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7abfb0dc..a1ced1b5 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ docker run -it --rm -eSERVER_PORT=${YOUR_CUSTOM_PORT} \ -e "DATASOURCE_URL=jdbc:mysql://127.0.0.1:3306/nacos_sync?characterEncoding=utf8" \ -e DATASOURCE_USERNAME=${YOUR_USER_NAME} \ -e DATASOURCE_PASSWORD=${YOUR_PASSWORD} \ - nacos-sync + nacos/nacos-sync ``` ### Supported Envs @@ -191,4 +191,4 @@ When “*” is entered in the “Service Name” field of this form, it will fu When “All” is entered in the “Service Name” field of this form, it will automatically synchronize all registered services within the **default group** of the current cluster. This description explains the functionality clearly for English-speaking users. -![img_2.png](img_2.png) \ No newline at end of file +![img_2.png](img_2.png)