From fe848488f0201afa58b5b41f500cee18868e94cb Mon Sep 17 00:00:00 2001 From: nero120 Date: Tue, 1 Jan 2019 14:51:45 +0000 Subject: [PATCH 01/10] Added dockerfile and updated target api version to 1.1.7. --- dockerfile | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 dockerfile diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..cefe825 --- /dev/null +++ b/dockerfile @@ -0,0 +1,20 @@ +FROM node:10.14.2-alpine + +# Set environment variables +ENV XBROWSERSYNC_API_VERSION 1.1.7 + +WORKDIR /usr/src/api + +# Download release and unpack +RUN wget -q -O release.tar.gz https://github.com/xBrowserSync/api/archive/v$XBROWSERSYNC_API_VERSION.tar.gz \ + && tar -C . -xzf release.tar.gz \ + && rm release.tar.gz \ + && mv api-$XBROWSERSYNC_API_VERSION/* . \ + && rm -rf api-$XBROWSERSYNC_API_VERSION/ + +# Install dependencies +RUN npm install --only=production + +# Expose port and start api +EXPOSE 8080 +CMD [ "node", "dist/api.js"] \ No newline at end of file From 6554db9377142914aed900ce5f316bd6e1950980 Mon Sep 17 00:00:00 2001 From: nero120 Date: Mon, 7 Jan 2019 11:55:50 +0000 Subject: [PATCH 02/10] Updated target api version to 1.1.8. --- dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfile b/dockerfile index cefe825..1c1bbc4 100644 --- a/dockerfile +++ b/dockerfile @@ -1,7 +1,7 @@ FROM node:10.14.2-alpine # Set environment variables -ENV XBROWSERSYNC_API_VERSION 1.1.7 +ENV XBROWSERSYNC_API_VERSION 1.1.8 WORKDIR /usr/src/api From fac91dced74a87f314684610aa3916bd7cade44a Mon Sep 17 00:00:00 2001 From: nero120 Date: Mon, 24 Jun 2019 10:55:40 +0100 Subject: [PATCH 03/10] Updated docker files to use API v1.1.9 and latest dependencies. --- docker-compose.yml | 6 +++--- dockerfile | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index fd3a0dc..35e569b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: - "MONGO_INITDB_DATABASE=xbrowsersync" - "MONGO_INITDB_ROOT_PASSWORD=$XBS_DB_PASSWORD" - "MONGO_INITDB_ROOT_USERNAME=$XBS_DB_USERNAME" - image: "mongo:4.0.4" + image: "mongo:4.0.10" labels: - "traefik.enable=false" networks: @@ -26,7 +26,7 @@ services: environment: - "XBROWSERSYNC_DB_PWD=$XBS_DB_PASSWORD" - "XBROWSERSYNC_DB_USER=$XBS_DB_USERNAME" - image: "xbrowsersync/api:1.1.6" + image: "xbrowsersync/api:1.1.9" labels: - "traefik.frontend.rule=Host:$XBS_API_HOSTNAME" - "traefik.port=8080" @@ -40,7 +40,7 @@ services: container_name: "xbs-reverse-proxy" depends_on: - "api" - image: traefik:1.7.5-alpine + image: traefik:1.7.12-alpine labels: - "traefik.enable=false" networks: diff --git a/dockerfile b/dockerfile index 1c1bbc4..c972e27 100644 --- a/dockerfile +++ b/dockerfile @@ -1,7 +1,7 @@ -FROM node:10.14.2-alpine +FROM node:10.16.0-alpine # Set environment variables -ENV XBROWSERSYNC_API_VERSION 1.1.8 +ENV XBROWSERSYNC_API_VERSION 1.1.9 WORKDIR /usr/src/api From eccab5084f847643180c3ec26366b96170a31e40 Mon Sep 17 00:00:00 2001 From: Rich Date: Fri, 28 Jun 2019 11:27:10 +0100 Subject: [PATCH 04/10] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 639fb0a..836c535 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ This repository contains the Docker files required to get your own [xBrowserSync ## Running the API image -Running the API image alone requires that you have a MongoDB instance and, ideally, a web server to reverse proxy the API behind. +Running the API image alone requires that you have a MongoDB instance and (ideally) a web server to reverse proxy the API behind. 1. Create a file named `settings.json` and include any required custom [settings](https://github.com/xbrowsersync/api#3-modify-configuration-settings) values, such as those for connecting to your MongoDB instance. For example, if you are running Docker and MongoDB on a windows server, you would point the service at the MongoDB instance running on the host using the following settings: @@ -67,4 +67,4 @@ If you do not already have a MongoDB instance or are intending to expose your xB ## Issues and feature requests -Please log Docker-related issues in the [api-docker Issues list](https://github.com/xbrowsersync/api-docker/issues), if you have found an issue with the xBrowserSync API itself or wish to request a new feature, do so in the [api Issues list](https://github.com/xbrowsersync/api/issues/). \ No newline at end of file +Please log Docker-related issues in the [api-docker Issues list](https://github.com/xbrowsersync/api-docker/issues), if you have found an issue with the xBrowserSync API itself or wish to request a new feature, do so in the [api Issues list](https://github.com/xbrowsersync/api/issues/). From 821f82a2b3fed5bf6429664ec0fbfa61a8388218 Mon Sep 17 00:00:00 2001 From: nero120 Date: Tue, 8 Oct 2019 22:00:31 +0100 Subject: [PATCH 05/10] Updated target api version to 1.1.10 and latest dependencies. --- docker-compose.yml | 6 +++--- dockerfile | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 35e569b..fa0edbd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: - "MONGO_INITDB_DATABASE=xbrowsersync" - "MONGO_INITDB_ROOT_PASSWORD=$XBS_DB_PASSWORD" - "MONGO_INITDB_ROOT_USERNAME=$XBS_DB_USERNAME" - image: "mongo:4.0.10" + image: "mongo:4.2.0" labels: - "traefik.enable=false" networks: @@ -26,7 +26,7 @@ services: environment: - "XBROWSERSYNC_DB_PWD=$XBS_DB_PASSWORD" - "XBROWSERSYNC_DB_USER=$XBS_DB_USERNAME" - image: "xbrowsersync/api:1.1.9" + image: "xbrowsersync/api:1.1.10" labels: - "traefik.frontend.rule=Host:$XBS_API_HOSTNAME" - "traefik.port=8080" @@ -40,7 +40,7 @@ services: container_name: "xbs-reverse-proxy" depends_on: - "api" - image: traefik:1.7.12-alpine + image: "traefik:1.7.18-alpine" labels: - "traefik.enable=false" networks: diff --git a/dockerfile b/dockerfile index c972e27..ea03e45 100644 --- a/dockerfile +++ b/dockerfile @@ -1,7 +1,7 @@ -FROM node:10.16.0-alpine +FROM node:10.16.3-alpine # Set environment variables -ENV XBROWSERSYNC_API_VERSION 1.1.9 +ENV XBROWSERSYNC_API_VERSION 1.1.10 WORKDIR /usr/src/api From da3bed3630d3605a12e2d0194482925fa6fe6b81 Mon Sep 17 00:00:00 2001 From: nero120 Date: Tue, 21 Jan 2020 05:25:48 +0000 Subject: [PATCH 06/10] Updated target api version to 1.1.11 and latest dependencies. --- docker-compose.yml | 6 +++--- dockerfile | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index fa0edbd..7603dfb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: - "MONGO_INITDB_DATABASE=xbrowsersync" - "MONGO_INITDB_ROOT_PASSWORD=$XBS_DB_PASSWORD" - "MONGO_INITDB_ROOT_USERNAME=$XBS_DB_USERNAME" - image: "mongo:4.2.0" + image: "mongo:4.2.2" labels: - "traefik.enable=false" networks: @@ -26,7 +26,7 @@ services: environment: - "XBROWSERSYNC_DB_PWD=$XBS_DB_PASSWORD" - "XBROWSERSYNC_DB_USER=$XBS_DB_USERNAME" - image: "xbrowsersync/api:1.1.10" + image: "xbrowsersync/api:1.1.11" labels: - "traefik.frontend.rule=Host:$XBS_API_HOSTNAME" - "traefik.port=8080" @@ -40,7 +40,7 @@ services: container_name: "xbs-reverse-proxy" depends_on: - "api" - image: "traefik:1.7.18-alpine" + image: "traefik:1.7.20-alpine" labels: - "traefik.enable=false" networks: diff --git a/dockerfile b/dockerfile index ea03e45..b7b248f 100644 --- a/dockerfile +++ b/dockerfile @@ -1,7 +1,7 @@ -FROM node:10.16.3-alpine +FROM node:10.18.1-alpine # Set environment variables -ENV XBROWSERSYNC_API_VERSION 1.1.10 +ENV XBROWSERSYNC_API_VERSION 1.1.11 WORKDIR /usr/src/api From 76d2d1e799ffd2d02539454311e29d2bd90f484f Mon Sep 17 00:00:00 2001 From: nero120 Date: Wed, 29 Apr 2020 14:53:47 +0100 Subject: [PATCH 07/10] Updated target api version to 1.1.12 and latest dependencies. --- docker-compose.yml | 6 +++--- dockerfile | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 7603dfb..8664bd4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: - "MONGO_INITDB_DATABASE=xbrowsersync" - "MONGO_INITDB_ROOT_PASSWORD=$XBS_DB_PASSWORD" - "MONGO_INITDB_ROOT_USERNAME=$XBS_DB_USERNAME" - image: "mongo:4.2.2" + image: "mongo:4.2.6" labels: - "traefik.enable=false" networks: @@ -26,7 +26,7 @@ services: environment: - "XBROWSERSYNC_DB_PWD=$XBS_DB_PASSWORD" - "XBROWSERSYNC_DB_USER=$XBS_DB_USERNAME" - image: "xbrowsersync/api:1.1.11" + image: "xbrowsersync/api:1.1.12" labels: - "traefik.frontend.rule=Host:$XBS_API_HOSTNAME" - "traefik.port=8080" @@ -40,7 +40,7 @@ services: container_name: "xbs-reverse-proxy" depends_on: - "api" - image: "traefik:1.7.20-alpine" + image: "traefik:1.7.24-alpine" labels: - "traefik.enable=false" networks: diff --git a/dockerfile b/dockerfile index b7b248f..559ce61 100644 --- a/dockerfile +++ b/dockerfile @@ -1,7 +1,7 @@ -FROM node:10.18.1-alpine +FROM node:12.16.2-alpine # Set environment variables -ENV XBROWSERSYNC_API_VERSION 1.1.11 +ENV XBROWSERSYNC_API_VERSION 1.1.12 WORKDIR /usr/src/api From 024b624d9e3dbf0736ab9472554d18626a5994be Mon Sep 17 00:00:00 2001 From: nero120 Date: Fri, 2 Apr 2021 01:27:43 +0100 Subject: [PATCH 08/10] Updated target api version to 1.1.13. Replaced traefik with Caddy as reverse proxy. Added health check for api in docker compose (resolves #4). Updated node to v14 and other dependencies. --- README.md | 18 +++++------------ acme.json | 0 docker-compose.yml | 48 +++++++++++++++++++--------------------------- dockerfile | 4 ++-- healthcheck.js | 44 ++++++++++++++++++++++++++++++++++++++++++ traefik.toml | 23 ---------------------- 6 files changed, 71 insertions(+), 66 deletions(-) delete mode 100644 acme.json create mode 100644 healthcheck.js delete mode 100644 traefik.toml diff --git a/README.md b/README.md index 836c535..14b4a79 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Running the API image alone requires that you have a MongoDB instance and (ideal ## Running a production-ready service -If you do not already have a MongoDB instance or are intending to expose your xBrowserSync service over the internet then it is recommended to use the provided [`docker-compose.yml`](https://github.com/xbrowsersync/api-docker/blob/master/docker-compose.yml) which will create fully configured containers for a MongoDB database, the xBrowserSync API and a [traefik](https://traefik.io/) reverse proxy web server to run in front of the API. Traefik automatically acquires and updates SSL certificates from [Let's Encrypt](https://letsencrypt.org/) so that your xBrowserSync API service will run securely over HTTPS. +If you do not already have a MongoDB instance or are intending to expose your xBrowserSync service over the internet then it is recommended to use the provided [`docker-compose.yml`](https://github.com/xbrowsersync/api-docker/blob/master/docker-compose.yml) which will create fully configured containers for a MongoDB database, the xBrowserSync API and a [Caddy](https://caddyserver.com/) web server as a reverse proxy in front of the API. Caddy automatically acquires and updates SSL certificates so that your xBrowserSync API service will run securely over HTTPS. 1. Clone the [api-docker](https://github.com/xbrowsersync/api-docker/) GitHub repo: @@ -45,22 +45,14 @@ If you do not already have a MongoDB instance or are intending to expose your xB $ git clone https://github.com/xbrowsersync/api-docker.git ``` - 2. Secure the [`acme.json`](https://github.com/xbrowsersync/api-docker/blob/master/acme.json) file as per traefik's requirements: + 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. - ``` - $ sudo chmod 600 acme.json - ``` - - 3. 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. - - 4. Open the [`traefik.toml`](https://github.com/xbrowsersync/api-docker/blob/master/traefik.toml) file in a text editor and update the `email` value on [line 18](https://github.com/xbrowsersync/api-docker/blob/master/traefik.toml#L18) to your own email address in order to successfully acquire an SSL certificate from [Let's Encrypt](https://letsencrypt.org/). - - 5. (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. + 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. - 6. Run the following command to start the containers: + 4. Run the following command to start the containers: ``` - $ sudo 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. diff --git a/acme.json b/acme.json deleted file mode 100644 index e69de29..0000000 diff --git a/docker-compose.yml b/docker-compose.yml index 8664bd4..8a8e45c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,5 @@ version: "3.7" -volumes: - xbs-db-data: - services: db: container_name: "xbs-db" @@ -10,12 +7,8 @@ services: - "MONGO_INITDB_DATABASE=xbrowsersync" - "MONGO_INITDB_ROOT_PASSWORD=$XBS_DB_PASSWORD" - "MONGO_INITDB_ROOT_USERNAME=$XBS_DB_USERNAME" - image: "mongo:4.2.6" - labels: - - "traefik.enable=false" - networks: - - "xbs-net" - restart: "always" + image: "mongo:4.4.4" + restart: "unless-stopped" volumes: - "xbs-db-data:/data/db" - "./mongoconfig.js:/docker-entrypoint-initdb.d/mongoconfig.js" @@ -26,33 +19,32 @@ services: environment: - "XBROWSERSYNC_DB_PWD=$XBS_DB_PASSWORD" - "XBROWSERSYNC_DB_USER=$XBS_DB_USERNAME" - image: "xbrowsersync/api:1.1.12" - labels: - - "traefik.frontend.rule=Host:$XBS_API_HOSTNAME" - - "traefik.port=8080" - networks: - - "xbs-net" - restart: "always" + healthcheck: + test: [ "CMD", "node", "/usr/src/api/healthcheck.js" ] + interval: "1m" + timeout: "10s" + retries: "5" + start_period: "30s" + image: "xbrowsersync/api:1.1.13" + restart: "unless-stopped" volumes: - "./settings.json:/usr/src/api/config/settings.json" + - "./healthcheck.js:/usr/src/api/healthcheck.js" reverse-proxy: - command: "--api --docker" + command: "caddy reverse-proxy --from $XBS_API_HOSTNAME --to api:8080" container_name: "xbs-reverse-proxy" depends_on: - "api" - image: "traefik:1.7.24-alpine" - labels: - - "traefik.enable=false" - networks: - - "xbs-net" + image: "caddy:2.3.0-alpine" ports: - "443:443" - "80:80" - restart: "always" + restart: "unless-stopped" volumes: - - "/var/run/docker.sock:/var/run/docker.sock" - - "./acme.json:/acme.json" - - "./traefik.toml:/traefik.toml" + - "xbs-caddy-config:/config" + - "xbs-caddy-data:/data" -networks: - xbs-net: \ No newline at end of file +volumes: + xbs-caddy-config: + xbs-caddy-data: + xbs-db-data: diff --git a/dockerfile b/dockerfile index 559ce61..10cd4b3 100644 --- a/dockerfile +++ b/dockerfile @@ -1,7 +1,7 @@ -FROM node:12.16.2-alpine +FROM node:14.16.0-alpine # Set environment variables -ENV XBROWSERSYNC_API_VERSION 1.1.12 +ENV XBROWSERSYNC_API_VERSION 1.1.13 WORKDIR /usr/src/api diff --git a/healthcheck.js b/healthcheck.js new file mode 100644 index 0000000..f8fafb9 --- /dev/null +++ b/healthcheck.js @@ -0,0 +1,44 @@ +const http = require('http'); + +const response = http.request( + { + host: '0.0.0.0', + method: 'GET', + path: '/info', + port: 8080, + timeout: 2000, + }, + (res) => { + let body = ''; + res.setEncoding('utf8'); + + res.on('data', (chunk) => { + body += chunk; + }); + + res.on('end', () => { + if (res.statusCode === 200) { + const payload = JSON.parse(body); + switch (payload.status) { + case 1: + case 3: + console.log('HEALTHCHECK: online'); + process.exit(0); + case 2: + default: + console.log('HEALTHCHECK: offline'); + } + } else { + console.log('HEALTHCHECK: offline'); + } + process.exit(1); + }); + } +); + +response.on('error', function (err) { + console.log('HEALTHCHECK: offline'); + process.exit(1); +}); + +response.end(); diff --git a/traefik.toml b/traefik.toml deleted file mode 100644 index de951b7..0000000 --- a/traefik.toml +++ /dev/null @@ -1,23 +0,0 @@ -defaultEntryPoints = ["http", "https"] - -[entryPoints] - [entryPoints.http] - address = ":80" - [entryPoints.http.redirect] - entryPoint = "https" - [entryPoints.https] - address = ":443" - [entryPoints.https.tls] - -[retry] - -[api] -dashboard = false - -[acme] -email = "you@yourdomain.org" -storage = "acme.json" -entryPoint = "https" -onHostRule = true - [acme.httpChallenge] - entryPoint = "http" \ No newline at end of file From 2ee8777459b5a52fc60034b1205d7235cb0a34ba Mon Sep 17 00:00:00 2001 From: nero120 Date: Sat, 3 Apr 2021 01:52:00 +0100 Subject: [PATCH 09/10] 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. --- .env | 9 ++++--- README.md | 65 ++++++++++++++++++++++++++++++++++++++++++---- docker-compose.yml | 17 +++++++----- 3 files changed, 76 insertions(+), 15 deletions(-) diff --git a/.env b/.env index 39f3876..89b8f5b 100644 --- a/.env +++ b/.env @@ -1,4 +1,5 @@ -COMPOSE_CONVERT_WINDOWS_PATHS=1 -XBS_API_HOSTNAME=xbsapi.yourdomain.org -XBS_DB_PASSWORD=xbsdbpass -XBS_DB_USERNAME=xbsdb \ No newline at end of file +API_HOSTNAME=xbsapi.yourdomain.org +DB_NAME=xbrowsersync +DB_PASSWORD=xbsdbpass +DB_USERNAME=xbsdb +COMPOSE_CONVERT_WINDOWS_PATHS=1 \ No newline at end of file diff --git a/README.md b/README.md index 14b4a79..3c3531a 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 8a8e45c..21d837e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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" @@ -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" @@ -47,4 +51,5 @@ services: volumes: xbs-caddy-config: xbs-caddy-data: + xbs-db-backups: xbs-db-data: From 5c332ebadc310ef4c50a67d11f29c98de77f87ab Mon Sep 17 00:00:00 2001 From: alydev Date: Fri, 10 May 2024 08:45:54 +1000 Subject: [PATCH 10/10] captain --- captain-definition | 4 ++++ settings.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 captain-definition diff --git a/captain-definition b/captain-definition new file mode 100644 index 0000000..8dbd8fd --- /dev/null +++ b/captain-definition @@ -0,0 +1,4 @@ +{ + "schemaVersion": 2, + "dockerfilePath": "./dockerfile" +} diff --git a/settings.json b/settings.json index 43cb51c..d698573 100644 --- a/settings.json +++ b/settings.json @@ -1,5 +1,5 @@ { "db": { - "host": "db" + "host": "srv-captain--mongodb" } }