Skip to content

Commit 2ee8777

Browse files
committed
Added upgrade info to README.
Updated mongodb container in docker-compose.yml to include db env vars. Added backup volume to mongodb container in docker-compose.yml. Updated env variable names.
1 parent 024b624 commit 2ee8777

File tree

3 files changed

+76
-15
lines changed

3 files changed

+76
-15
lines changed

.env

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
COMPOSE_CONVERT_WINDOWS_PATHS=1
2-
XBS_API_HOSTNAME=xbsapi.yourdomain.org
3-
XBS_DB_PASSWORD=xbsdbpass
4-
XBS_DB_USERNAME=xbsdb
1+
API_HOSTNAME=xbsapi.yourdomain.org
2+
DB_NAME=xbrowsersync
3+
DB_PASSWORD=xbsdbpass
4+
DB_USERNAME=xbsdb
5+
COMPOSE_CONVERT_WINDOWS_PATHS=1

README.md

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Running the API image alone requires that you have a MongoDB instance and (ideal
3030
3. Run the following command to start an API container, providing the actual path to the `settings.json` file created in step 1. The service will be exposed via port 8080. If you did not create the environment variables in step 2, you will need to provide the actual username and password values in line, i.e. `-e XBROWSERSYNC_DB_USER=YourDatabaseUsername -e XBROWSERSYNC_DB_PWD=YourDatabasePassword`:
3131
3232
```
33-
$ sudo docker run --name xbs-api -p 8080:8080 -e XBROWSERSYNC_DB_USER -e XBROWSERSYNC_DB_PWD -v /path/to/settings.json:/usr/src/api/config/settings.json -d xbrowsersync/api
33+
docker run --name xbs-api -p 8080:8080 -e XBROWSERSYNC_DB_USER -e XBROWSERSYNC_DB_PWD -v /path/to/settings.json:/usr/src/api/config/settings.json -d xbrowsersync/api
3434
```
3535
3636
You can now access your xBrowserSync API service at http://127.0.0.1:8080.
@@ -42,20 +42,75 @@ If you do not already have a MongoDB instance or are intending to expose your xB
4242
1. Clone the [api-docker](https://github.com/xbrowsersync/api-docker/) GitHub repo:
4343
4444
```
45-
$ git clone https://github.com/xbrowsersync/api-docker.git
45+
git clone https://github.com/xbrowsersync/api-docker.git
4646
```
4747
48-
2. Open the [`.env`](https://github.com/xbrowsersync/api-docker/blob/master/.env) file in a text editor and update the `XBS_API_HOSTNAME` value to correspond to the host name that the API service will be exposed over (ensure you have configured your DNS provider to point the desired host name to your host's IP address). Also, change the `XBS_DB_USERNAME` and `XBS_DB_PASSWORD` values to any of your choosing.
48+
2. Open the [`.env`](https://github.com/xbrowsersync/api-docker/blob/master/.env) file in a text editor and update the `API_HOSTNAME` value to correspond to the host name that the API service will be exposed over (ensure you have configured your DNS provider to point the desired host name to your host's IP address). Also, change the `DB_USERNAME` and `DB_PASSWORD` values to any of your choosing.
4949
5050
3. (Optionally) open the [`settings.json`](https://github.com/xbrowsersync/api-docker/blob/master/settings.json) file and include any custom [settings](https://github.com/xbrowsersync/api#3-modify-configuration-settings) values you wish to run on your service. Important: do not change the `db.host` value.
5151
5252
4. Run the following command to start the containers:
5353
5454
```
55-
$ docker-compose up -d
55+
docker-compose up -d
5656
```
5757
58-
You can now access your xBrowserSync API service over HTTPS at the value of `XBS_API_HOSTNAME` defined in the [`.env`](https://github.com/xbrowsersync/api-docker/blob/master/.env) file.
58+
You can now access your xBrowserSync API service over HTTPS at the value of `API_HOSTNAME` defined in the [`.env`](https://github.com/xbrowsersync/api-docker/blob/master/.env) file.
59+
60+
## Upgrade process
61+
62+
If you wish to upgrade your existing production-ready service created using the [`docker-compose.yml`](https://github.com/xbrowsersync/api-docker/blob/master/docker-compose.yml) file, you may encounter database errors when upgrading the MongoDB version. To avoid these issues, it is recommended that you export the db data from the old version and restore to the new version once up and running.
63+
64+
The following steps detail the process in full:
65+
66+
67+
1. Connect to the MongoDB container:
68+
69+
```
70+
docker exec -it xbs-db bash
71+
```
72+
73+
2. Export db data to the `xbs-db-backups` Docker volume using [mongodump](https://docs.mongodb.com/database-tools/mongodump/):
74+
75+
```
76+
mongodump --db $XBS_DB_NAME --host localhost --port 27017 --username $XBS_DB_USERNAME --password $XBS_DB_PASSWORD --authenticationDatabase admin --archive=/data/backups/xbs-db-`date +"%Y-%m-%d"`.gz --gzip
77+
```
78+
79+
3. Exit the MongoDB container and navigate to the api-docker GitHub repo folder. Stop and remove all containers:
80+
81+
```
82+
docker-compose down
83+
```
84+
85+
4. Delete the `xbs-db-data` Docker volume before upgrading MongoDB. You need to find the volume name first using:
86+
87+
```
88+
docker volume ls
89+
```
90+
91+
It will be something like `api-docker_xbs-db-data`. Once located, delete it with:
92+
93+
```
94+
docker volume rm api-docker_xbs-db-data
95+
```
96+
97+
5. Get latest changes and start the containers:
98+
99+
```
100+
git pull
101+
docker-compose up -d
102+
```
103+
6. Connect to the MongoDB container:
104+
105+
```
106+
docker exec -it xbs-db bash
107+
```
108+
109+
7. Restore db data from the `xbs-db-backups` Docker volume using [mongorestore](https://docs.mongodb.com/database-tools/mongorestore/) (replace `{BackupFileName}` with the actual backup file name):
110+
111+
```
112+
mongorestore --username $XBS_DB_USERNAME --password $XBS_DB_PASSWORD --authenticationDatabase admin --verbose=5 --gzip --drop --archive=/data/backups/{BackupFileName}
113+
```
59114
60115
## Issues and feature requests
61116

docker-compose.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@ services:
44
db:
55
container_name: "xbs-db"
66
environment:
7-
- "MONGO_INITDB_DATABASE=xbrowsersync"
8-
- "MONGO_INITDB_ROOT_PASSWORD=$XBS_DB_PASSWORD"
9-
- "MONGO_INITDB_ROOT_USERNAME=$XBS_DB_USERNAME"
7+
- "MONGO_INITDB_DATABASE=$DB_NAME"
8+
- "MONGO_INITDB_ROOT_PASSWORD=$DB_PASSWORD"
9+
- "MONGO_INITDB_ROOT_USERNAME=$DB_USERNAME"
10+
- "XBS_DB_NAME=$DB_NAME"
11+
- "XBS_DB_PASSWORD=$DB_PASSWORD"
12+
- "XBS_DB_USERNAME=$DB_USERNAME"
1013
image: "mongo:4.4.4"
1114
restart: "unless-stopped"
1215
volumes:
1316
- "xbs-db-data:/data/db"
17+
- "xbs-db-backups:/data/backups"
1418
- "./mongoconfig.js:/docker-entrypoint-initdb.d/mongoconfig.js"
1519
api:
1620
container_name: "xbs-api"
1721
depends_on:
1822
- "db"
1923
environment:
20-
- "XBROWSERSYNC_DB_PWD=$XBS_DB_PASSWORD"
21-
- "XBROWSERSYNC_DB_USER=$XBS_DB_USERNAME"
24+
- "XBROWSERSYNC_DB_PWD=$DB_PASSWORD"
25+
- "XBROWSERSYNC_DB_USER=$DB_USERNAME"
2226
healthcheck:
2327
test: [ "CMD", "node", "/usr/src/api/healthcheck.js" ]
2428
interval: "1m"
@@ -31,7 +35,7 @@ services:
3135
- "./settings.json:/usr/src/api/config/settings.json"
3236
- "./healthcheck.js:/usr/src/api/healthcheck.js"
3337
reverse-proxy:
34-
command: "caddy reverse-proxy --from $XBS_API_HOSTNAME --to api:8080"
38+
command: "caddy reverse-proxy --from $API_HOSTNAME --to api:8080"
3539
container_name: "xbs-reverse-proxy"
3640
depends_on:
3741
- "api"
@@ -47,4 +51,5 @@ services:
4751
volumes:
4852
xbs-caddy-config:
4953
xbs-caddy-data:
54+
xbs-db-backups:
5055
xbs-db-data:

0 commit comments

Comments
 (0)