Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add option to preset kong-admin url and not change it #39

Closed
cronventis opened this issue May 22, 2023 · 7 comments · Fixed by #44
Closed

Add option to preset kong-admin url and not change it #39

cronventis opened this issue May 22, 2023 · 7 comments · Fixed by #44
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@cronventis
Copy link
Contributor

I would like to be able to have a docker image with a kong admin url as environment variable und not be able to change it in the UI
This way I can deploy it for multiple clusters with different urls, without the need to know the admin url.

@ligreman
Copy link
Owner

ligreman commented May 31, 2023

@cronventis King is made with Angular framework, in a serverless way. It is executed in the browser. So there is no place to have variables defined, like environment, files, etc.

To archieve what you need, you must made a mix of modifications in Kings code to hardcode the Kong Admin url, and then configure the dockerfile to modify the file with this url to adapt it to the cluster it is being deployed.

Other option but based in something similar, is to deploy King + a server like apache to serve it (I don't know if you are already using apache or nginx...), and then serve with apache a json file as an static resource, e.g https://myserver/file.json. In the json file you can put the kong admin url, and then modify King's code to get this json file and read it.

I'm not used to work with docker (but currently I'm learning) so I don't kknow if there are better ways to have "dinamic" deployments depending the cluster you are working with.

@funkytaco
Copy link

If you enable passing as ENV variable, it will work with a Dockerfile.

@ligreman ligreman reopened this Jun 19, 2023
@cronventis
Copy link
Contributor Author

cronventis commented Jun 20, 2023

Just as a follow-up:
Off course, you are right.. There is nothing like an environment variable.
I have created a dockerfile, so I could also offer a PR regarding this.
But what is missing, is exactly what you described: for example a config.json somewhere, wher IF a hostname is entered in it, then the input field at the top-right should be gone. Maybe also including settings for auth... Something like:

{
  "kong_admin_url": "http://example.com/admin",
  "username": "admin",
  "password": "password123",
  "auth_type": "basic"
}

Then, I could create a script that replaces the values with data coming from env variables in docker.. Something like this:

#!/bin/bash

# Set the file path to your JSON file
json_file=" /usr/share/nginx/html/config.json"

# Update the values using jq
jq '.kong_admin_url = "$KONG_ADMIN_URL"' \
   | jq '.username = "$USERNAME"' \
   | jq '.password = "$PASSWORD"' \
   | jq '.auth_type = "$AUTH_TYPE"' \
   "$json_file" > tmp_file && mv tmp_file "$json_file"

# Start the web server
exec "$@"

The Dockerfile would look something like this:

# build environment
FROM node:20 as build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package*.json ./
RUN npm ci --silent
COPY . ./
RUN npm run build

# production environment
FROM nginx:stable-alpine
RUN apk add --no-cache jq
COPY --from=build /app/build /usr/share/nginx/html
COPY startup.sh /usr/local/bin/startup.sh
RUN chmod +x /usr/local/bin/startup.sh
EXPOSE 80
CMD ["/usr/local/bin/startup.sh", "nginx", "-g", "daemon off;"]

The only thing you need to do, Is configure king to use the config.json if it exists..?

@ligreman
Copy link
Owner

ligreman commented Jun 22, 2023

I think I can make some changes to make one request for a json, served as an static resource by the same server that is serving King.

I'll take a look at that. And then any help with the docker files would be great, I'm not used to work with it (not yet).

Thanks.

Edit: I didn't saw the pull request you made when I wrote the comment :P

@ligreman ligreman added this to the 3.1.0 milestone Jun 23, 2023
@ligreman
Copy link
Owner

ligreman commented Jul 9, 2023

I reopen this because I closed it by mistake.

@cronventis I've pushed some changes that adds the "config file" functionality as we were talking. Given you have one JSON config file served as a static file, you can set a config-file-url for King (saved in your browser localStorage). You point that url to the json file, and the King will try to read it on load. If it's available then King will use the information in that config file to connect to the Kong node overriding the url in the header field (and maybe more configuration in the future).

Of course the CORS problems that may arise must be solved in the web server serving the config file (if the hostname/port are different between King and that json file).

(see README.md and the template in the examples folder for more information about the format)

Give it a try if you can!

PST: I have not implemented the other configuration option of being able to hide or not the kong url node field. In order to "not allow" anyone to connect to another kong node. Although it would be a lie, anyone can change the javascript or html "on live" in their own browser, so I hesitate to implement it or not.

@ligreman ligreman reopened this Jul 9, 2023
@ligreman ligreman added the enhancement New feature or request label Jul 9, 2023
@ligreman ligreman self-assigned this Jul 9, 2023
@ligreman
Copy link
Owner

ligreman commented Jul 9, 2023

I forgot. Another thing pending is to set a default config file url. Probably by default will be the current host King is running on "/config.json". So you can automatically "set it up" in the Dockerfile just by creating the config.json file in the same folder as the "index.html" of King.

Example
http://current-king-host.com/config.json

@cronventis
Copy link
Contributor Author

Yea, that would be needed.. Otherwise I could also just enter the Kong Admin URL directly..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
3 participants