Browse Source

Feature: Ability to config server port via Environment Variable (#434)

* add "SERVER_PORT" as an optional environment variable that can be used to configure the node.js server port, defaulting to 3000. Update readme to reflect new env var and add docker run example.

* typos in readme

---------

Co-authored-by: Brandon <bbeiler@ridgelineintl.com>
Brandon Beiler 1 year ago
parent
commit
a114fbe495
2 changed files with 19 additions and 3 deletions
  1. 16 1
      README.md
  2. 3 2
      server/src/app.ts

+ 16 - 1
README.md

@@ -31,13 +31,15 @@ Make sure that the Attu container can access the Milvus IP address. After starti
 #### Optional Environment Variables for Running Attu Docker
 
 | Parameter        | Example              | Required | Description                             |
-| :--------------- | :------------------- | :------: | --------------------------------------- |
+|:-----------------|:---------------------| :------: |-----------------------------------------|
 | MILVUS_URL       | 192.168.0.1:19530    |  false   | Optional, Milvus server URL             |
 | ATTU_LOG_LEVEL   | info                 |  false   | Optional, sets the log level for Attu   |
 | ROOT_CERT_PATH   | /path/to/root/cert   |  false   | Optional, path to the root certificate  |
 | PRIVATE_KEY_PATH | /path/to/private/key |  false   | Optional, path to the private key       |
 | CERT_CHAIN_PATH  | /path/to/cert/chain  |  false   | Optional, path to the certificate chain |
 | SERVER_NAME      | your_server_name     |  false   | Optional, name of your server           |
+| SERVER_PORT      | Server listen port   |  false   | Optional, 3000 by default if unset      |
+
 
 > Please note that the `MILVUS_URL` should be an address that the Attu Docker container can access. Therefore, "127.0.0.1" or "localhost" will not work.
 
@@ -56,6 +58,19 @@ docker run -p 8000:3000 \
 zilliz/attu:dev
 ```
 
+#### Custom Server Port Example
+*This command lets you run the docker container with host networking, specifying a custom port for 
+the server to listen on*
+
+```bash
+docker run --network host \
+-v /your-tls-file-path:/app/tls \
+-e ATTU_LOG_LEVEL=info  \
+-e SERVER_NAME=your_server_name \
+-e SERVER_PORT=8080 \
+zilliz/attu:dev
+```
+
 ### Running Attu within Kubernetes
 
 Before you begin, make sure that you have Milvus installed and running within your [K8's Cluster](https://milvus.io/docs/install_cluster-milvusoperator.md). Note that Attu only supports Milvus 2.x.

+ 3 - 2
server/src/app.ts

@@ -58,8 +58,6 @@ router.get('/healthy', (req, res, next) => {
 
 // initialize a simple http server
 const server = http.createServer(app);
-// default port 3000
-const PORT = 3000;
 
 // setup middlewares
 // use cors https://expressjs.com/en/resources/middleware/cors.html
@@ -93,6 +91,9 @@ app.use(ErrorMiddleware);
 // init websocket server
 initWebSocket(server);
 
+// use port 3000 unless there exists a preconfigured port
+const PORT = process.env.SERVER_PORT || 3000;
+
 // start server
 server.listen(PORT, () => {
   const ips = getIp();