openresty docker 镜像集成gor


openresty 是一个很不错的nginx 增强版本,以下是openresty 集成gor 的尝试

问题

很多时候我们会基于nginx(openresty) 进行接口的代理,但是我们需要获取请求信息,同时进行回放

解决

gor 是一个很不错的工具,但是我们希望能够进行控制(按需数据捕捉)所以我使用了supervisord进行
管理,而且我们使用的容器部署,使用supervisord是一个不错的选择(我没有使用python版本的,而是使用
了golang版本的)

参考配置

  • Dockerfile
 
FROM openresty/openresty:alpine
ENV PATH=$PATH:/app
COPY --from=dalongrong/gor /app/gor /app/gor
COPY --from=ochinchina/supervisord:latest /usr/local/bin/supervisord /usr/local/bin/supervisord
EXPOSE 9001 8080 80
COPY supervisor.conf /etc/supervisor.conf
CMD ["/usr/local/bin/supervisord"]
  • supervisor.conf 配置
    集成gor 以及supervisord 的管理还有openresty 的启动,gor 部分比较简单,自己可以按需扩展
 
[program:website]
command = /usr/local/openresty/bin/openresty
[inet_http_server]
port = :9001
[program:gor]
command = gor --input-raw :80 --output-file=/app/capture/requests.gor

使用

基于docker-compose 搞的一个环境

  • docker-compose 文件
    注意容器需要使用cap 能力,为了简单我添加了ALL
 
version: "3"
services: 
  minio: 
    image: minio/minio
    command: server /data
    volumes: 
    - "./data:/data"
    ports: 
    - "9000:9000"
    environment:
      - "MINIO_ACCESS_KEY=minio"
      - "MINIO_SECRET_KEY=minio123"
  api:
    image: dalongrong/openresty-gor
    build: 
      dockerfile: ./Dockerfile-openresty
      context: ./
    privileged: true
    cap_add: 
    - ALL
    volumes:
    - "./supervisor.conf:/etc/supervisord.conf"
    - "./nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf"
    - "./demoapps:/opt/demoapps"
    - "./capture:/app/capture"
    ports:
    - "80:80"
    - "8080:8080"
    - "9001:9001"
  • 启动
docker-compose up -d
  • 效果

 

 

说明

以上是一个简单的集成,实际上我们可以集成minio的,这样就可以灵活的进行数据回放了,如果感觉supervisord的控制不是很灵活,我们可以
基于jpillora/webproc 进行包装,或者自己编写已给rest api 方便控制,个人感觉supervisord 的admin 控制基本够用了

参考资料

https://github.com/buger/goreplay
https://github.com/rongfengliang/openresty_rewrite_static/tree/minio


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM