Browse Source

Improve logic for docker upgrade

pull/9688/head
Andrii Landiak 3 years ago
parent
commit
60fb14a708
  1. 23
      application/src/main/data/json/edge/instructions/upgrade/centos/instructions.md
  2. 5
      application/src/main/data/json/edge/instructions/upgrade/docker/instructions.md
  3. 16
      application/src/main/data/json/edge/instructions/upgrade/docker/start_service.md
  4. 11
      application/src/main/data/json/edge/instructions/upgrade/docker/stop_service.md
  5. 2
      application/src/main/data/json/edge/instructions/upgrade/docker/upgrade_db.md
  6. 10
      application/src/main/data/json/edge/instructions/upgrade/docker/upgrade_preparing.md
  7. 5
      application/src/main/data/json/edge/instructions/upgrade/docker/upgrade_rm.md
  8. 2
      application/src/main/data/json/edge/instructions/upgrade/start_service.md
  9. 6
      application/src/main/data/json/edge/instructions/upgrade/stop_service.md
  10. 12
      application/src/main/data/json/edge/instructions/upgrade/ubuntu/instructions.md
  11. 7
      application/src/main/data/json/edge/instructions/upgrade/upgrade_preparing.md
  12. 36
      application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeUpgradeService.java

23
application/src/main/data/json/edge/instructions/upgrade/centos/instructions.md

@ -1,30 +1,15 @@
#### Upgrading to ${TB_EDGE_VERSION_TITLE} #### Upgrading to ${TB_EDGE_VERSION}EDGE
**NOTE**:These steps are applicable for ThingsBoard Edge ${CURRENT_TB_EDGE_VERSION} version.
**ThingsBoard Edge package download** **ThingsBoard Edge package download:**
```bash ```bash
wget https://github.com/thingsboard/thingsboard-edge/releases/download/v${TB_EDGE_TAG}/tb-edge-${TB_EDGE_TAG}.rpm wget https://github.com/thingsboard/thingsboard-edge/releases/download/v${TB_EDGE_TAG}/tb-edge-${TB_EDGE_TAG}.rpm
{:copy-code} {:copy-code}
``` ```
##### ThingsBoard Edge service upgrade
#### ThingsBoard Edge service upgrade Install package:
Stop ThingsBoard Edge service if it is running:
```bash
sudo service tb-edge stop
{:copy-code}
```
```bash ```bash
sudo rpm -Uvh tb-edge-${TB_EDGE_TAG}.rpm sudo rpm -Uvh tb-edge-${TB_EDGE_TAG}.rpm
{:copy-code} {:copy-code}
``` ```
${UPGRADE_DB} ${UPGRADE_DB}
Start the service
```bash
sudo service tb-edge start
{:copy-code}
```

5
application/src/main/data/json/edge/instructions/upgrade/docker/instructions.md

@ -1,6 +1,5 @@
#### Upgrading to ${TB_EDGE_VERSION} #### Upgrading to ${TB_EDGE_VERSION}
**NOTE**:These steps are applicable for ThingsBoard Edge ${CURRENT_TB_EDGE_VERSION} version.
Execute the following command to pull **${TB_EDGE_VERSION}** image: Execute the following command to pull **${TB_EDGE_VERSION}** image:
```bash ```bash
@ -8,8 +7,4 @@ docker pull thingsboard/tb-edge:${TB_EDGE_VERSION}
{:copy-code} {:copy-code}
``` ```
${STOP_SERVICE}
${UPGRADE_DB} ${UPGRADE_DB}
Make sure your image is the set to tb-edge-${TB_EDGE_VERSION}.

16
application/src/main/data/json/edge/instructions/upgrade/docker/start_service.md

@ -1,3 +1,19 @@
Modify ‘main’ docker compose (`docker-compose.yml`) file for ThingsBoard Edge and update version of the image:
```bash
nano docker-compose.yml
{:copy-code}
```
```text
version: '3.0'
services:
mytbedge:
restart: always
image: "thingsboard/tb-edge:${TB_EDGE_VERSION}"
...
```
Make sure your image is the set to tb-edge-${TB_EDGE_VERSION}.
Execute the following commands to up this docker compose directly: Execute the following commands to up this docker compose directly:
```bash ```bash

