-
-
Notifications
You must be signed in to change notification settings - Fork 118
Add script for D2D with SCIO using docker container #1912
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Tushar Goel <[email protected]>
| def get_free_port(): | ||
| """Find a free host port for Postgres.""" | ||
| with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | ||
| s.bind(("", 0)) |
Check warning
Code scanning / CodeQL
Binding a socket to all network interfaces Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 days ago
To fix this issue, you should replace the empty string '' used in s.bind(("", 0)) with the loopback interface IP '127.0.0.1'. This will cause the socket to bind only to localhost, reducing exposure by ensuring the port is only allocated on the local interface. The rest of the function can remain unchanged since the purpose is solely to obtain an available port number. The change should be made in the get_free_port function, specifically at line 96. No additional imports or method modifications are needed.
-
Copy modified line R96
| @@ -93,7 +93,7 @@ | ||
| def get_free_port(): | ||
| """Find a free host port for Postgres.""" | ||
| with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | ||
| s.bind(("", 0)) | ||
| s.bind(("127.0.0.1", 0)) | ||
| return s.getsockname()[1] | ||
|
|
||
|
|
Output with the following script. |
Signed-off-by: Tushar Goel <[email protected]>
Signed-off-by: Tushar Goel <[email protected]>
Signed-off-by: Tushar Goel <[email protected]>
|
For simplicity and safety, I would consider using Docker compose to handle the database service. You can create a new docker-compose.yml that has scanpipe and the database, something along the lines of: You can run scanpipe commands by doing |
Signed-off-by: Tushar Goel <[email protected]>
| def get_free_port(): | ||
| """Find a free host port for Postgres.""" | ||
| with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | ||
| s.bind(("", 0)) |
Check warning
Code scanning / CodeQL
Binding a socket to all network interfaces Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 days ago
General fix:
Instead of binding the test socket to all interfaces (using ''), bind it specifically to the loopback interface (using '127.0.0.1'). This restricts the socket from being accessible on external interfaces, even for the short lifetime of this test binding.
Best way to fix:
In the get_free_port() function, replace s.bind(("", 0)) with s.bind(("127.0.0.1", 0)). This changes only the test socket binding, preserving all existing behavior and functionality.
File/region to change:
File: etc/scripts/d2d/run_d2d_scio.py, line 54 (“s.bind(("", 0))”).
What is needed:
- Edit the socket bind call.
- No new imports or additional code changes are required.
-
Copy modified line R54
| @@ -51,7 +51,7 @@ | ||
| def get_free_port(): | ||
| """Find a free host port for Postgres.""" | ||
| with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | ||
| s.bind(("", 0)) | ||
| s.bind(("127.0.0.1", 0)) | ||
| return s.getsockname()[1] | ||
|
|
||
|
|
|
|
I agree with @JonoYang, we do not want to re-invent orchestration here. Also, in case of a simple one-off pipeline run, what about using the dedicated
The Running it would looks somthing like this: |
|
When I use above docker compose file with run command, I get this error. |
|
@TG1999 #1916 merged and released https://github.com/aboutcode-org/scancode.io/releases/tag/v35.4.1 Documented at https://scancodeio.readthedocs.io/en/latest/quickstart.html#use-postgresql-for-better-performance Pull the latest ScanCode.io Docker imageStart a PostgreSQL Database ServiceStop the service with Run the
|
Closes:
Related: