diff --git a/.gitignore b/.gitignore index be66674e72..e6d138c75c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,8 @@ ecosystem.config.js .idea coverage -.nyc_output \ No newline at end of file +.nyc_output + +kubernetes-dev/mongo-data + +kubernetes-local/ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 175380e558..e235b5c8ca 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -77,6 +77,7 @@ "Kubernetes", "lafjs", "lafyun", + "millicores", "objs", "signin", "uids", diff --git a/CHANGELOG.md b/CHANGELOG.md index b1adfd8e4f..4c759ab8a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,22 @@ -# [](https://github.com/lafjs/laf/compare/v0.7.2...v) (2022-01-21) +# [](https://github.com/lafjs/laf/compare/v0.7.4...v) (2022-01-21) + + + +## [0.7.4](https://github.com/lafjs/laf/compare/v0.7.3...v0.7.4) (2022-01-21) + + +### Bug Fixes + +* **gateway:** fix conf path not created error ([97d2693](https://github.com/lafjs/laf/commit/97d2693eec1451d39a509131267cd327728466f3)) + + + +## [0.7.3](https://github.com/lafjs/laf/compare/v0.7.2...v0.7.3) (2022-01-21) + + +### Bug Fixes + +* **storage-service:** add content-length for download api; ([6601885](https://github.com/lafjs/laf/commit/6601885eede5bea930357f0142c6326c25217fc3)) diff --git a/README.md b/README.md index 2c513a2447..7f6628d03d 100644 --- a/README.md +++ b/README.md @@ -51,28 +51,28 @@ ## 运行截图 应用列表 -![](https://9b069020-06e3-4949-83d9-992a52ca99fe.lafyun.com/file/laf_preview_screens/apps.png) +![](https://9b069020-06e3-4949-83d9-992a52ca99fe_laf_preview_screens.fs.lafyun.com/apps.png) 云函数列表 -![](https://9b069020-06e3-4949-83d9-992a52ca99fe.lafyun.com/file/laf_preview_screens/functions.png) +![](https://9b069020-06e3-4949-83d9-992a52ca99fe_laf_preview_screens.fs.lafyun.com/functions.png) 在线开发云函数 -![](https://9b069020-06e3-4949-83d9-992a52ca99fe.lafyun.com/file/laf_preview_screens/ide.png) +![](https://9b069020-06e3-4949-83d9-992a52ca99fe_laf_preview_screens.fs.lafyun.com/ide.png) 云存储:文件管理 -![](https://9b069020-06e3-4949-83d9-992a52ca99fe.lafyun.com/file/laf_preview_screens/files.png) +![](https://9b069020-06e3-4949-83d9-992a52ca99fe_laf_preview_screens.fs.lafyun.com/files.png) 云数据库:数据管理 -![](https://9b069020-06e3-4949-83d9-992a52ca99fe.lafyun.com/file/laf_preview_screens/collection.png) +![](https://9b069020-06e3-4949-83d9-992a52ca99fe_laf_preview_screens.fs.lafyun.com/collection.png) 云数据库:访问策略 -![](https://9b069020-06e3-4949-83d9-992a52ca99fe.lafyun.com/file/laf_preview_screens/policy.png) +![](https://9b069020-06e3-4949-83d9-992a52ca99fe_laf_preview_screens.fs.lafyun.com/policy.png) 远程部署 -![](https://9b069020-06e3-4949-83d9-992a52ca99fe.lafyun.com/file/laf_preview_screens/deploy.png) +![](https://9b069020-06e3-4949-83d9-992a52ca99fe_laf_preview_screens.fs.lafyun.com/deploy.png) 协作成员 -![](https://9b069020-06e3-4949-83d9-992a52ca99fe.lafyun.com/file/laf_preview_screens/member.png) +![](https://9b069020-06e3-4949-83d9-992a52ca99fe_laf_preview_screens.fs.lafyun.com/member.png) ## 使用说明 diff --git a/deploy/kubernetes/0-namespace.yml b/deploy/kubernetes/0-namespace.yml index af8d55c64c..f22928b608 100644 --- a/deploy/kubernetes/0-namespace.yml +++ b/deploy/kubernetes/0-namespace.yml @@ -2,10 +2,18 @@ apiVersion: v1 kind: Namespace metadata: - name: mongodb + name: laf --- -apiVersion: v1 -kind: Namespace +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding metadata: - name: laf + name: clusterrolebinding +subjects: + - kind: Group + name: system:serviceaccounts + apiGroup: rbac.authorization.k8s.io +roleRef: + kind: ClusterRole + name: cluster-admin + apiGroup: rbac.authorization.k8s.io diff --git a/deploy/kubernetes/README.md b/deploy/kubernetes/README.md new file mode 100644 index 0000000000..a8e0d3bcba --- /dev/null +++ b/deploy/kubernetes/README.md @@ -0,0 +1,13 @@ + +## Run laf on kubernetes cluster + +> Mongodb is NOT provided, your should config a mongodb server for it before run laf cluster. + +> Edit `config.yml` to config your laf cluster first. + + +```sh +# run it +kubectl apply -f . + +``` \ No newline at end of file diff --git a/deploy/kubernetes/config.yml b/deploy/kubernetes/config.yml new file mode 100644 index 0000000000..a4efa504d5 --- /dev/null +++ b/deploy/kubernetes/config.yml @@ -0,0 +1,65 @@ +### Databases configuration +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: db-config + namespace: laf +data: + sys-db-uri: "mongodb://my_user:password123@mongo.laf:27017/sys_db?authSource=sys_db&replicaSet=laf&writeConcern=majority" + app-db-uri: "mongodb://root:password123@mongo.laf:27017/?authSource=admin&replicaSet=laf&writeConcern=majority&maxPoolSize=10" + fs-db-uri: "mongodb://root:password123@mongo.laf:27017/fs_db?authSource=admin&replicaSet=laf&writeConcern=majority" + +### Root account for system extension app +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: root-account + namespace: laf +data: + account: "root" + password: "abc123" + +### Server secrets used for signature tokens +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: secret-salt + namespace: laf +data: + system-server-salt: "Rewrite_Your_Own_Secret_Salt_abcdefg1234567" + fs-server-salt: "Rewrite_Your_Own_Secret_Salt_abcdefg1234567" + +### Deployment domains for gateway & clients +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: deploy-domain + namespace: laf +data: + app-service-host: "local-dev.host:30000" # `*.local-dev.host` always resolved to 127.0.0.1, used to local development + fs-service-host: "fs.local-dev.host:30000" # `*.local-dev.host` always resolved to 127.0.0.1, used to local development + deploy-url-schema: "http" + app-service-domain: "*.local-dev.host" + fs-service-domain: "*.fs.local-dev.host" + system-console-domain: "console.local-dev.host" + docs-domain: "docs.local-dev.host" + +### App service config & default quotas +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: app-service + namespace: laf +data: + image: "docker.io/lafyun/app-service:0.7.2" + default-request-memory: "128" + default-request-cpu: "100" + default-limit-memory: "256" + default-limit-cpu: "500" + default-app-quota-created-per-user: "5" + kube-namespace-of-app-services: 'laf' diff --git a/deploy/kubernetes/deploy.fs.yml b/deploy/kubernetes/deploy.fs.yml deleted file mode 100644 index ead4ad574b..0000000000 --- a/deploy/kubernetes/deploy.fs.yml +++ /dev/null @@ -1,58 +0,0 @@ ---- -kind: Service -apiVersion: v1 -metadata: - name: storage-service - namespace: laf -spec: - selector: - app: storage-service - type: ClusterIP - ports: - - port: 9010 - targetPort: 9010 - ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: storage-service - namespace: laf - labels: - app: storage-service -spec: - replicas: 1 - selector: - matchLabels: - app: storage-service - strategy: - rollingUpdate: - maxSurge: 1 - maxUnavailable: 1 - type: RollingUpdate - template: - metadata: - labels: - app: storage-service - spec: - automountServiceAccountToken: false - containers: - - image: lafyun/storage-service:0.7.0 - name: storage-service - resources: - # requests: - # memory: "128Mi" - # cpu: "500m" - limits: - memory: "1024Mi" - cpu: "1000m" - env: - - name: DB_URI - value: mongodb://root:password123@prod.mongodb:27017/laf-fs?authSource=admin&replicaSet=laf&writeConcern=majority - - name: LOG_LEVEL - value: debug - - name: SYS_SERVER_SECRET_SALT - value: Rewrite_Your_Own_Secret_Salt_abcdefg1234567 - ports: - - containerPort: 9010 - restartPolicy: Always diff --git a/deploy/kubernetes/deploy.gateway.yml b/deploy/kubernetes/deploy.gateway.yml deleted file mode 100644 index 93f2910cc3..0000000000 --- a/deploy/kubernetes/deploy.gateway.yml +++ /dev/null @@ -1,63 +0,0 @@ ---- -kind: Service -apiVersion: v1 -metadata: - name: gateway - namespace: laf -spec: - selector: - app: gateway - type: NodePort - ports: - - port: 80 - targetPort: 80 - nodePort: 30000 - ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: gateway - namespace: laf - labels: - app: gateway -spec: - replicas: 1 - selector: - matchLabels: - app: gateway - strategy: - rollingUpdate: - maxSurge: 1 - maxUnavailable: 1 - type: RollingUpdate - template: - metadata: - labels: - app: gateway - spec: - automountServiceAccountToken: false - containers: - - image: lafyun/gateway:0.7.1 - name: gateway - resources: - # requests: - # memory: "128Mi" - # cpu: "1000m" - limits: - memory: "1024Mi" - cpu: "1000m" - env: - - name: DEPLOY_DOMAIN - value: "*.local-dev.host" - - name: DEPLOY_FS_DOMAIN - value: "*.fs.local-dev.host" - - name: SYS_CLIENT_HOST - value: console.local-dev.host - - name: DOCS_HOST - value: docs.local-dev.host - - name: SERVICE_DRIVER - value: kubernetes - ports: - - containerPort: 80 - restartPolicy: Always \ No newline at end of file diff --git a/deploy/kubernetes/deploy.sys.yml b/deploy/kubernetes/deploy.sys.yml deleted file mode 100644 index 96daddb95e..0000000000 --- a/deploy/kubernetes/deploy.sys.yml +++ /dev/null @@ -1,85 +0,0 @@ ---- -kind: Service -apiVersion: v1 -metadata: - name: system-server - namespace: laf -spec: - selector: - app: system-server - type: ClusterIP - ports: - - port: 9000 - targetPort: 9000 - ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: system-server - namespace: laf - labels: - app: system-server -spec: - replicas: 1 - selector: - matchLabels: - app: system-server - strategy: - rollingUpdate: - maxSurge: 1 - maxUnavailable: 1 - type: RollingUpdate - template: - metadata: - labels: - app: system-server - spec: - automountServiceAccountToken: true - containers: - - image: lafyun/system-server:latest - name: system-server - resources: - # requests: - # memory: "128Mi" - # cpu: "500m" - limits: - memory: "1024Mi" - cpu: "1000m" - livenessProbe: - httpGet: - path: /health-check - port: 9000 - initialDelaySeconds: 90 - timeoutSeconds: 10 - command: ["sh", "/app/start.sh"] - env: - - name: SYS_DB_URI - value: mongodb://my_user:password123@prod.mongodb:27017/laf-sys?authSource=laf-sys&replicaSet=laf&writeConcern=majority - - name: APP_DB_URI - value: mongodb://root:password123@prod.mongodb:27017/?authSource=admin&replicaSet=laf&writeConcern=majority - - name: SYS_SERVER_SECRET_SALT - value: Rewrite_Your_Own_Secret_Salt_abcdefg1234567 - - name: APP_SERVICE_IMAGE - value: lafyun/app-service:latest - - name: SERVICE_DRIVER - value: kubernetes - - name: LOG_LEVEL - value: debug - - name: ACCOUNT_DEFAULT_APP_QUOTA - value: "5" - - name: APP_SERVICE_DEPLOY_HOST - value: local-dev.host:30000 # `*.local-dev.host` always resolved to 127.0.0.1, used to local development - - name: APP_SERVICE_DEPLOY_URL_SCHEMA - value: "http" - - name: STORAGE_SERVICE_API_ENTRYPOINT - value: http://storage-service:9010 - - name: STORAGE_SERVICE_SECRET - value: Rewrite_Your_Own_Secret_Salt_abcdefg1234567 - - name: STORAGE_SERVICE_DEPLOY_HOST - value: fs.local-dev.host:30000 # `*.local-dev.host` always resolved to 127.0.0.1, used to local development - - name: INIT_ROOT_ACCOUNT_PASSWORD - value: abc123 - ports: - - containerPort: 9000 - restartPolicy: Always \ No newline at end of file diff --git a/kubernetes-dev/deploy.fs.yml b/deploy/kubernetes/fs.yml similarity index 63% rename from kubernetes-dev/deploy.fs.yml rename to deploy/kubernetes/fs.yml index 57d026a6b1..c186cfa547 100644 --- a/kubernetes-dev/deploy.fs.yml +++ b/deploy/kubernetes/fs.yml @@ -20,6 +20,7 @@ metadata: namespace: laf labels: app: storage-service + type: sys spec: replicas: 1 selector: @@ -34,33 +35,35 @@ spec: metadata: labels: app: storage-service + type: sys spec: automountServiceAccountToken: false + restartPolicy: Always + terminationGracePeriodSeconds: 30 containers: - - image: lafyun/storage-service:0.7.0 + - image: docker.io/lafyun/storage-service:0.7.3 + imagePullPolicy: IfNotPresent name: storage-service resources: - # requests: - # memory: "128Mi" - # cpu: "500m" - limits: + requests: memory: "256Mi" - cpu: "500m" + cpu: "100m" + limits: + memory: "1024Mi" + cpu: "1000m" env: - name: DB_URI - value: mongodb://root:password123@mongo:27017/laf-fs?authSource=admin&replicaSet=laf&writeConcern=majority + valueFrom: + configMapKeyRef: + name: db-config + key: fs-db-uri + - name: SERVER_SECRET_SALT + valueFrom: + configMapKeyRef: + name: secret-salt + key: fs-server-salt - name: LOG_LEVEL value: debug - - name: SERVER_SECRET_SALT - value: Rewrite_Your_Own_Secret_Salt_abcdefg1234567 ports: - containerPort: 9010 command: ["node", "/app/dist/index.js"] - volumeMounts: - - name: local-storage-service - mountPath: /app - restartPolicy: Always - volumes: - - name: local-storage-service - hostPath: - path: /Users/fugen/codes/less/laf/packages/storage-service diff --git a/deploy/kubernetes/gateway.yml b/deploy/kubernetes/gateway.yml new file mode 100644 index 0000000000..bec7a7051e --- /dev/null +++ b/deploy/kubernetes/gateway.yml @@ -0,0 +1,90 @@ +--- +kind: Service +apiVersion: v1 +metadata: + name: gateway + namespace: laf +spec: + selector: + app: gateway + type: NodePort + ports: + - port: 80 + targetPort: 80 + name: http + nodePort: 30000 + - port: 443 + targetPort: 443 + name: https + +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: gateway + namespace: laf + labels: + app: gateway + type: sys +spec: + selector: + matchLabels: + app: gateway + template: + metadata: + labels: + app: gateway + type: sys + spec: + automountServiceAccountToken: false + hostNetwork: true + dnsPolicy: ClusterFirstWithHostNet + restartPolicy: Always + terminationGracePeriodSeconds: 30 + tolerations: + # this toleration is to have the daemonset runnable on master nodes + # remove it if your masters can't run pods + - key: node-role.kubernetes.io/master + operator: Exists + effect: NoSchedule + containers: + - image: docker.io/lafyun/gateway:0.7.4 + imagePullPolicy: IfNotPresent + name: gateway + resources: + requests: + memory: "256Mi" + cpu: "100m" + limits: + memory: "1024Mi" + cpu: "1000m" + env: + - name: DEPLOY_DOMAIN + valueFrom: + configMapKeyRef: + name: deploy-domain + key: app-service-domain + - name: DEPLOY_FS_DOMAIN + valueFrom: + configMapKeyRef: + name: deploy-domain + key: fs-service-domain + - name: SYS_CLIENT_HOST + valueFrom: + configMapKeyRef: + name: deploy-domain + key: system-console-domain + - name: DOCS_HOST + valueFrom: + configMapKeyRef: + name: deploy-domain + key: docs-domain + - name: KUBE_NAMESPACE_OF_APP_SERVICES + valueFrom: + configMapKeyRef: + name: app-service + key: kube-namespace-of-app-services + - name: SERVICE_DRIVER + value: kubernetes + ports: + - containerPort: 80 diff --git a/kubernetes-dev/deploy.mongo.yml b/deploy/kubernetes/mongo.yml similarity index 73% rename from kubernetes-dev/deploy.mongo.yml rename to deploy/kubernetes/mongo.yml index 9cf9f0bd85..95b767e92d 100644 --- a/kubernetes-dev/deploy.mongo.yml +++ b/deploy/kubernetes/mongo.yml @@ -12,6 +12,7 @@ spec: - port: 27017 targetPort: 27017 +### This mongodb ONLY work for demo purpose, you should config your own volume for production use! --- apiVersion: apps/v1 kind: StatefulSet @@ -31,19 +32,22 @@ spec: labels: app: mongo spec: - terminationGracePeriodSeconds: 10 + terminationGracePeriodSeconds: 30 containers: - image: bitnami/mongodb:5.0 name: mongo resources: + requests: + memory: "256Mi" + cpu: "100m" limits: - cpu: "500m" - memory: "256M" + memory: "1024Mi" + cpu: "1000m" env: - name: MONGODB_REPLICA_SET_MODE value: primary - name: MONGODB_ADVERTISED_HOSTNAME - value: mongo + value: mongo.laf - name: MONGODB_REPLICA_SET_NAME value: laf - name: MONGODB_REPLICA_SET_KEY @@ -55,7 +59,7 @@ spec: - name: MONGODB_PASSWORD value: password123 - name: MONGODB_DATABASE - value: laf-sys + value: sys_db ports: - containerPort: 27017 volumeMounts: @@ -63,5 +67,7 @@ spec: name: data volumes: - name: data - emptyDir: {} + hostPath: + path: /tmp/laf-mongo-test-db # update to your local path + type: DirectoryOrCreate restartPolicy: Always diff --git a/deploy/kubernetes/service.mongodb.yml b/deploy/kubernetes/service.mongodb.yml deleted file mode 100644 index d8003c091d..0000000000 --- a/deploy/kubernetes/service.mongodb.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -kind: Service -apiVersion: v1 -metadata: - name: prod - namespace: mongodb -spec: - type: ExternalName - externalName: kubernetes.docker.internal # update for your own mongo host diff --git a/deploy/kubernetes/sys.yml b/deploy/kubernetes/sys.yml new file mode 100644 index 0000000000..2777b99968 --- /dev/null +++ b/deploy/kubernetes/sys.yml @@ -0,0 +1,149 @@ +--- +kind: Service +apiVersion: v1 +metadata: + name: system-server + namespace: laf +spec: + selector: + app: system-server + type: ClusterIP + ports: + - port: 9000 + targetPort: 9000 + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: system-server + namespace: laf + labels: + app: system-server + type: sys +spec: + replicas: 1 + selector: + matchLabels: + app: system-server + strategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 1 + type: RollingUpdate + template: + metadata: + labels: + app: system-server + type: sys + spec: + automountServiceAccountToken: true + restartPolicy: Always + terminationGracePeriodSeconds: 30 + containers: + - image: docker.io/lafyun/system-server:0.7.2 + imagePullPolicy: IfNotPresent + name: system-server + resources: + requests: + memory: "256Mi" + cpu: "100m" + limits: + memory: "1024Mi" + cpu: "1000m" + livenessProbe: + httpGet: + path: /health-check + port: 9000 + initialDelaySeconds: 90 + timeoutSeconds: 10 + command: ["sh", "/app/start.sh"] + env: + - name: SYS_DB_URI + valueFrom: + configMapKeyRef: + name: db-config + key: sys-db-uri + - name: APP_DB_URI + valueFrom: + configMapKeyRef: + name: db-config + key: app-db-uri + - name: SYS_SERVER_SECRET_SALT + valueFrom: + configMapKeyRef: + name: secret-salt + key: system-server-salt + - name: KUBE_NAMESPACE_OF_APP_SERVICES + valueFrom: + configMapKeyRef: + name: app-service + key: kube-namespace-of-app-services + - name: APP_SERVICE_IMAGE + valueFrom: + configMapKeyRef: + name: app-service + key: image + - name: SERVICE_DRIVER + value: kubernetes + - name: APP_SERVICE_DEFAULT_REQUEST_MEMORY + valueFrom: + configMapKeyRef: + name: app-service + key: default-request-memory + - name: APP_SERVICE_DEFAULT_REQUEST_CPU + valueFrom: + configMapKeyRef: + name: app-service + key: default-request-cpu + - name: APP_SERVICE_DEFAULT_LIMIT_MEMORY + valueFrom: + configMapKeyRef: + name: app-service + key: default-limit-memory + - name: APP_SERVICE_DEFAULT_LIMIT_CPU + valueFrom: + configMapKeyRef: + name: app-service + key: default-limit-cpu + - name: ACCOUNT_DEFAULT_APP_QUOTA + valueFrom: + configMapKeyRef: + name: app-service + key: default-app-quota-created-per-user + - name: APP_SERVICE_DEPLOY_HOST + valueFrom: + configMapKeyRef: + name: deploy-domain + key: app-service-host + - name: APP_SERVICE_DEPLOY_URL_SCHEMA + valueFrom: + configMapKeyRef: + name: deploy-domain + key: deploy-url-schema + - name: STORAGE_SERVICE_SECRET + valueFrom: + configMapKeyRef: + name: secret-salt + key: system-server-salt + - name: STORAGE_SERVICE_DEPLOY_HOST + valueFrom: + configMapKeyRef: + name: deploy-domain + key: fs-service-host + - name: INIT_ROOT_ACCOUNT + valueFrom: + configMapKeyRef: + name: root-account + key: account + - name: INIT_ROOT_ACCOUNT_PASSWORD + valueFrom: + configMapKeyRef: + name: root-account + key: password + - name: STORAGE_SERVICE_API_ENTRYPOINT + value: http://storage-service:9010 + - name: LOG_LEVEL + value: debug + ports: + - containerPort: 9000 diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js index d2f3cf8175..1f0a4dcf7b 100644 --- a/docs/.vitepress/config.js +++ b/docs/.vitepress/config.js @@ -14,7 +14,8 @@ module.exports = { { text: '主页', link: '/' }, { text: '开发指南', link: '/guide/', activeMatch: '^/guide/' }, { text: '预览图', link: '/screenshots', }, - { text: '在线演示', link: '/todo-list', }, + { text: '在线 Demo', link: '/todo-list', }, + { text: 'lafyun.com', link: 'https://www.lafyun.com/'}, { text: '更新记录', link: 'https://github.com/lafjs/laf/blob/main/CHANGELOG.md' diff --git a/docs/deploy/quick.md b/docs/deploy/quick.md deleted file mode 100644 index 08c08cad77..0000000000 --- a/docs/deploy/quick.md +++ /dev/null @@ -1,55 +0,0 @@ ---- -title: 快速部署 laf.js 服务 -sidebar: false ---- - -### 快速部署 laf.js 服务 - -> 基于 Docker Compose 快速部署,需要你熟悉 docker 以及 docker-compose 的使用 - -##### 安装 Docker (CentOS) - -> 本例只给出 CentOS 下的安装脚本,若安装其它环境请参考官方文档 https://docs.docker.com/engine/install/ - -```shell -sudo yum install -y yum-utils -sudo yum-config-manager \ - --add-repo \ - https://download.docker.com/linux/centos/docker-ce.repo - -sudo yum install docker-ce docker-ce-cli containerd.io -sudo systemctl start docker - -``` - -> 还需安装 docker-compose @see https://docs.docker.com/compose/install/ - -##### 启动服务 - -```shell -git clone https://github.com/lafjs/laf.git -cd laf/deploy-scripts - -# 启动所有服务 -docker-compose up - -# 浏览器打开 http://locahost:8080 访问 - -``` - -##### 停止服务 - -```shell -# 停止服务 -docker-compose down - -# 停止服务并清数据卷 -docker-compose down -v -``` - -##### 更新服务镜像 - -```shell -# 更新镜像 -docker-compose pull -``` diff --git a/docs/index.md b/docs/index.md index 110db298f8..3f92c0c20d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -21,5 +21,15 @@ features: - title: 云存储 details: 内置分布式文件存储机制。可按 `Bucket` 存储和管理文件,可通过文件操作 Token,灵活控制文件访问。 -footer: Server Side Public Licensed | Copyright © 2021-present Maslow +footer: Server Side Public Licensed | Copyright © 2021-present Maslow | lafyun.com --- + +--- + +[lafyun.com](http://www.lafyun.com) 正式上线!可直接在线体验,[立即创建](http://www.lafyun.com) laf 云开发应用服务! + +> 开发者可免费在 [lafyun.com](http://www.lafyun.com) 上快速创建自己的应用,不用进行服务器部署和运维工作,立即拥有应用独立的域名及 HTTPS 证书,快速上线应用! + +> 开发者可以在私有服务器上部署一套 laf 云开发平台,可方便的将 [lafyun.com](http://www.lafyun.com) 中的应用迁至自己的 laf 云开发平台中运行! + +[`laf.js`](https://github.com/lafjs/laf) 让每个开发团队都可以随时拥有一个自己的云开发平台! diff --git a/kubernetes-dev/0-namespace.yml b/kubernetes-dev/0-namespace.yml deleted file mode 100644 index af8d55c64c..0000000000 --- a/kubernetes-dev/0-namespace.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -apiVersion: v1 -kind: Namespace -metadata: - name: mongodb - ---- -apiVersion: v1 -kind: Namespace -metadata: - name: laf diff --git a/kubernetes-dev/README.md b/kubernetes-dev/README.md deleted file mode 100644 index 2919158ebc..0000000000 --- a/kubernetes-dev/README.md +++ /dev/null @@ -1,4 +0,0 @@ - -> This kubernetes-dev can ONLY be used for development purpose !!! - -> Mongodb data will be automatically released when delete this laf cluster. \ No newline at end of file diff --git a/kubernetes-dev/deploy.gateway.yml b/kubernetes-dev/deploy.gateway.yml deleted file mode 100644 index 61ff92b4cd..0000000000 --- a/kubernetes-dev/deploy.gateway.yml +++ /dev/null @@ -1,73 +0,0 @@ ---- -kind: Service -apiVersion: v1 -metadata: - name: gateway - namespace: laf -spec: - selector: - app: gateway - type: NodePort - ports: - - port: 80 - targetPort: 80 - nodePort: 30000 - ---- -apiVersion: apps/v1 -kind: DaemonSet -metadata: - name: gateway - namespace: laf - labels: - app: gateway -spec: - selector: - matchLabels: - app: gateway - template: - metadata: - labels: - app: gateway - spec: - automountServiceAccountToken: false - # hostNetwork: true - # dnsPolicy: ClusterFirstWithHostNet - containers: - - image: lafyun/gateway:0.7.1 - name: gateway - resources: - limits: - memory: "256Mi" - cpu: "500m" - env: - - name: DEPLOY_DOMAIN - value: "*.local-dev.host" - - name: DEPLOY_FS_DOMAIN - value: "*.fs.local-dev.host" - - name: SYS_CLIENT_HOST - value: console.local-dev.host - - name: DOCS_HOST - value: docs.local-dev.host - - name: SERVICE_DRIVER - value: kubernetes - ports: - - containerPort: 80 - volumeMounts: - - name: system-conf - mountPath: /etc/nginx/templates/system.conf.template - - name: app-conf - mountPath: /etc/nginx/templates/app.conf.template - - name: fs-conf - mountPath: /etc/nginx/templates/fs-proxy.conf.template - restartPolicy: Always - volumes: - - name: system-conf - hostPath: - path: /Users/fugen/codes/less/laf/packages/gateway/conf.kubernetes/system.conf - - name: app-conf - hostPath: - path: /Users/fugen/codes/less/laf/packages/gateway/conf.kubernetes/app.conf - - name: fs-conf - hostPath: - path: /Users/fugen/codes/less/laf/packages/gateway/conf.kubernetes/fs-proxy.conf diff --git a/kubernetes-dev/deploy.sys.yml b/kubernetes-dev/deploy.sys.yml deleted file mode 100644 index 4a24c4843c..0000000000 --- a/kubernetes-dev/deploy.sys.yml +++ /dev/null @@ -1,89 +0,0 @@ ---- -kind: Service -apiVersion: v1 -metadata: - name: system-server - namespace: laf -spec: - selector: - app: system-server - type: ClusterIP - ports: - - port: 9000 - targetPort: 9000 - ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: system-server - namespace: laf - labels: - app: system-server -spec: - replicas: 1 - selector: - matchLabels: - app: system-server - strategy: - rollingUpdate: - maxSurge: 1 - maxUnavailable: 1 - type: RollingUpdate - template: - metadata: - labels: - app: system-server - spec: - automountServiceAccountToken: true - containers: - - image: lafyun/system-server:0.7.1 - name: system-server - resources: - limits: - memory: "256Mi" - cpu: "500m" - livenessProbe: - httpGet: - path: /health-check - port: 9000 - initialDelaySeconds: 90 - timeoutSeconds: 10 - command: ["sh", "/app/start.sh"] - env: - - name: SYS_DB_URI - value: mongodb://my_user:password123@mongo:27017/laf-sys?authSource=laf-sys&replicaSet=laf&writeConcern=majority - - name: APP_DB_URI - value: mongodb://root:password123@mongo:27017/?authSource=admin&replicaSet=laf&writeConcern=majority - - name: SYS_SERVER_SECRET_SALT - value: Rewrite_Your_Own_Secret_Salt_abcdefg1234567 - - name: APP_SERVICE_IMAGE - value: lafyun/app-service:0.7.1 - - name: SERVICE_DRIVER - value: kubernetes - - name: LOG_LEVEL - value: debug - - name: ACCOUNT_DEFAULT_APP_QUOTA - value: "5" - - name: APP_SERVICE_DEPLOY_HOST - value: local-dev.host:30000 # `*.local-dev.host` always resolved to 127.0.0.1, used to local development - - name: APP_SERVICE_DEPLOY_URL_SCHEMA - value: "http" - - name: STORAGE_SERVICE_API_ENTRYPOINT - value: http://storage-service:9010 - - name: STORAGE_SERVICE_SECRET - value: Rewrite_Your_Own_Secret_Salt_abcdefg1234567 - - name: STORAGE_SERVICE_DEPLOY_HOST - value: fs.local-dev.host:30000 # `*.local-dev.host` always resolved to 127.0.0.1, used to local development - - name: INIT_ROOT_ACCOUNT_PASSWORD - value: abc123 - ports: - - containerPort: 9000 - volumeMounts: - - name: local-system-server - mountPath: /app - restartPolicy: Always - volumes: - - name: local-system-server - hostPath: - path: /Users/fugen/codes/less/laf/packages/system-server diff --git a/lerna.json b/lerna.json index b906658aae..1ddf02d406 100644 --- a/lerna.json +++ b/lerna.json @@ -2,7 +2,7 @@ "packages": [ "packages/*" ], - "version": "0.7.4", + "version": "0.7.5", "command": { "publish": { "ignoreChanges": [ diff --git a/packages/gateway/conf.kubernetes/app.conf b/packages/gateway/conf.kubernetes/app.conf index 5bafcdeb05..052dbf676c 100644 --- a/packages/gateway/conf.kubernetes/app.conf +++ b/packages/gateway/conf.kubernetes/app.conf @@ -25,7 +25,7 @@ server { set $service_id app-$appid; } - proxy_pass http://$service_id.laf.svc.cluster.local:8000; + proxy_pass http://$service_id.$KUBE_NAMESPACE_OF_APP_SERVICES.svc.cluster.local:8000; add_header appid $appid; proxy_read_timeout 600s; proxy_set_header Host $host; diff --git a/packages/gateway/conf.kubernetes/system.conf b/packages/gateway/conf.kubernetes/system.conf index 86a9288f28..d388f0f15e 100644 --- a/packages/gateway/conf.kubernetes/system.conf +++ b/packages/gateway/conf.kubernetes/system.conf @@ -16,9 +16,17 @@ server { } location /sys-api/ { - proxy_pass http://system-server:9000/; - proxy_send_timeout 600s; - proxy_read_timeout 600s; + resolver kube-dns.kube-system.svc.cluster.local valid=10s; + + # use var to force nginx resolve domain through DNS resolver; + # to prevent nginx from just resolving service once in starting; + set $service_name "system-server"; + + if ($uri ~* "/sys-api/(.*)$") { + set $proxy_uri $1$is_args$query_string; + } + + proxy_pass http://$service_name.laf.svc.cluster.local:9000/$proxy_uri; } location /sys-extension-api/ { @@ -32,7 +40,7 @@ server { set $proxy_uri $1$is_args$query_string; } - proxy_pass http://$service_id.laf.svc.cluster.local:8000/$proxy_uri; + proxy_pass http://$service_id.$KUBE_NAMESPACE_OF_APP_SERVICES.svc.cluster.local:8000/$proxy_uri; proxy_send_timeout 600s; proxy_read_timeout 600s; diff --git a/packages/gateway/package-lock.json b/packages/gateway/package-lock.json index ae8d4e5261..574dcd0642 100644 --- a/packages/gateway/package-lock.json +++ b/packages/gateway/package-lock.json @@ -1,6 +1,6 @@ { "name": "gateway", - "version": "0.7.4", + "version": "0.7.5", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/packages/gateway/package.json b/packages/gateway/package.json index bcc84d614c..dcbb21f65c 100644 --- a/packages/gateway/package.json +++ b/packages/gateway/package.json @@ -1,6 +1,6 @@ { "name": "gateway", - "version": "0.7.4", + "version": "0.7.5", "description": "gateway service for laf.js", "main": "index.js", "private": true, diff --git a/packages/system-client/package-lock.json b/packages/system-client/package-lock.json index 0e9d4ed8dd..4128cc8d39 100644 --- a/packages/system-client/package-lock.json +++ b/packages/system-client/package-lock.json @@ -1,6 +1,6 @@ { "name": "system-client", - "version": "0.7.2", + "version": "0.7.5", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/packages/system-client/package.json b/packages/system-client/package.json index 38a75af43f..a1e0cfb3f6 100644 --- a/packages/system-client/package.json +++ b/packages/system-client/package.json @@ -1,6 +1,6 @@ { "name": "system-client", - "version": "0.7.2", + "version": "0.7.5", "description": "system-client of laf", "author": "Maslow ", "private": true, diff --git a/packages/system-client/src/views/application/index.vue b/packages/system-client/src/views/application/index.vue index d6c3493207..8e73c92ce1 100644 --- a/packages/system-client/src/views/application/index.vue +++ b/packages/system-client/src/views/application/index.vue @@ -460,8 +460,8 @@ export default { return version || 'unknown' }, getRuntimeMemory(app) { - const memory = app.runtime?.metrics?.memory - return memory || '256' + const memory = app.runtime?.resources?.limit_memory + return memory || '-' } } } diff --git a/packages/system-server/.gitignore b/packages/system-server/.gitignore index 7a4c006672..6f9d43cc92 100644 --- a/packages/system-server/.gitignore +++ b/packages/system-server/.gitignore @@ -6,6 +6,7 @@ data/* tmp .env +.env.local ecosystem.config.js .DS_Store diff --git a/packages/system-server/package-lock.json b/packages/system-server/package-lock.json index 35514f4eb2..58a500c1fa 100644 --- a/packages/system-server/package-lock.json +++ b/packages/system-server/package-lock.json @@ -1,6 +1,6 @@ { "name": "system-server", - "version": "0.7.2", + "version": "0.7.5", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/packages/system-server/package.json b/packages/system-server/package.json index f8fd96e1fe..ed9e1019e1 100644 --- a/packages/system-server/package.json +++ b/packages/system-server/package.json @@ -1,6 +1,6 @@ { "name": "system-server", - "version": "0.7.2", + "version": "0.7.5", "description": "laf - system server", "main": "./dist/index.js", "typings": "./dist/index.d.ts", diff --git a/packages/system-server/src/api/application.ts b/packages/system-server/src/api/application.ts index 7d0e385d8f..d5213d942d 100644 --- a/packages/system-server/src/api/application.ts +++ b/packages/system-server/src/api/application.ts @@ -1,7 +1,7 @@ /* * @Author: Maslow * @Date: 2021-08-28 22:00:45 - * @LastEditTime: 2022-01-13 13:48:28 + * @LastEditTime: 2022-02-01 00:04:33 * @Description: Application APIs */ @@ -38,9 +38,20 @@ export interface ApplicationStruct { } runtime: { image: string - metrics: { + /** @deprecated use `resources` instead, will be removed in future */ + metrics?: { cpu_shares?: number memory?: number + }, + resources: { + /** `requests.cpu` in kubernetes, in millicores. ex. `1000` for 1 cpu, `100` for 0.1 cpu. */ + req_cpu: string, + /** `requests.memory` in kubernetes, in Mib. */ + req_memory: string, + /** `limits.cpu` in kubernetes, also valid for docker cpu shares. In millicores. ex. `1000` for 1 cpu, `100` for 0.1 cpu. */ + limit_cpu: string, + /** `limits.memory` in kubernetes, also valid for docker memory limit, in Mib. */ + limit_memory: string } } buckets: { diff --git a/packages/system-server/src/api/init.ts b/packages/system-server/src/api/init.ts index d7597f852d..a4cbeb10dd 100644 --- a/packages/system-server/src/api/init.ts +++ b/packages/system-server/src/api/init.ts @@ -83,9 +83,11 @@ export class InitializerApi { }, runtime: { image: Config.APP_SERVICE_IMAGE, - metrics: { - cpu_shares: 2048, - memory: 1024 + resources: { + req_cpu: '100', + req_memory: '256', + limit_cpu: '1000', + limit_memory: '1024' } }, buckets: [], diff --git a/packages/system-server/src/config.ts b/packages/system-server/src/config.ts index 282ddcac03..37812f41f5 100644 --- a/packages/system-server/src/config.ts +++ b/packages/system-server/src/config.ts @@ -119,16 +119,35 @@ export default class Config { /** * The max memory limit of application service, default is 256 in mb + * + * @deprecated this field was deprecated and removed, use APP_SERVICE_DEFAULT_LIMIT_MEMORY instead + */ + static get APP_SERVICE_MEMORY_LIMIT() { + throw new Error('APP_SERVICE_MEMORY_LIMIT is deprecated, use APP_SERVICE_DEFAULT_LIMIT_MEMORY instead.') + } + + /** + * The max cpu limit of application service, default is 100 + * + * * @deprecated this field was deprecated and removed, use APP_SERVICE_DEFAULT_LIMIT_CPU instead */ - static get APP_SERVICE_MEMORY_LIMIT(): number { - return (process.env.APP_SERVICE_MEMORY_LIMIT ?? 256) as number + static get APP_SERVICE_CPU_LIMIT(): number { + throw new Error('APP_SERVICE_CPU_LIMIT is deprecated, use APP_SERVICE_DEFAULT_LIMIT_CPU instead.') } /** - * The cpu shares of application service, default is 256 + * The resources (cpu & memory) limit of application service. */ - static get APP_SERVICE_CPU_SHARES(): number { - return (process.env.APP_SERVICE_MEMORY_LIMIT ?? 256) as number + static get APP_DEFAULT_RESOURCES(): { req_cpu: string, req_memory: string, limit_cpu: string, limit_memory: string } { + const limit_cpu = process.env.APP_SERVICE_DEFAULT_LIMIT_CPU ?? '100' + const limit_memory = process.env.APP_SERVICE_DEFAULT_LIMIT_MEMORY || '256' + + return { + req_cpu: process.env.APP_SERVICE_DEFAULT_REQUEST_CPU ?? limit_cpu, + req_memory: process.env.APP_SERVICE_DEFAULT_REQUEST_MEMORY ?? limit_memory, + limit_cpu, + limit_memory, + } } /** @@ -173,4 +192,12 @@ export default class Config { const package_: string = process.env.SYSTEM_EXTENSION_SERVER_APP_PACKAGE || default_ return package_ } + + static get KUBE_NAMESPACE_OF_APP_SERVICES() { + return process.env.KUBE_NAMESPACE_OF_APP_SERVICES || 'laf' + } + + static get KUBE_NAMESPACE_OF_SYS_SERVICES() { + return process.env.KUBE_NAMESPACE_OF_SYS_SERVICES || 'laf' + } } \ No newline at end of file diff --git a/packages/system-server/src/index.ts b/packages/system-server/src/index.ts index 1f7515c141..298cf74011 100644 --- a/packages/system-server/src/index.ts +++ b/packages/system-server/src/index.ts @@ -1,7 +1,7 @@ /* * @Author: Maslow * @Date: 2021-07-30 10:30:29 - * @LastEditTime: 2022-01-20 13:52:36 + * @LastEditTime: 2022-01-23 19:46:34 * @Description: */ @@ -58,8 +58,14 @@ process.on('SIGTERM', gracefullyExit) process.on('SIGINT', gracefullyExit) async function gracefullyExit() { + logger.info('exiting: removing system extension service') await ServiceDriver.create().removeService({ appid: Constants.SYSTEM_EXTENSION_APPID } as any) + logger.info('exiting: system extension service has been removed') + + logger.info('exiting: closing db connection') await DatabaseAgent.sys_accessor.close() + logger.info('exiting: db connection has been closed') + server.close(async () => { logger.info('process gracefully exited!') process.exit(0) diff --git a/packages/system-server/src/lib/service-driver/container.ts b/packages/system-server/src/lib/service-driver/container.ts index 6492e5cb56..f16f5019e9 100644 --- a/packages/system-server/src/lib/service-driver/container.ts +++ b/packages/system-server/src/lib/service-driver/container.ts @@ -92,10 +92,9 @@ export class DockerContainerServiceDriver implements ServiceDriverInterface { */ private async createService(app: ApplicationStruct) { const uri = getApplicationDbUri(app) - const memoryLimit = app.runtime?.metrics?.memory ?? Config.APP_SERVICE_MEMORY_LIMIT + const memoryLimit = parseInt(app.runtime?.resources?.limit_memory ?? Config.APP_DEFAULT_RESOURCES.limit_memory) const max_old_space_size = ~~(memoryLimit * 0.8) - // if no cpu-shares set, use memory limit as it - const cpuShares = app.runtime?.metrics?.cpu_shares ?? Config.APP_SERVICE_CPU_SHARES + const cpuShares = parseInt(app.runtime?.resources?.limit_cpu ?? Config.APP_DEFAULT_RESOURCES.limit_cpu) const imageName = app.runtime?.image ?? Config.APP_SERVICE_IMAGE const logLevel = Config.LOG_LEVEL diff --git a/packages/system-server/src/lib/service-driver/kubernetes.ts b/packages/system-server/src/lib/service-driver/kubernetes.ts index e2b7d83cce..8e81528b9d 100644 --- a/packages/system-server/src/lib/service-driver/kubernetes.ts +++ b/packages/system-server/src/lib/service-driver/kubernetes.ts @@ -7,7 +7,7 @@ import { ServiceDriverInterface } from './interface' export class KubernetesServiceDriver implements ServiceDriverInterface { - namespace = "laf" + namespace = Config.KUBE_NAMESPACE_OF_APP_SERVICES apps_api: k8s.AppsV1Api core_api: k8s.CoreV1Api @@ -92,13 +92,18 @@ export class KubernetesServiceDriver implements ServiceDriverInterface { */ private async createK8sDeployment(app: ApplicationStruct, labels: any) { const uri = getApplicationDbUri(app) - const memoryLimit = app.runtime?.metrics?.memory ?? Config.APP_SERVICE_MEMORY_LIMIT - const max_old_space_size = ~~(memoryLimit * 0.8) - // if no cpu-shares set, use memory limit as it - const cpuShares = app.runtime?.metrics?.cpu_shares ?? Config.APP_SERVICE_CPU_SHARES + + const limit_memory = parseInt(app.runtime?.resources?.limit_memory ?? Config.APP_DEFAULT_RESOURCES.limit_memory) + const limit_cpu = app.runtime?.resources?.limit_cpu ?? Config.APP_DEFAULT_RESOURCES.limit_cpu + + const req_cpu = app.runtime?.resources?.req_cpu ?? Config.APP_DEFAULT_RESOURCES.req_cpu + const req_memory = app.runtime?.resources?.req_memory ?? Config.APP_DEFAULT_RESOURCES.req_memory + const imageName = app.runtime?.image ?? Config.APP_SERVICE_IMAGE + const max_old_space_size = ~~(limit_memory * 0.8) const logLevel = Config.LOG_LEVEL + // create k8s deployment const { body: deployment } = await this.apps_api.createNamespacedDeployment(this.namespace, { metadata: { @@ -133,13 +138,13 @@ export class KubernetesServiceDriver implements ServiceDriverInterface { ], ports: [{ containerPort: 8000 }], resources: { - // requests: { - // memory: `${memoryLimit}Mi`, - // cpu: `${cpuShares}m` - // }, + requests: { + memory: `${req_memory}Mi`, + cpu: `${req_cpu}m` + }, limits: { - memory: `${memoryLimit}Mi`, - cpu: `${cpuShares}m` + memory: `${limit_memory}Mi`, + cpu: `${limit_cpu}m` } } } diff --git a/packages/system-server/src/router/application/create.ts b/packages/system-server/src/router/application/create.ts index 272f6d6cb5..9eb0db95ce 100644 --- a/packages/system-server/src/router/application/create.ts +++ b/packages/system-server/src/router/application/create.ts @@ -1,7 +1,7 @@ /* * @Author: Maslow * @Date: 2021-08-31 15:00:04 - * @LastEditTime: 2021-12-07 13:57:21 + * @LastEditTime: 2022-01-31 23:44:45 * @Description: */ @@ -59,9 +59,11 @@ export async function handleCreateApplication(req: Request, res: Response) { }, runtime: { image: Config.APP_SERVICE_IMAGE, - metrics: { - cpu_shares: Config.APP_SERVICE_CPU_SHARES, - memory: Config.APP_SERVICE_MEMORY_LIMIT + resources: { + req_cpu: Config.APP_DEFAULT_RESOURCES.req_cpu, + req_memory: Config.APP_DEFAULT_RESOURCES.req_memory, + limit_cpu: Config.APP_DEFAULT_RESOURCES.limit_cpu, + limit_memory: Config.APP_DEFAULT_RESOURCES.limit_memory, } }, buckets: [],