11
application/src/main/data/json/edge/instructions/upgrade/docker/stop_service.md

@ -1,11 +0,0 @@
Set the terminal in the directory which contains the `docker-compose.yml` file and execute the following command to stop
and remove currently running TB Edge container (if it’s still running):
```bash
make <span style="color:red;">docker-compose.yml</span>
```bash
docker compose stop
docker compose rm mytbedge
{:copy-code}
```

2
application/src/main/data/json/edge/instructions/upgrade/docker/upgrade_db.md

@ -1,3 +1,5 @@
${CLEAR_DOCKER_UPGRADE}
Create docker compose file for ThingsBoard Edge upgrade process: Create docker compose file for ThingsBoard Edge upgrade process:
```bash ```bash

10
application/src/main/data/json/edge/instructions/upgrade/docker/upgrade_preparing.md

@ -10,17 +10,15 @@ docker compose rm mytbedge
{:copy-code} {:copy-code}
``` ```
If you still rely on Docker Compose as docker-compose (with a hyphen) here is the list of the above commands: **OPTIONAL:** If you still rely on Docker Compose as docker-compose (with a hyphen) here is the list of the above commands:
```text
docker-compose stop docker-compose stop
docker-compose rm mytbedge docker-compose rm mytbedge
```
#### Backup Database ##### Backup Database
Make a copy of the database folder before upgrading: Make a copy of the database folder before upgrading:
```bash ```bash
sudo cp -r ~/.mytb-edge-data/db ~/.mytb-edge-db-BACKUP sudo cp -r ~/.mytb-edge-data/db ~/.mytb-edge-db-BACKUP
{:copy-code} {:copy-code}
``` ```
```bash
make <span style="color:red;">docker-compose.yml</span>

5
application/src/main/data/json/edge/instructions/upgrade/docker/upgrade_rm.md

@ -0,0 +1,5 @@
Delete docker compose file, if already exists:
```bash
rm docker-compose-upgrade.yml
{:copy-code}
```

2
application/src/main/data/json/edge/instructions/upgrade/start_service.md

@ -1,6 +1,6 @@
Start the service Start the service
```bash ```bash
sudo service tb-edge start sudo systemctl tb-edge start
{:copy-code} {:copy-code}
``` ```

6
application/src/main/data/json/edge/instructions/upgrade/stop_service.md

@ -1,6 +0,0 @@
Stop ThingsBoard Edge service if it is running:
```bash
sudo service tb-edge stop
{:copy-code}
```

12
application/src/main/data/json/edge/instructions/upgrade/ubuntu/instructions.md

@ -1,19 +1,15 @@
#### Upgrading to ${TB_EDGE_VERSION} #### Upgrading to ${TB_EDGE_VERSION}EDGE
**NOTE**:These steps are applicable for ThingsBoard Edge ${CURRENT_TB_EDGE_VERSION} version.
**ThingsBoard Edge package download** **ThingsBoard Edge package download:**
```bash ```bash
wget https://github.com/thingsboard/thingsboard-edge/releases/download/v${TB_EDGE_TAG}/tb-edge-${TB_EDGE_TAG}.deb wget https://github.com/thingsboard/thingsboard-edge/releases/download/v${TB_EDGE_TAG}/tb-edge-${TB_EDGE_TAG}.deb
{:copy-code} {:copy-code}
``` ```
##### ThingsBoard Edge service upgrade
#### ThingsBoard Edge service upgrade Install package:
${STOP_SERVICE}
```bash ```bash
sudo dpkg -i tb-edge-${TB_EDGE_TAG}.deb sudo dpkg -i tb-edge-${TB_EDGE_TAG}.deb
{:copy-code} {:copy-code}
``` ```
${UPGRADE_DB} ${UPGRADE_DB}

