Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support build docker image when package project #363

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
44 changes: 33 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/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.

Expand Down Expand Up @@ -122,15 +144,15 @@ nacos-sync

```

## Initialize The DB
### Initialize The DB

The default is Mysql database, which can support other relational databases

- Build db schema, the default schema name nacos_sync.
- 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:

Expand All @@ -142,7 +164,7 @@ spring.datasource.password=root

```

## Start Server
### Start Server

``` xml

Expand All @@ -151,7 +173,7 @@ sh startup.sh start

```

## Admin Console
### Admin Console

``` xml

Expand All @@ -169,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)
![img_2.png](img_2.png)
8 changes: 8 additions & 0 deletions nacossync-distribution/bin/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand Down
61 changes: 61 additions & 0 deletions nacossync-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
<packaging>pom</packaging>
<artifactId>nacossync-distribution</artifactId>

<properties>
<env.docker.host>${env.DOCKER_HOST}</env.docker.host>
<env.docker.username>${env.DOCKER_USER_NAME}</env.docker.username>
<env.docker.password>${env.DOCKER_PASSWORD}</env.docker.password>
</properties>

<build>
<finalName>nacos-sync-${project.version}</finalName>
<plugins>
Expand All @@ -33,6 +39,61 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.40.2</version>
<extensions>true</extensions>
<configuration>
<dockerHost>${env.docker.host}</dockerHost>
<authConfig>
<username>${env.docker.username}</username>
<password>${env.docker.password}</password>
</authConfig>
<images>
<image>
<name>nacos-sync</name>
<build>
<tags>
<tag>${revision}</tag>
</tags>
<from>openjdk:11</from>
<cmd>[ "/bin/bash", "/nacos-sync/bin/startup.sh", "start_hup"]</cmd>
<assembly>
<mode>dir</mode>
<targetDir>/</targetDir>
<mode>dir</mode>
<inline>
<id>nacossync-</id>
<fileSets>
<fileSet>
<directory>${project.build.directory}/nacos-sync-${project.version}</directory>
<outputDirectory>./</outputDirectory>
<includes>
<include>**</include>
</includes>
</fileSet>
</fileSets>
</inline>
</assembly>
</build>

</image>
</images>
</configuration>
<executions>
<execution>
<id>build-docker-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<distributionManagement>
</distributionManagement>
</project>
8 changes: 4 additions & 4 deletions nacossync-worker/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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