Skip to content

Commit

Permalink
Added upgrade info to README.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nero120 committed Apr 3, 2021
1 parent 024b624 commit 2ee8777
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 15 deletions.
9 changes: 5 additions & 4 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
COMPOSE_CONVERT_WINDOWS_PATHS=1
XBS_API_HOSTNAME=xbsapi.yourdomain.org
XBS_DB_PASSWORD=xbsdbpass
XBS_DB_USERNAME=xbsdb
API_HOSTNAME=xbsapi.yourdomain.org
DB_NAME=xbrowsersync
DB_PASSWORD=xbsdbpass
DB_USERNAME=xbsdb
COMPOSE_CONVERT_WINDOWS_PATHS=1
65 changes: 60 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Running the API image alone requires that you have a MongoDB instance and (ideal
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`:
```
$ 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
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
```
You can now access your xBrowserSync API service at http://127.0.0.1:8080.
Expand All @@ -42,20 +42,75 @@ If you do not already have a MongoDB instance or are intending to expose your xB
1. Clone the [api-docker](https://github.com/xbrowsersync/api-docker/) GitHub repo:
```
$ git clone https://github.com/xbrowsersync/api-docker.git
git clone https://github.com/xbrowsersync/api-docker.git
```
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.
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.
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.
4. Run the following command to start the containers:
```
$ docker-compose up -d
docker-compose up -d
```
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.
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.
## Upgrade process
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.
The following steps detail the process in full:
1. Connect to the MongoDB container:
```
docker exec -it xbs-db bash
```
2. Export db data to the `xbs-db-backups` Docker volume using [mongodump](https://docs.mongodb.com/database-tools/mongodump/):
```
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
```
3. Exit the MongoDB container and navigate to the api-docker GitHub repo folder. Stop and remove all containers:
```
docker-compose down
```
4. Delete the `xbs-db-data` Docker volume before upgrading MongoDB. You need to find the volume name first using:
```
docker volume ls
```
It will be something like `api-docker_xbs-db-data`. Once located, delete it with:
```
docker volume rm api-docker_xbs-db-data
```
5. Get latest changes and start the containers:
```
git pull
docker-compose up -d
```
6. Connect to the MongoDB container:
```
docker exec -it xbs-db bash
```
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):
```
mongorestore --username $XBS_DB_USERNAME --password $XBS_DB_PASSWORD --authenticationDatabase admin --verbose=5 --gzip --drop --archive=/data/backups/{BackupFileName}
```
## Issues and feature requests
Expand Down
17 changes: 11 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ services:
db:
container_name: "xbs-db"
environment:
- "MONGO_INITDB_DATABASE=xbrowsersync"
- "MONGO_INITDB_ROOT_PASSWORD=$XBS_DB_PASSWORD"
- "MONGO_INITDB_ROOT_USERNAME=$XBS_DB_USERNAME"
- "MONGO_INITDB_DATABASE=$DB_NAME"
- "MONGO_INITDB_ROOT_PASSWORD=$DB_PASSWORD"
- "MONGO_INITDB_ROOT_USERNAME=$DB_USERNAME"
- "XBS_DB_NAME=$DB_NAME"
- "XBS_DB_PASSWORD=$DB_PASSWORD"
- "XBS_DB_USERNAME=$DB_USERNAME"
image: "mongo:4.4.4"
restart: "unless-stopped"
volumes:
- "xbs-db-data:/data/db"
- "xbs-db-backups:/data/backups"
- "./mongoconfig.js:/docker-entrypoint-initdb.d/mongoconfig.js"
api:
container_name: "xbs-api"
depends_on:
- "db"
environment:
- "XBROWSERSYNC_DB_PWD=$XBS_DB_PASSWORD"
- "XBROWSERSYNC_DB_USER=$XBS_DB_USERNAME"
- "XBROWSERSYNC_DB_PWD=$DB_PASSWORD"
- "XBROWSERSYNC_DB_USER=$DB_USERNAME"
healthcheck:
test: [ "CMD", "node", "/usr/src/api/healthcheck.js" ]
interval: "1m"
Expand All @@ -31,7 +35,7 @@ services:
- "./settings.json:/usr/src/api/config/settings.json"
- "./healthcheck.js:/usr/src/api/healthcheck.js"
reverse-proxy:
command: "caddy reverse-proxy --from $XBS_API_HOSTNAME --to api:8080"
command: "caddy reverse-proxy --from $API_HOSTNAME --to api:8080"
container_name: "xbs-reverse-proxy"
depends_on:
- "api"
Expand All @@ -47,4 +51,5 @@ services:
volumes:
xbs-caddy-config:
xbs-caddy-data:
xbs-db-backups:
xbs-db-data:

0 comments on commit 2ee8777

Please sign in to comment.