7
application/src/main/data/json/edge/instructions/upgrade/upgrade_preparing.md

@ -1,4 +1,4 @@
Here is the list of commands, that can be used to quickly upgrade ThingsBoard Edge on RHEL/CentOS 7/8. Here is the list of commands, that can be used to quickly upgrade ThingsBoard Edge on ${OS}
#### Prepare for upgrading ThingsBoard Edge #### Prepare for upgrading ThingsBoard Edge
@ -9,9 +9,8 @@ sudo systemctl stop tb-edge
{:copy-code} {:copy-code}
``` ```
#### Backup Database ##### Backup Database
Make a backup of the database before upgrading. Make a backup of the database before upgrading. **Make sure you have enough space to place a backup of the database.**
**Make sure you have enough space to place a backup of the database.**
Check database size: Check database size:

36
application/src/main/java/org/thingsboard/server/service/edge/instructions/DefaultEdgeUpgradeService.java

@ -74,10 +74,10 @@ public class DefaultEdgeUpgradeService implements EdgeUpgradeService {
private EdgeInstructions getDockerUpgradeInstructions(String tbVersion, String currentEdgeVersion) { private EdgeInstructions getDockerUpgradeInstructions(String tbVersion, String currentEdgeVersion) {
UpgradeInfo upgradeInfo = upgradeVersionHashMap.get(currentEdgeVersion); UpgradeInfo upgradeInfo = upgradeVersionHashMap.get(currentEdgeVersion);
if (upgradeInfo.getNextVersion() == null || tbVersion.equals(currentEdgeVersion)) { if (upgradeInfo == null || upgradeInfo.getNextVersion() == null || tbVersion.equals(currentEdgeVersion)) {
return null; return new EdgeInstructions("Edge upgrade instruction for " + currentEdgeVersion + "EDGE is not available.");
} }
boolean stoppedService = false; boolean rmUpgradeCompose = false;
StringBuilder result = new StringBuilder(readFile(resolveFile("docker", "upgrade_preparing.md"))); StringBuilder result = new StringBuilder(readFile(resolveFile("docker", "upgrade_preparing.md")));
while (upgradeInfo.getNextVersion() != null || !tbVersion.equals(currentEdgeVersion)) { while (upgradeInfo.getNextVersion() != null || !tbVersion.equals(currentEdgeVersion)) {
String edgeVersion = upgradeInfo.getNextVersion(); String edgeVersion = upgradeInfo.getNextVersion();
@ -85,13 +85,15 @@ public class DefaultEdgeUpgradeService implements EdgeUpgradeService {
if (upgradeInfo.isUpgradeDb()) { if (upgradeInfo.isUpgradeDb()) {
String upgradeDb = readFile(resolveFile("docker", "upgrade_db.md")); String upgradeDb = readFile(resolveFile("docker", "upgrade_db.md"));
ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${UPGRADE_DB}", upgradeDb); ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${UPGRADE_DB}", upgradeDb);
} else {
ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${UPGRADE_DB}", "");
} }
if (!stoppedService) { if (!rmUpgradeCompose) {
stoppedService = true; rmUpgradeCompose = true;
String stopService = readFile(resolveFile("docker", "stop_service.md")); ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${CLEAR_DOCKER_UPGRADE}", "");
ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${STOP_SERVICE}", stopService);
} else { } else {
ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${STOP_SERVICE}", ""); String rmUpgrade = readFile(resolveFile("docker", "upgrade_rm.md"));
ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${CLEAR_DOCKER_UPGRADE}", rmUpgrade);
} }
ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${TB_EDGE_VERSION}", edgeVersion + "EDGE"); ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${TB_EDGE_VERSION}", edgeVersion + "EDGE");
ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${CURRENT_TB_EDGE_VERSION}", currentEdgeVersion + "EDGE"); ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${CURRENT_TB_EDGE_VERSION}", currentEdgeVersion + "EDGE");
@ -100,36 +102,32 @@ public class DefaultEdgeUpgradeService implements EdgeUpgradeService {
result.append(ubuntuUpgradeInstructions); result.append(ubuntuUpgradeInstructions);
} }
String startService = readFile(resolveFile("docker", "start_service.md")); String startService = readFile(resolveFile("docker", "start_service.md"));
startService = startService.replace("${TB_EDGE_VERSION}", currentEdgeVersion + "EDGE");
result.append(startService); result.append(startService);
return new EdgeInstructions(result.toString()); return new EdgeInstructions(result.toString());
} }
private EdgeInstructions getLinuxUpgradeInstructions(String tbVersion, String currentEdgeVersion, String os) { private EdgeInstructions getLinuxUpgradeInstructions(String tbVersion, String currentEdgeVersion, String os) {
UpgradeInfo upgradeInfo = upgradeVersionHashMap.get(currentEdgeVersion); UpgradeInfo upgradeInfo = upgradeVersionHashMap.get(currentEdgeVersion);
if (upgradeInfo.getNextVersion() == null || tbVersion.equals(currentEdgeVersion)) { if (upgradeInfo == null || upgradeInfo.getNextVersion() == null || tbVersion.equals(currentEdgeVersion)) {
return null; return new EdgeInstructions("Edge upgrade instruction for " + currentEdgeVersion + "EDGE is not available.");
} }
boolean stoppedService = false; String upgrade_preparing = readFile(resolveFile("upgrade_preparing.md"));
StringBuilder result = new StringBuilder(readFile(resolveFile("upgrade_preparing.md"))); upgrade_preparing = upgrade_preparing.replace("${OS}", os.equals("centos") ? "RHEL/CentOS 7/8" : "Ubuntu");
StringBuilder result = new StringBuilder(upgrade_preparing);
while (upgradeInfo.getNextVersion() != null || !tbVersion.equals(currentEdgeVersion)) { while (upgradeInfo.getNextVersion() != null || !tbVersion.equals(currentEdgeVersion)) {
String edgeVersion = upgradeInfo.getNextVersion(); String edgeVersion = upgradeInfo.getNextVersion();
String ubuntuUpgradeInstructions = readFile(resolveFile(os, "instructions.md")); String ubuntuUpgradeInstructions = readFile(resolveFile(os, "instructions.md"));
if (upgradeInfo.isUpgradeDb()) { if (upgradeInfo.isUpgradeDb()) {
String upgradeDb = readFile(resolveFile("upgrade_db.md")); String upgradeDb = readFile(resolveFile("upgrade_db.md"));
ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${UPGRADE_DB}", upgradeDb); ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${UPGRADE_DB}", upgradeDb);
}
if (!stoppedService) {
stoppedService = true;
String stopService = readFile(resolveFile("stop_service.md"));
ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${STOP_SERVICE}", stopService);
} else { } else {
ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${STOP_SERVICE}", ""); ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${UPGRADE_DB}", "");
} }
ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${TB_EDGE_TAG}", getTagVersion(edgeVersion)); ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${TB_EDGE_TAG}", getTagVersion(edgeVersion));
ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${CURRENT_TB_EDGE_TAG}", getTagVersion(currentEdgeVersion)); ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${CURRENT_TB_EDGE_TAG}", getTagVersion(currentEdgeVersion));
ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${TB_EDGE_VERSION}", edgeVersion); ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${TB_EDGE_VERSION}", edgeVersion);
ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${CURRENT_TB_EDGE_VERSION}", currentEdgeVersion); ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${CURRENT_TB_EDGE_VERSION}", currentEdgeVersion);
ubuntuUpgradeInstructions = ubuntuUpgradeInstructions.replace("${TB_EDGE_VERSION_TITLE}", edgeVersion + "EDGE");
currentEdgeVersion = edgeVersion; currentEdgeVersion = edgeVersion;
upgradeInfo = upgradeVersionHashMap.get(upgradeInfo.getNextVersion()); upgradeInfo = upgradeVersionHashMap.get(upgradeInfo.getNextVersion());
result.append(ubuntuUpgradeInstructions); result.append(ubuntuUpgradeInstructions);

Loading…
Cancel
Save