Gravitee.io docker-compose运行

时间:2021-05-06 20:02:55

Gravitee.io 是一个相对比较完整的api gateway 平台,包含了api 相对比较完整的生命周期管理
同时在访问控制以及日志监控上也做的比较好,是一款可以尝试试用的api gateway 平台

环境准备

  • docker-compose 文件
 
version: '3'
networks:
  default:
services:
  nginx:
    image: nginx:1.15-alpine
    container_name: gio_platform_nginx
    restart: always
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/ssl/gio-selfsigned.crt:/etc/ssl/certs/gio-selfsigned.crt
      - ./nginx/ssl/gio-selfsigned.key:/etc/ssl/private/gio-selfsigned.key
      - ./nginx/ssl/gio.pem:/etc/ssl/certs/gio.pem
    ports:
      - "80:80"
      - "443:443"
    depends_on:
      - apim_gateway
      - apim_portal
      - apim_management
      - am_gateway
      - am_management
      - am_webui
  mongodb:
    image: mongo:3.4
    restart: always
    container_name: gio_platform_mongo
    ports:
      - 27017:27017
    environment:
      - MONGO_INITDB_DATABASE=gravitee
    volumes:
      - ./mongo/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
      - ./data/mongo:/data/db
      - ./logs/mongodb:/var/log/mongodb
  elasticsearch:
    image: elasticsearch:6.4.0
    container_name: gio_platform_elasticsearch
    restart: always
    ports:
      - 9200:9200
    environment:
      - http.host=0.0.0.0
      - transport.host=0.0.0.0
      - xpack.security.enabled=false
      - xpack.monitoring.enabled=false
      - cluster.name=elasticsearch
    ulimits:
      nofile: 65536
    volumes:
      - ./data/elasticsearch:/usr/share/elasticsearch/data
      - ./logs/elasticsearch:/var/log/elasticsearch
  apim_gateway:
    image: graviteeio/gateway:latest
    container_name: gio_platform_apim_gateway
    restart: always
    volumes: 
      - ./logs/apim-gateway:/opt/graviteeio-gateway/logs
    environment:
      - gravitee_management_mongodb_uri=mongodb://mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
      - gravitee_ratelimit_mongodb_uri=mongodb://mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
      - gravitee_reporters_elasticsearch_endpoints_0=http://elasticsearch:9200
    depends_on:
      - mongodb
      - elasticsearch
  apim_portal:
    image: graviteeio/management-ui:latest
    container_name: gio_platform_apim_portal
    restart: always
    environment:
      - MGMT_API_URL=https:\/\/localhost\/apim\/management\/
    depends_on:
      - apim_management
  apim_management:
    image: graviteeio/management-api:latest
    container_name: gio_platform_apim_mgmt_api
    restart: always
    volumes:
      - ./logs/apim-management-api:/opt/graviteeio-management-api/logs
    environment:
      - gravitee_management_mongodb_uri=mongodb://mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
      - gravitee_ratelimit_mongodb_uri=mongodb://mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
      - gravitee_analytics_elasticsearch_endpoints_0=http://elasticsearch:9200
      - gravitee_jwt_cookiepath=/apim/management
      - gravitee_jwt_cookiesecure=true
    depends_on:
      - mongodb
      - elasticsearch
  am_gateway:
    image: graviteeio/am-gateway:2
    container_name: gio_platform_am_gateway
    restart: always
    volumes:
      - ./logs/am-gateway:/opt/graviteeio-am-gateway/logs
    environment:
      - gravitee_management_mongodb_uri=mongodb://mongodb:27017/gravitee-am?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
      - gravitee_oauth2_mongodb_uri=mongodb://mongodb:27017/gravitee-am?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
    depends_on:
      - mongodb
  am_management:
    image: graviteeio/am-management-api:2
    container_name: gio_platform_am_management
    restart: always
    volumes:
      - ./logs/am-management-api:/opt/graviteeio-am-management-api/logs
    environment:
      - gravitee_management_mongodb_uri=mongodb://mongodb:27017/gravitee-am?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
      - gravitee_oauth2_mongodb_uri=mongodb://mongodb:27017/gravitee-am?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
      - gravitee_jwt_cookiepath=/am/management
      - gravitee_jwt_cookiesecure=true
    depends_on:
      - mongodb
  am_webui:
    image: graviteeio/am-management-ui:2
    container_name: gio_platform_am_webui
    restart: always
    environment:
      - MGMT_API_URL=https:\/\/localhost\/am\/
      - MGMT_UI_URL=https:\/\/localhost\/am\/ui\/
    volumes:
      - ./logs/am-webui:/var/log/nginx
    depends_on:
      - am_management
 
 
  • 简单说明
    docker compose 文件包含了api gateway 以及访问管理以及日志的基础组件,访问入口通过nginx,同时官方
    也提供了一个基于trafic 的demo,也挺不错
    nginx.conf 主要是proxy 的配置,同时添加了https 证书的处理(自签名的),nginx 配置文件处理了对于重定向
    的配置,好多配置对于我们来说还是有借鉴意义的。
    因为使用了mongo 所以在初始化数据库的时候进行了一些索引的创建,详细的配置可以参考github

运行

  • 运行
 
docker-compose up -d
 

UI 效果 账户admin admin
Gravitee.io docker-compose运行
访问控制管理UI 账户 admin adminadmin
Gravitee.io docker-compose运行

试用

  • 创建api

Gravitee.io docker-compose运行
中间的一些步骤按照提示操作即可
Gravitee.io docker-compose运行
同时可以需要进行api 的发布以及启动,界面上还是很全的,直接参考提示操作即可
Gravitee.io docker-compose运行

  • 使用api

需要创建app
Gravitee.io docker-compose运行
然后需要创建api 的订阅,我们可以进行审核处理

说明

Gravitee.io 对于api 的管理功能比较全,后边会写一些关于如果使用的简单demo

参考资料

https://docs.gravitee.io/apim_quickstart_publish.html
https://docs.gravitee.io/apim_quickstart_consume.html
https://github.com/gravitee-io/gravitee-docker