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.
This commit is contained in:
parent
76d2d1e799
commit
024b624d9e
6 changed files with 71 additions and 66 deletions
22
README.md
22
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
|
## 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:
|
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
|
$ 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.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo chmod 600 acme.json
|
$ docker-compose up -d
|
||||||
```
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
6. Run the following command to start the containers:
|
|
||||||
|
|
||||||
```
|
|
||||||
$ sudo 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 `XBS_API_HOSTNAME` defined in the [`.env`](https://github.com/xbrowsersync/api-docker/blob/master/.env) file.
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
version: "3.7"
|
version: "3.7"
|
||||||
|
|
||||||
volumes:
|
|
||||||
xbs-db-data:
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
db:
|
db:
|
||||||
container_name: "xbs-db"
|
container_name: "xbs-db"
|
||||||
|
@ -10,12 +7,8 @@ services:
|
||||||
- "MONGO_INITDB_DATABASE=xbrowsersync"
|
- "MONGO_INITDB_DATABASE=xbrowsersync"
|
||||||
- "MONGO_INITDB_ROOT_PASSWORD=$XBS_DB_PASSWORD"
|
- "MONGO_INITDB_ROOT_PASSWORD=$XBS_DB_PASSWORD"
|
||||||
- "MONGO_INITDB_ROOT_USERNAME=$XBS_DB_USERNAME"
|
- "MONGO_INITDB_ROOT_USERNAME=$XBS_DB_USERNAME"
|
||||||
image: "mongo:4.2.6"
|
image: "mongo:4.4.4"
|
||||||
labels:
|
restart: "unless-stopped"
|
||||||
- "traefik.enable=false"
|
|
||||||
networks:
|
|
||||||
- "xbs-net"
|
|
||||||
restart: "always"
|
|
||||||
volumes:
|
volumes:
|
||||||
- "xbs-db-data:/data/db"
|
- "xbs-db-data:/data/db"
|
||||||
- "./mongoconfig.js:/docker-entrypoint-initdb.d/mongoconfig.js"
|
- "./mongoconfig.js:/docker-entrypoint-initdb.d/mongoconfig.js"
|
||||||
|
@ -26,33 +19,32 @@ services:
|
||||||
environment:
|
environment:
|
||||||
- "XBROWSERSYNC_DB_PWD=$XBS_DB_PASSWORD"
|
- "XBROWSERSYNC_DB_PWD=$XBS_DB_PASSWORD"
|
||||||
- "XBROWSERSYNC_DB_USER=$XBS_DB_USERNAME"
|
- "XBROWSERSYNC_DB_USER=$XBS_DB_USERNAME"
|
||||||
image: "xbrowsersync/api:1.1.12"
|
healthcheck:
|
||||||
labels:
|
test: [ "CMD", "node", "/usr/src/api/healthcheck.js" ]
|
||||||
- "traefik.frontend.rule=Host:$XBS_API_HOSTNAME"
|
interval: "1m"
|
||||||
- "traefik.port=8080"
|
timeout: "10s"
|
||||||
networks:
|
retries: "5"
|
||||||
- "xbs-net"
|
start_period: "30s"
|
||||||
restart: "always"
|
image: "xbrowsersync/api:1.1.13"
|
||||||
|
restart: "unless-stopped"
|
||||||
volumes:
|
volumes:
|
||||||
- "./settings.json:/usr/src/api/config/settings.json"
|
- "./settings.json:/usr/src/api/config/settings.json"
|
||||||
|
- "./healthcheck.js:/usr/src/api/healthcheck.js"
|
||||||
reverse-proxy:
|
reverse-proxy:
|
||||||
command: "--api --docker"
|
command: "caddy reverse-proxy --from $XBS_API_HOSTNAME --to api:8080"
|
||||||
container_name: "xbs-reverse-proxy"
|
container_name: "xbs-reverse-proxy"
|
||||||
depends_on:
|
depends_on:
|
||||||
- "api"
|
- "api"
|
||||||
image: "traefik:1.7.24-alpine"
|
image: "caddy:2.3.0-alpine"
|
||||||
labels:
|
|
||||||
- "traefik.enable=false"
|
|
||||||
networks:
|
|
||||||
- "xbs-net"
|
|
||||||
ports:
|
ports:
|
||||||
- "443:443"
|
- "443:443"
|
||||||
- "80:80"
|
- "80:80"
|
||||||
restart: "always"
|
restart: "unless-stopped"
|
||||||
volumes:
|
volumes:
|
||||||
- "/var/run/docker.sock:/var/run/docker.sock"
|
- "xbs-caddy-config:/config"
|
||||||
- "./acme.json:/acme.json"
|
- "xbs-caddy-data:/data"
|
||||||
- "./traefik.toml:/traefik.toml"
|
|
||||||
|
|
||||||
networks:
|
volumes:
|
||||||
xbs-net:
|
xbs-caddy-config:
|
||||||
|
xbs-caddy-data:
|
||||||
|
xbs-db-data:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
FROM node:12.16.2-alpine
|
FROM node:14.16.0-alpine
|
||||||
|
|
||||||
# Set environment variables
|
# Set environment variables
|
||||||
ENV XBROWSERSYNC_API_VERSION 1.1.12
|
ENV XBROWSERSYNC_API_VERSION 1.1.13
|
||||||
|
|
||||||
WORKDIR /usr/src/api
|
WORKDIR /usr/src/api
|
||||||
|
|
||||||
|
|
44
healthcheck.js
Normal file
44
healthcheck.js
Normal file
|
@ -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();
|
23
traefik.toml
23
traefik.toml
|
@ -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"
|
|
Loading…
Reference in a new issue