-
Notifications
You must be signed in to change notification settings - Fork 153
feat: allow ports to be customised via env vars #379
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
Conversation
✅ Deploy Preview for endearing-brigadeiros-63f9d0 canceled.
|
lwhiteley
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from the changes it looks good,
i dont see any reason why it wouldnt work.
I wont be able to test it until next week either way. [reviewing from phone]
maybe someone else can test to not hold it up
src/proxy/index.js
Outdated
| const config = require('../config'); | ||
| const db = require('../db'); | ||
| const proxyHttpPort = 8000; | ||
| const proxyHttpPort = process.env.GIT_PROXY_SERVER_PORT || 8000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given there are more than 2 files affected here, it may be better to create a file to setup the environment variables and their defaults to avoid future mistakes
for eg.
// file path: src/common/env.js
const {
GIT_PROXY_SERVER_PORT = 8000,
GIT_PROXY_UI_PORT = 8080
} = process.env
export { GIT_PROXY_SERVER_PORT, GIT_PROXY_UI_PORT}then here:
| const proxyHttpPort = process.env.GIT_PROXY_SERVER_PORT || 8000; | |
| const { GIT_PROXY_SERVER_PORT: proxyHttpPort } = require('../common/env') |
similar for other files.
this way the defaults are only defined in one place and easier to maintain.
you can then further use this when reading the file config somehow later given its all in one place
| By default, Git Proxy uses port 8000 to expose the Git Server and 8080 for the UI frontend; | ||
| you can change ports by setting the `GIT_PROXY_SERVER_PORT` and `GIT_PROXY_UI_PORT` | ||
| environment variables. | ||
|
|
||
| Note that `GIT_PROXY_UI_PORT` is needed for both server and UI Node processes, | ||
| whereas `GIT_PROXY_SERVER_PORT` is only needed by the server process. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[optional]
maybe also add an example of how to set the env vars via command line
|
@lwhiteley - all good suggestions, thanks! I've pushed changes following your suggestions. @JamieSlome @coopernetes - please review/text at your earliest convenience. TY! |
Co-authored-by: Layton Whiteley <layton.w@smart-host.com>
Co-authored-by: Layton Whiteley <layton.w@smart-host.com>
coopernetes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - as a future enhancement, we should expose the server ports as both file-based config (via proxy.config.json) as well as environment variables. We should have this available for all our configurable values, merge or reconcile between the two sources and allow users to choose whichever method best suits their deployment to configure ports & other values.
Co-authored-by: Thomas Cooper <coopernetes@proton.me>
|
Can we look to include some test functionality to demonstrate the usage and successful loading of ports via ENV? |
JamieSlome
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice PR! 👍
I've made a couple of comments and mentioned in a previous commit that a test case would be great prior to merge.
Thank you @maoo @lwhiteley 🍰
Co-authored-by: Jamie Slome <jamie.slome@citi.com>
custom ports is still failing tho
|
Added tests, but when testing custom ports, the test fails; I think that the problem is how I'm stubbing environment variables in |
|
Thanks @lwhiteley - that's the same code I did, and yes, the tutorial I followed used Jest; I didn't really think that mocha would not work. Re. e2e testing, I agree with you, but the issue with env var setup would still be there. I've tried several approaches, including https://medium.com/nodejsmadeeasy/elegant-ways-to-pass-env-variables-to-mocha-test-cases-4486cb238bb1 and https://glebbahmutov.com/blog/mocking-process-env/ I'll sleep on it and see if next week I can find a working solution. @JamieSlome - did you face this issue in the past with mocha? And is there any e2e testing where we can add the custom port testing? |
|
Yup but I don't mean in a spec runner like jest or mocha where you have to manipulate the require cache. It may be possible to setup jobs that simulate how the end user would test it in CI and just provide the env vars there to confirm by pinging the running services. |
|
I see that @coopernetes raised #394 - so maybe we could simply skip the e2e part on this PR and tackle this challenge in a separate issue/PR ? WDYT? |
|
@maoo - sounds good 👍 Feel free to remove the test(s) and we can get this merged 🍰 |
JamieSlome
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ready to merge 👍
|
Thanks for stepping in @JamieSlome ! |
feat: allow ports to be customised via env vars
Closes #378
To test this PR:
You should see: