Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

faild follow guide to install js plugin #401

Open
miniboxhaha opened this issue Dec 11, 2024 · 0 comments
Open

faild follow guide to install js plugin #401

miniboxhaha opened this issue Dec 11, 2024 · 0 comments

Comments

@miniboxhaha
Copy link

miniboxhaha commented Dec 11, 2024

dockerfile

FROM kong:3.7
# Ensure any patching steps are executed as root user
USER root

# Add custom plugin to the image
RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y curl
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs
RUN npm config set registry https://registry.npmmirror.com/
RUN npm install -g kong-pdk
ADD myjwt.js /usr/local/kong/js-plugins/
ADD package.json /usr/local/kong/js-plugins/
WORKDIR /usr/local/kong/js-plugins/
RUN npm install
WORKDIR /

# Ensure kong user is selected for image execution
USER kong

# Run kong
ENTRYPOINT ["/docker-entrypoint.sh"]
EXPOSE 8000 8443 8001 8444
STOPSIGNAL SIGQUIT
HEALTHCHECK --interval=10s --timeout=10s --retries=10 CMD kong health
CMD ["kong", "docker-start"]

pulgin.js

'use strict';

// This is an example plugin that add a header to the response

class KongPlugin {
  constructor(config) {
    this.config = config
  }

  async access(kong) {
    await Promise.all([
      kong.response.setHeader("x-hello-from-javascript", "Javascript"),
      kong.response.setHeader("x-javascript-pid", process.pid),
    ])
  }
}

module.exports = {
  Plugin: KongPlugin,
  Schema: [
    { message: { type: "string" } },
  ],
  Version: '0.1.0',
  Priority: 0,
}

package.json

{
  "name": "myjwt",
  "version": "0.1.0",
  "description": "hello JS plugin from kong",
  "main": "myjwt.js",
  "dependencies": {
    "kong-pdk": "^0.5.5"
  }
}

helm chart value.yaml

deployment:
  test:
    enabled: false

controller:
  proxy:
    nameOverride: "{{ .Release.Name }}-gateway-proxy"

  enabled: false

  deployment:
    kong:
      enabled: false

  ingressController:
    enabled: false
    image:
      repository: registry.cluster.local:30443/kong/kubernetes-ingress-controller
      tag: "3.3.1"

    gatewayDiscovery:
      enabled: true
      generateAdminApiService: true

  podAnnotations:
    kuma.io/gateway: enabled
    # This port must match your Kong admin API port. 8444 is the default.
    # If you set gateway.admin.tls.containerPort, change these annotations
    # to use that value.
    traffic.kuma.io/exclude-outbound-ports: "8444"
    traffic.sidecar.istio.io/excludeOutboundPorts: "8444"

gateway:
  replicaCount: 1
  proxy:
    type: NodePort
    http:
      nodePort: 32000
  manager:
    type: NodePort
    http:
      nodePort: 32100
  admin:
    enabled: true
    http:
      enabled: true
      nodePort: 32080
      servicePort: 32080
      containerPort: 32080
  enabled: true
  image:
    repository: registry.cluster.local:30443/my-kong
    tag: "3.7"
  dblessConfig:
    config: |
      _format_version: "3.0"
      _transform: true

      services:
      - name: my-first-service
        protocol: http
        port: 3000
        host: my-first-upstreams
        path: /test_header
        routes:
        - name: my-first-route
          paths:
            - /test_app/test_header
      upstreams: 
      - name: my-first-upstreams
        algorithm: consistent-hashing
        hash_on: ip
        targets:
        - target: test-app-service.ha:3000
  deployment:
    kong:
      enabled: true

  ingressController:
    enabled: false

  env:
    role: traditional
    database: "off"
    pluginserver_names: myjwt
    pluginserver_myjwt_start_cmd: /usr/bin/kong-js-pluginserver -v --plugins-directory /usr/local/kong/js-plugins
    pluginserver_myjwt_query_cmd: /usr/bin/kong-js-pluginserver --plugins-directory /usr/local/kong/js-plugins --dump-all-plugins
    pluginserver_myjwt_socket: /usr/local/kong/js_pluginserver.sock

log:

2024/12/12 08:13:26 [warn] 1#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /kong_prefix/nginx.conf:7
nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /kong_prefix/nginx.conf:7
2024/12/12 08:13:26 [notice] 1#0: [lua] init.lua:788: init(): [request-debug] token for request debugging: 077f2f9b-21b0-43f5-abab-182528a9ecd2
2024/12/12 08:13:26 [notice] 1#0: using the "epoll" event method
2024/12/12 08:13:26 [notice] 1#0: openresty/1.25.3.1
2024/12/12 08:13:26 [notice] 1#0: OS: Linux 5.15.0-67-generic
2024/12/12 08:13:26 [notice] 1#0: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2024/12/12 08:13:26 [notice] 1#0: start worker processes
2024/12/12 08:13:26 [notice] 1#0: start worker process 1334
2024/12/12 08:13:26 [notice] 1#0: start worker process 1335
2024/12/12 08:13:26 [notice] 1335#0: *2 [lua] globalpatches.lua:75: sleep(): executing a blocking 'sleep' (0.001 seconds), context: init_worker_by_lua*
2024/12/12 08:13:26 [notice] 1335#0: *2 [lua] globalpatches.lua:75: sleep(): executing a blocking 'sleep' (0.002 seconds), context: init_worker_by_lua*
2024/12/12 08:13:26 [notice] 1335#0: *2 [lua] globalpatches.lua:75: sleep(): executing a blocking 'sleep' (0.004 seconds), context: init_worker_by_lua*
2024/12/12 08:13:26 [notice] 1334#0: *1 [lua] init.lua:266: purge(): [DB cache] purging (local) cache, context: init_worker_by_lua*
2024/12/12 08:13:26 [notice] 1334#0: *1 [lua] init.lua:266: purge(): [DB cache] purging (local) cache, context: init_worker_by_lua*
2024/12/12 08:13:26 [notice] 1334#0: *1 [kong] init.lua:593 declarative config loaded from /kong_dbless/kong.yml, context: init_worker_by_lua*
2024/12/12 08:13:26 [notice] 1334#0: *645 [kong] process.lua:217 Starting myjwt, context: ngx.timer
2024/12/12 08:13:26 [notice] 1334#0: signal 17 (SIGCHLD) received from 1336
2024/12/12 08:13:26 [notice] 1334#0: *645 [kong] process.lua:233 external pluginserver 'myjwt' terminated: exit 1, context: ngx.timer
2024/12/12 08:13:27 [notice] 1334#0: *645 [kong] process.lua:217 Starting myjwt, context: ngx.timer
2024/12/12 08:13:27 [notice] 1334#0: signal 17 (SIGCHLD) received from 1343
2024/12/12 08:13:27 [notice] 1334#0: *645 [kong] process.lua:233 external pluginserver 'myjwt' terminated: exit 1, context: ngx.timer
2024/12/12 08:13:28 [notice] 1334#0: *645 [kong] process.lua:217 Starting myjwt, context: ngx.timer
2024/12/12 08:13:28 [notice] 1334#0: signal 17 (SIGCHLD) received from 1350
2024/12/12 08:13:28 [notice] 1334#0: *645 [kong] process.lua:233 external pluginserver 'myjwt' terminated: exit 1, context: ngx.timer
2024/12/12 08:13:29 [notice] 1334#0: *645 [kong] process.lua:217 Starting myjwt, context: ngx.timer
2024/12/12 08:13:29 [notice] 1334#0: signal 17 (SIGCHLD) received from 1357

can someon help, thanks.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant