Skip to content

Commit

Permalink
feat: init gateway controller (#133)
Browse files Browse the repository at this point in the history
* feat: init gateway controller

* fix: add full path

* feat: add oss bucket route

* feat: add route type
  • Loading branch information
skyoct authored Jun 15, 2022
1 parent 672f70b commit b7ca2f7
Show file tree
Hide file tree
Showing 26 changed files with 4,996 additions and 11 deletions.
11 changes: 7 additions & 4 deletions deploy/docker-compose/.env
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ APP_SERVICE_DEPLOY_URL_SCHEMA=http

# `*.127-0-0-1.nip.io` always resolved to 127.0.0.1, just for local development
# Replace it with your own domain which should be resolved(*.domain.com) to your server ip
DEPLOY_DOMAIN=127-0-0-1.nip.io
SYS_CLIENT_HOST=console.127-0-0-1.nip.io
OSS_DOMAIN=oss.127-0-0-1.nip.io
DEPLOY_DOMAIN=local
SYS_CLIENT_HOST=console.local
OSS_DOMAIN=oss.local

APP_SERVICE_IMAGE=lafyun/app-service:latest
SYSTEM_EXTENSION_APPID='000000'
SYSTEM_EXTENSION_APPID='000000'

# gateway config
API_SIX_KEY=edd1c9f034335f136f87ad84b625c8f1
26 changes: 26 additions & 0 deletions deploy/docker-compose/apisix_conf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apisix:
node_listen: 9080 # APISIX listening port
enable_ipv6: false

allow_admin: # http://nginx.org/en/docs/http/ngx_http_access_module.html#allow
- 0.0.0.0/0 # We need to restrict ip access rules for security. 0.0.0.0/0 is for test.

admin_key:
- name: "admin"
key: edd1c9f034335f136f87ad84b625c8f1
role: admin # admin: manage all configuration data
# viewer: only can view configuration data
- name: "viewer"
key: 4054f7cf07e344346cd3f287985e76a2
role: viewer

enable_control: true
control:
ip: "0.0.0.0"
port: 9092

etcd:
host: # it's possible to define multiple etcd hosts addresses of the same etcd cluster.
- "http://etcd:2379" # multiple etcd address
prefix: "/apisix" # apisix configurations prefix
timeout: 30 # 30 seconds
104 changes: 104 additions & 0 deletions deploy/docker-compose/dashboard_conf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

conf:
listen:
host: 0.0.0.0 # `manager api` listening ip or host name
port: 9000 # `manager api` listening port
allow_list: # If we don't set any IP list, then any IP access is allowed by default.
- 0.0.0.0/0
etcd:
endpoints: # supports defining multiple etcd host addresses for an etcd cluster
- "http://etcd:2379"
# yamllint disable rule:comments-indentation
# etcd basic auth info
# username: "root" # ignore etcd username if not enable etcd auth
# password: "123456" # ignore etcd password if not enable etcd auth
mtls:
key_file: "" # Path of your self-signed client side key
cert_file: "" # Path of your self-signed client side cert
ca_file: "" # Path of your self-signed ca cert, the CA is used to sign callers' certificates
# prefix: /apisix # apisix config's prefix in etcd, /apisix by default
log:
error_log:
level: warn # supports levels, lower to higher: debug, info, warn, error, panic, fatal
file_path:
logs/error.log # supports relative path, absolute path, standard output
# such as: logs/error.log, /tmp/logs/error.log, /dev/stdout, /dev/stderr
access_log:
file_path:
logs/access.log # supports relative path, absolute path, standard output
# such as: logs/access.log, /tmp/logs/access.log, /dev/stdout, /dev/stderr
# log example: 2020-12-09T16:38:09.039+0800 INFO filter/logging.go:46 /apisix/admin/routes/r1 {"status": 401, "host": "127.0.0.1:9000", "query": "asdfsafd=adf&a=a", "requestId": "3d50ecb8-758c-46d1-af5b-cd9d1c820156", "latency": 0, "remoteIP": "127.0.0.1", "method": "PUT", "errs": []}
authentication:
secret:
secret # secret for jwt token generation.
# NOTE: Highly recommended to modify this value to protect `manager api`.
# if it's default value, when `manager api` start, it will generate a random string to replace it.
expire_time: 3600 # jwt token expire time, in second
users: # yamllint enable rule:comments-indentation
- username: admin # username and password for login `manager api`
password: admin
- username: user
password: user

plugins: # plugin list (sorted in alphabetical order)
- api-breaker
- authz-keycloak
- basic-auth
- batch-requests
- consumer-restriction
- cors
# - dubbo-proxy
- echo
# - error-log-logger
# - example-plugin
- fault-injection
- grpc-transcode
- hmac-auth
- http-logger
- ip-restriction
- jwt-auth
- kafka-logger
- key-auth
- limit-conn
- limit-count
- limit-req
# - log-rotate
# - node-status
- openid-connect
- prometheus
- proxy-cache
- proxy-mirror
- proxy-rewrite
- redirect
- referer-restriction
- request-id
- request-validation
- response-rewrite
- serverless-post-function
- serverless-pre-function
# - skywalking
- sls-logger
- syslog
- tcp-logger
- udp-logger
- uri-blocker
- wolf-rbac
- zipkin
- server-info
- traffic-split
37 changes: 33 additions & 4 deletions deploy/docker-compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ services:
- laf_shared_network

system-server:
image: lafyun/system-server:0.8.0
image: system-server
user: root
working_dir: /app
environment:
Expand Down Expand Up @@ -87,18 +87,47 @@ services:
- laf_shared_network

gateway:
image: lafyun/gateway:0.8.0-alpha.3
image: apache/apisix:2.14.1-alpine
depends_on:
- system-server
- mongo
- etcd
environment:
DEPLOY_DOMAIN: "*.${DEPLOY_DOMAIN:?err}"
DEPLOY_OSS_DOMAIN: ${OSS_DOMAIN}
SYS_CLIENT_HOST: ${SYS_CLIENT_HOST:?err}
SYSTEM_EXTENSION_APPID: ${SYSTEM_EXTENSION_APPID}
command: "sh /scripts/start.sh"
volumes:
- ./apisix_conf.yaml:/usr/local/apisix/conf/config.yaml:ro
ports:
- ${PUBLISH_PORT:-8080}:9080
networks:
- laf_shared_network

gateway-controller:
image: gateway-controller
depends_on:
- gateway
environment:
DEPLOY_DOMAIN: "${DEPLOY_DOMAIN:?err}"
DEPLOY_OSS_DOMAIN: ${OSS_DOMAIN}
SYS_CLIENT_HOST: ${SYS_CLIENT_HOST:?err}
SYSTEM_EXTENSION_APPID: ${SYSTEM_EXTENSION_APPID}
LOG_LEVEL: debug
SERVICE_DRIVER: docker
GATEWAY_TYPE: apisix
SYS_DB_URI: mongodb://${SYS_DB_USER}:${SYS_DB_PASSWORD}@mongo:27017/?authSource=${SYS_DB}&replicaSet=laf&writeConcern=majority
API_SIX_KEY: ${API_SIX_KEY}
networks:
- laf_shared_network

apisix-dashboard:
image: apache/apisix-dashboard:2.13-alpine
restart: always
volumes:
- ./dashboard_conf.yaml:/usr/local/apisix-dashboard/conf/conf.yaml
ports:
- ${PUBLISH_PORT:-8080}:80
- "9000:9000"
networks:
- laf_shared_network

Expand Down
7 changes: 7 additions & 0 deletions packages/gateway-controller/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# node_modules
.env
ecosystem.config.js
# dist
data
src
tests
12 changes: 12 additions & 0 deletions packages/gateway-controller/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
node_modules
dist

upload
data/*
tmp

.env
.env.local

ecosystem.config.js
.DS_Store
11 changes: 11 additions & 0 deletions packages/gateway-controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:16-alpine


EXPOSE 9001
WORKDIR /app
ENV LOG_LEVEL=debug
COPY . /app
# RUN npm i
# RUN npm run build
USER node
CMD [ "npm", "run", "start" ]
70 changes: 70 additions & 0 deletions packages/gateway-controller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@


# laf service controller


### Application instance status
```ts
export enum ApplicationInstanceStatus {
CREATED = 'created',
PREPARED_START = 'prepared_start',
STARTING = 'starting',
RUNNING = 'running',
PREPARED_STOP = 'prepared_stop',
STOPPING = 'stopping',
STOPPED = 'stopped',
PREPARED_RESTART = 'prepared_restart',
RESTARTING = 'restarting'
}

```

### instance status machine

`created`: nop

`prepared_start`:
-> loop apps in `prepared_start`
-> start app instance for each
-> update app status to `starting`

`starting`:
-> loop apps in `starting`
-> get instance status for each app
-> update running app status to `running`

`running`: nop

`prepared_stop`:
-> loop apps in `prepared_stop`
-> stop app instance for each
-> update app status to `stopping`

`stopping`:
-> loop apps in `stopping`
-> get instance status for each app
-> update stopped app status to `stopped`

`stopped`: nop

`prepared_restart`:
-> loop apps in `prepared_restart`
-> stop app instance for each
-> update app status to `restarting`

`restarting`:
-> loop apps in `restarting`
-> get instance status for each app
-> start stopped app & update app status to `starting`


### scheduler logic design

- set a timer to execute schedular loop
- call each handlers in loop:
- `prepared_start` handler
- `starting` handler
- `prepared_stop` handler
- `stopping` handler
- `prepared_restart` handler
- `restarting` handler
Loading

0 comments on commit b7ca2f7

Please sign in to comment.