From 820924f04fd5c7cd0fbdee19b8b09c904a28221b Mon Sep 17 00:00:00 2001 From: Mohammed Abdi Date: Thu, 20 Apr 2023 18:56:30 +0000 Subject: [PATCH] Parameterizing ports in docker files (#159) * parameterize ports in docker file Signed-off-by: Mohammed Abdi * implement health check (#161) * implemented health check Signed-off-by: Maia Iyer * fixing lint check Signed-off-by: Maia Iyer * reverting cmd file Signed-off-by: Maia Iyer * nit Signed-off-by: Maia Iyer * added debug server call Signed-off-by: Maia Iyer * adding documentation Signed-off-by: Maia Iyer * attempting to clean lint Signed-off-by: Maia Iyer * attempt to remove lint Signed-off-by: Maia Iyer * removing deadcode Signed-off-by: Maia Iyer * removing more deadcode Signed-off-by: Maia Iyer * removing more deadcode Signed-off-by: Maia Iyer * removing more deadcode Signed-off-by: Maia Iyer --------- Signed-off-by: Maia Iyer * adding documentation Signed-off-by: Mohammed Abdi --------- Signed-off-by: Mohammed Abdi Signed-off-by: Maia Iyer Co-authored-by: Mohammed Abdi Co-authored-by: Maia Iyer --- Dockerfile.frontend-container | 4 +++- Dockerfile.tornjak-container | 7 +++++-- USAGE.md | 10 ++++++---- tornjak-frontend/package-lock.json | 14 +++++++------- tornjak-frontend/package.json | 2 +- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Dockerfile.frontend-container b/Dockerfile.frontend-container index 61179f37..5506d5c8 100644 --- a/Dockerfile.frontend-container +++ b/Dockerfile.frontend-container @@ -14,6 +14,8 @@ ENV REACT_APP_API_SERVER_URI $REACT_APP_API_SERVER_URI ENV REACT_APP_AUTH_SERVER_URI $REACT_APP_AUTH_SERVER_URI ENV NODE_OPTIONS $NODE_OPTIONS ARG NODE_OPTIONS=--openssl-legacy-provider -EXPOSE 3000 + +ENV PORT_FE=3000 +EXPOSE $PORT_FE CMD ["npm", "start"] \ No newline at end of file diff --git a/Dockerfile.tornjak-container b/Dockerfile.tornjak-container index 17d4367e..9f19b60b 100644 --- a/Dockerfile.tornjak-container +++ b/Dockerfile.tornjak-container @@ -20,8 +20,11 @@ ENV REACT_APP_AUTH_SERVER_URI $REACT_APP_AUTH_SERVER_URI ARG NODE_OPTIONS=--openssl-legacy-provider ENV NODE_OPTIONS $NODE_OPTIONS -EXPOSE 3000 -EXPOSE 10000 +# front-end port +ENV PORT_FE=3000 +# back-end port +ENV PORT_BE=10000 +EXPOSE $PORT_FE $PORT_BE # start app ENTRYPOINT ["/opt/spire/run_tornjak.sh"] diff --git a/USAGE.md b/USAGE.md index e1363bf6..a38cb0a8 100644 --- a/USAGE.md +++ b/USAGE.md @@ -46,12 +46,14 @@ The frontend is meant to connect to either the Tornjak backend or the Tornjak ma | `NODE_OPTIONS` | Node options for npm start | `--openssl-legacy-provider` | `--openssl-legacy-provider` | false | | `REACT_APP_TORNJAK_MANAGER` | Boolean for whether the connected server is a manager | `false` | `true` | false | | `REACT_APP_AUTH_SERVER_URI` | URI for the Keycloak instance to obtain access tokens | | `http://localhost:8080` | false | +| `PORT_FE` | Port for the frontend to run | `3000` | `3000` | true | +| `PORT_BE` | Port for the backend to run | `10000` | `10000` | true | ``` -docker run -p 3000:3000 -e REACT_APP_API_SERVER_URI='http://localhost:50000' -e REACT_APP_TORNJAK_MANAGER=true ghcr.io/spiffe/tornjak-fe:latest +docker run -p 3000:8080 -e REACT_APP_API_SERVER_URI='http://localhost:50000' -e REACT_APP_TORNJAK_MANAGER=true -e PORT_FE-8080 ghcr.io/spiffe/tornjak-fe:latest ``` -The above command is an example of how to run the frontend. This creates a UI available at http://localhost:3000 forwarded from container port 3000. It is listening to a Tornjak manager component available at http://localhost:50000, and knows to run in manager mode with the `REACT_APP_TORNJAK_MANAGER` flag. +The above command is an example of how to run the frontend. This creates a UI available at http://localhost:3000 forwarded from container port `8080`. It is listening to a Tornjak manager component available at http://localhost:50000, and knows to run in manager mode with the `REACT_APP_TORNJAK_MANAGER` flag. ## Tornjak @@ -60,10 +62,10 @@ This container may be used as an alternative to having a frontend and backend co An example command: ``` -docker run -p 10000:10000 -p 3000:3000 -e REACT_APP_API_SERVER_URI='http://localhost:10000' ghcr.io/spiffe/tornjak:latest -c -t +docker run -p 10000:10000 -p 3000:8080 -e REACT_APP_API_SERVER_URI='http://localhost:10000' -e PORT_FE-8080 -e PORT_BE-10000 ghcr.io/spiffe/tornjak:latest -c -t ``` -The above command creates a UI available at `http://localhost:3000` forwarded from container port 3000. It is listening to the Tornjak backend at `http://localhost:10000`, as given by the `REACT_APP_API_SERVER_URI` value. At the same time, the container is exposing port 10000 for the backend, which reads the SPIRE config and Tornjak config at `` and `` respectively. +The above command creates a UI available at `http://localhost:3000` forwarded from container port `8080`. It is listening to the Tornjak backend at `http://localhost:10000`, as given by the `REACT_APP_API_SERVER_URI` value. At the same time, the container is exposing port `10000` for the backend, which reads the SPIRE config and Tornjak config at `` and `` respectively. NOTE: The value of `REACT_APP_API_SERVER_URI` must be a URI that is separately available to any browser that accesses the frontend. Therefore, in production environments, it is necessary that backend service endpoint be public. diff --git a/tornjak-frontend/package-lock.json b/tornjak-frontend/package-lock.json index 4413e9e6..9f22aa71 100644 --- a/tornjak-frontend/package-lock.json +++ b/tornjak-frontend/package-lock.json @@ -25114,16 +25114,16 @@ } }, "node_modules/typescript": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.3.tgz", - "integrity": "sha512-xv8mOEDnigb/tN9PSMTwSEqAnUvkoXMQlicOb0IUVDBSQCgBSaAAROUZYy2IcUy5qU6XajK5jjjO7TMWqBTKZA==", + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { - "node": ">=12.20" + "node": ">=4.2.0" } }, "node_modules/ua-parser-js": { @@ -47052,9 +47052,9 @@ } }, "typescript": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.3.tgz", - "integrity": "sha512-xv8mOEDnigb/tN9PSMTwSEqAnUvkoXMQlicOb0IUVDBSQCgBSaAAROUZYy2IcUy5qU6XajK5jjjO7TMWqBTKZA==", + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "peer": true }, "ua-parser-js": { diff --git a/tornjak-frontend/package.json b/tornjak-frontend/package.json index b09e4ce0..cb40a4de 100644 --- a/tornjak-frontend/package.json +++ b/tornjak-frontend/package.json @@ -62,7 +62,7 @@ "@babel/preset-env": "^7.15.6" }, "scripts": { - "start": "react-scripts start --openssl-legacy-provider", + "start": "PORT=$PORT_FE react-scripts start --openssl-legacy-provider", "build": "react-scripts build", "build:staging": "env-cmd -f .env.staging npm run build", "test": "react-scripts test",