Skip to content

Conversation

@maoo
Copy link
Member

@maoo maoo commented Jan 1, 2024

Closes #378

To test this PR:

npm install -g
export GIT_PROXY_UI_PORT="5000"
export GIT_PROXY_SERVER_PORT="9090"
git-proxy

You should see:

Service Listening on 5000
Listening on 9090

@maoo maoo requested review from JamieSlome and coopernetes January 1, 2024 11:36
@netlify
Copy link

netlify bot commented Jan 1, 2024

Deploy Preview for endearing-brigadeiros-63f9d0 canceled.

Name Link
🔨 Latest commit 8d0ec57
🔍 Latest deploy log https://app.netlify.com/sites/endearing-brigadeiros-63f9d0/deploys/65a1168b5c01ce0008c8347d

Copy link
Contributor

@lwhiteley lwhiteley left a 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

const config = require('../config');
const db = require('../db');
const proxyHttpPort = 8000;
const proxyHttpPort = process.env.GIT_PROXY_SERVER_PORT || 8000;
Copy link
Contributor

@lwhiteley lwhiteley Jan 1, 2024

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:

Suggested change
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

Comment on lines 47 to 52
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.
Copy link
Contributor

@lwhiteley lwhiteley Jan 1, 2024

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

@maoo
Copy link
Member Author

maoo commented Jan 2, 2024

@lwhiteley - all good suggestions, thanks! I've pushed changes following your suggestions.

@JamieSlome @coopernetes - please review/text at your earliest convenience. TY!

maoo and others added 2 commits January 2, 2024 20:09
Co-authored-by: Layton Whiteley <layton.w@smart-host.com>
Co-authored-by: Layton Whiteley <layton.w@smart-host.com>
Copy link
Contributor

@coopernetes coopernetes left a 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.

maoo and others added 2 commits January 3, 2024 20:30
Co-authored-by: Thomas Cooper <coopernetes@proton.me>
@maoo maoo marked this pull request as ready for review January 3, 2024 21:48
@JamieSlome
Copy link
Member

Can we look to include some test functionality to demonstrate the usage and successful loading of ports via ENV?

Copy link
Member

@JamieSlome JamieSlome left a 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 🍰

maoo and others added 2 commits January 5, 2024 16:32
Co-authored-by: Jamie Slome <jamie.slome@citi.com>
custom ports is still failing tho
@maoo
Copy link
Member Author

maoo commented Jan 5, 2024

Added tests, but when testing custom ports, the test fails; I think that the problem is how I'm stubbing environment variables in testConfig.js

@maoo
Copy link
Member Author

maoo commented Jan 5, 2024

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?

@lwhiteley
Copy link
Contributor

lwhiteley commented Jan 5, 2024

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.

@maoo
Copy link
Member Author

maoo commented Jan 11, 2024

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?

@JamieSlome
Copy link
Member

@maoo - sounds good 👍 Feel free to remove the test(s) and we can get this merged 🍰

Copy link
Member

@JamieSlome JamieSlome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready to merge 👍

@JamieSlome JamieSlome merged commit cda57c3 into main Jan 12, 2024
@JamieSlome JamieSlome deleted the custom-ports branch January 12, 2024 10:41
@maoo
Copy link
Member Author

maoo commented Jan 12, 2024

Thanks for stepping in @JamieSlome !

Psingle20 pushed a commit to Psingle20/git-proxy that referenced this pull request Nov 27, 2024
feat: allow ports to be customised via env vars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make service ports configurable

4 participants