概要

  • pub/sub を用いて Config の値のアップデート時に他の App にキャッシュの更新を促す
    • Nchan, Redis の2種をサポートする
    • v4.1.0 向けにはとりあえず Nchan のみ実装を行う

Nchan

https://nchan.io/ external_link

概要

  • nginx のサードパーティーモジュール
  • GROWI は WebSocket で subscribe、HTTP POST で publish する方針

Nchan 専用 nginx イメージのビルド

Why?

  • nginx 公式 docker image external_link は debian ベースだが、debian 公式パッケージを使わず、nginx 独自の apt repos のバイナリをインストールしている
  • そのため、Nchan module は自前ビルドする必要がある

コンパイル参考

Dockerfile の種

NGINX_VERSIONNCHAN_VERSION は ENV で用意する

FROM debian:buster-slim

apt update apt install --no-install-recommends --no-install-suggests -y gnupg1 ca-certificates wget apt install -y dpkg-dev libpcre3-dev zlib1g-dev NGINX_GPGKEY=573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62; \ KEY_SERVER=hkp://keyserver.ubuntu.com:80; \ apt-key adv --keyserver "$KEY_SERVER" --keyserver-options timeout=10 --recv-keys "$NGINX_GPGKEY" echo "deb-src https://nginx.org/packages/mainline/debian/ buster nginx" >> /etc/apt/sources.list.d/nginx.list apt update cd apt source nginx=1.19.1-1~buster wget "https://github.com/slact/nchan/archive/v1.2.7.tar.gz" -O nchan.tar.gz tar zxf nchan.tar.gz export NCHANDIR="$(pwd)/nchan-${NCHAN_VERSION}" cd nginx-$NGINX_VERSION ./configure --with-compat --add-dynamic-module=$NCHANDIR # make modules make -f objs/Makefile objs/ngx_nchan_module.so

FROM nginx:1.19.1

mkdir -p /usr/local/nginx/modules cp /root/nchan-1.2.7/objs/ngx_nchan_module.so /usr/local/nginx/modules/ cd /etc/nginx echo -e "# load Nchan module" > /tmp/nginx.conf echo -e "load_module /usr/local/nginx/modules/ngx_nchan_module.so;" > /tmp/nginx.conf cat nginx.conf >> /tmp/nginx.conf mv nginx.conf nginx.conf.org mv /tmp/nginx.conf nginx.conf

/etc/nginx/conf.d/default.conf

server { listen 80; listen [::]:80; server_name localhost; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # Pub/sub location /pubsub { nchan_pubsub; nchan_channel_id common; } location ~ /pubsub/(\w+) { nchan_pubsub; nchan_channel_id "$1"; } }

Redis

https://redis.io/topics/pubsub external_link

(TBD)