├── .dockerignore ├── Dockerfile ├── LICENSE ├── bin ├── docker-entrypoint └── health-check ├── examples ├── laravel-echo-server.json ├── redis.yml └── sqlite.yml └── src ├── healthcheck.js └── laravel-echo-server.json /.dockerignore: -------------------------------------------------------------------------------- 1 | # Other files # 2 | ################ 3 | examples 4 | 5 | # User specific & automatically generated files # 6 | ################################################# 7 | *.log 8 | *.md 9 | .travis.yml 10 | .github 11 | README.md 12 | CHANGELOG.md 13 | 14 | # IDE and editor specific files # 15 | ################################# 16 | nbproject 17 | .idea 18 | .vscode 19 | .editorconfig 20 | 21 | # OS generated files # 22 | ###################### 23 | .DS_Store 24 | .DS_Store? 25 | ._* 26 | .Spotlight-V100 27 | .Trashes 28 | Icon? 29 | ehthumbs.db 30 | Thumbs.db 31 | 32 | # Git config # 33 | ############## 34 | .git 35 | .gitignore 36 | .gitattributes 37 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:lts-alpine 2 | 3 | WORKDIR /app 4 | 5 | ### Install Laravel Echo Server and dependencies 6 | RUN set -eux; \ 7 | apk add --update --no-cache \ 8 | sqlite \ 9 | openssl \ 10 | ; \ 11 | apk add --update --no-cache --virtual .build-deps \ 12 | build-base \ 13 | ; \ 14 | yarn global add --prod --no-lockfile laravel-echo-server ; \ 15 | apk del .build-deps ; \ 16 | yarn cache clean ; \ 17 | mkdir -p /app/database ; \ 18 | rm /usr/local/bin/docker-entrypoint.sh 19 | 20 | COPY bin/* /usr/local/bin/ 21 | COPY src/* /usr/local/src/ 22 | 23 | VOLUME /app 24 | EXPOSE 6001 25 | 26 | ENTRYPOINT ["docker-entrypoint"] 27 | CMD ["start"] 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Oanh Nguyen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /bin/docker-entrypoint: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | # laravel-echo-server init 5 | if [[ "$1" == 'init' ]]; then 6 | set -- laravel-echo-server "$@" 7 | fi 8 | 9 | if [ "$1" == 'start' ] && [ -f '/app/laravel-echo-server.lock' ]; then 10 | rm /app/laravel-echo-server.lock 11 | fi 12 | 13 | # laravel-echo-server 14 | if [[ "$1" == 'start' ]] || [[ "$1" == 'client:add' ]] || [[ "$1" == 'client:remove' ]]; then 15 | if [[ "${LARAVEL_ECHO_SERVER_GENERATE_CONFIG:-true}" == "false" ]]; then 16 | # wait for another process to inject the config 17 | echo -n "Waiting for /app/laravel-echo-server.json" 18 | while [[ ! -f /app/laravel-echo-server.json ]]; do 19 | sleep 2 20 | echo -n "." 21 | done 22 | elif [[ ! -f /app/laravel-echo-server.json ]]; then 23 | cp /usr/local/src/laravel-echo-server.json /app/laravel-echo-server.json 24 | # Replace with environment variables 25 | sed -i "s|LARAVEL_ECHO_AUTH_HOST|${LARAVEL_ECHO_AUTH_HOST:-${LARAVEL_ECHO_SERVER_HOST:-localhost}}|i" /app/laravel-echo-server.json 26 | sed -i "s|LARAVEL_ECHO_ALLOW_ORIGIN|${LARAVEL_ECHO_ALLOW_ORIGIN:-${LARAVEL_ECHO_AUTH_HOST:-${LARAVEL_ECHO_SERVER_HOST:-localhost}}}|i" /app/laravel-echo-server.json 27 | LARAVEL_ECHO_CLIENTS="[]" 28 | if [ ! -z "${LARAVEL_ECHO_CLIENT_APP_ID}" ]; then 29 | LARAVEL_ECHO_CLIENTS="[{\"appId\": \"${LARAVEL_ECHO_CLIENT_APP_ID}\",\"key\": \"${LARAVEL_ECHO_CLIENT_APP_KEY}\"}]" 30 | fi 31 | sed -i "s|\"LARAVEL_ECHO_CLIENTS\"|${LARAVEL_ECHO_CLIENTS}|i" /app/laravel-echo-server.json 32 | sed -i "s|LARAVEL_ECHO_SERVER_DB|${LARAVEL_ECHO_SERVER_DB:-redis}|i" /app/laravel-echo-server.json 33 | sed -i "s|REDIS_HOST|${REDIS_HOST:-redis}|i" /app/laravel-echo-server.json 34 | sed -i "s|REDIS_PORT|${REDIS_PORT:-6379}|i" /app/laravel-echo-server.json 35 | sed -i "s|REDIS_PASSWORD|${REDIS_PASSWORD}|i" /app/laravel-echo-server.json 36 | sed -i "s|REDIS_PREFIX|${REDIS_PREFIX-laravel_database_}|i" /app/laravel-echo-server.json 37 | sed -i "s|REDIS_DB|${REDIS_DB:-0}|i" /app/laravel-echo-server.json 38 | # Remove password config if it is empty 39 | sed -i "s|\"password\": \"\",||i" /app/laravel-echo-server.json 40 | fi 41 | set -- laravel-echo-server "$@" 42 | fi 43 | 44 | # first arg is `-f` or `--some-option` 45 | if [[ "${1#-}" != "$1" ]]; then 46 | set -- laravel-echo-server "$@" 47 | fi 48 | 49 | exec "$@" 50 | -------------------------------------------------------------------------------- /bin/health-check: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | node /usr/local/src/healthcheck.js 3 | -------------------------------------------------------------------------------- /examples/laravel-echo-server.json: -------------------------------------------------------------------------------- 1 | { 2 | "apiOriginAllow": {}, 3 | "authEndpoint": "/broadcasting/auth", 4 | "authHost": "http://localhost", 5 | "clients": [], 6 | "database": "sqlite", 7 | "databaseConfig": { 8 | "sqlite": { 9 | "databasePath": "/database/laravel-echo-server.sqlite" 10 | }, 11 | "publishPresence": true 12 | }, 13 | "devMode": false, 14 | "host": null, 15 | "port": 6001, 16 | "protocol": "http", 17 | "sslCertPath": "", 18 | "sslKeyPath": "", 19 | "sslCertChainPath": "", 20 | "sslPassphrase": "", 21 | "socketio": { 22 | "path": "/example.io" 23 | }, 24 | "subscribers": {"http": true} 25 | } 26 | -------------------------------------------------------------------------------- /examples/redis.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | networks: 4 | redis-net: {} 5 | 6 | volumes: 7 | redis-vol: {} 8 | 9 | services: 10 | redis: 11 | image: redis:alpine 12 | networks: 13 | - redis-net 14 | restart: unless-stopped 15 | volumes: 16 | - redis-vol:/data 17 | healthcheck: 18 | test: redis-cli -h redis -p 6379 ping 19 | start_period: 3s 20 | interval: 2s 21 | timeout: 2s 22 | retries: 10 23 | 24 | laravel-echo-server: 25 | image: oanhnn/laravel-echo-server:latest 26 | depends_on: 27 | - redis 28 | environment: 29 | LARAVEL_ECHO_SERVER_AUTH_HOST: http://example.com 30 | LARAVEL_ECHO_SERVER_DEBUG: 'true' 31 | LARAVEL_ECHO_SERVER_DB: redis 32 | REDIS_HOST: redis 33 | REDIS_PORT: 6379 34 | REDIS_PREFIX: "" 35 | REDIS_DB: 0 36 | networks: 37 | - redis-net 38 | ports: 39 | - 6001:6001 40 | restart: unless-stopped 41 | healthcheck: 42 | test: node /usr/local/src/healthcheck.js 43 | start_period: 5s 44 | interval: 3s 45 | timeout: 3s 46 | retries: 10 47 | -------------------------------------------------------------------------------- /examples/sqlite.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | volumes: 4 | sqlite-vol: {} 5 | 6 | services: 7 | laravel-echo-server: 8 | image: oanhnn/laravel-echo-server:latest 9 | # environment: 10 | # LARAVEL_ECHO_SERVER_AUTH_HOST: http://example.com 11 | # LARAVEL_ECHO_SERVER_DEBUG: 'true' 12 | # LARAVEL_ECHO_SERVER_DATABASE: sqlite 13 | ports: 14 | - 6001:6001 15 | restart: unless-stopped 16 | volumes: 17 | - sqlite-vol:/database 18 | - ./laravel-echo-server.json:/app/laravel-echo-server.json:ro 19 | healthcheck: 20 | # test: node /usr/local/src/healthcheck.js 21 | test: /usr/local/bin/health-check 22 | start_period: 5s 23 | interval: 3s 24 | timeout: 3s 25 | retries: 10 26 | -------------------------------------------------------------------------------- /src/healthcheck.js: -------------------------------------------------------------------------------- 1 | // See https://blog.sixeyed.com/docker-healthchecks-why-not-to-use-curl-or-iwr/ 2 | 3 | var http = require("http"); 4 | var config = {}; 5 | 6 | try { 7 | config = require("/app/laravel-echo-server.json"); 8 | } catch (error) { 9 | } 10 | 11 | var options = { 12 | host : "localhost", 13 | port : config.port | 6001, 14 | path : `${config.socketio && config.socketio.path ? config.socketio.path : '/socket.io'}/socket.io.js`, 15 | timeout : 2000 16 | }; 17 | 18 | var request = http.request(options, (res) => { 19 | console.log(`STATUS: ${res.statusCode}`); 20 | if (res.statusCode == 200) { 21 | process.exit(0); 22 | } else { 23 | process.exit(1); 24 | } 25 | }); 26 | 27 | request.on('error', function(err) { 28 | console.log('ERROR'); 29 | process.exit(1); 30 | }); 31 | 32 | request.end(); 33 | -------------------------------------------------------------------------------- /src/laravel-echo-server.json: -------------------------------------------------------------------------------- 1 | { 2 | "apiOriginAllow":{ 3 | "allowCors" : true, 4 | "allowOrigin" : "LARAVEL_ECHO_ALLOW_ORIGIN", 5 | "allowMethods" : "GET, POST", 6 | "allowHeaders" : "Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id" 7 | }, 8 | "authEndpoint": "/broadcasting/auth", 9 | "authHost": "LARAVEL_ECHO_AUTH_HOST", 10 | "clients": "LARAVEL_ECHO_CLIENTS", 11 | "database": "LARAVEL_ECHO_SERVER_DB", 12 | "databaseConfig": { 13 | "redis": { 14 | "host": "REDIS_HOST", 15 | "port": "REDIS_PORT", 16 | "password": "REDIS_PASSWORD", 17 | "keyPrefix": "REDIS_PREFIX", 18 | "options": { 19 | "db": "REDIS_DB" 20 | } 21 | }, 22 | "sqlite": { 23 | "databasePath": "/database/laravel-echo-server.sqlite" 24 | }, 25 | "publishPresence": true 26 | }, 27 | "devMode": false, 28 | "host": null, 29 | "port": 6001, 30 | "protocol": "http", 31 | "sslCertPath": "", 32 | "sslKeyPath": "", 33 | "sslCertChainPath": "", 34 | "sslPassphrase": "", 35 | "socketio": {}, 36 | "subscribers": {"http": true, "redis": true} 37 | } 38 | --------------------------------------------------------------------------------