Skip to content
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

🔧 [fix] Fix Port Mapping Issue #62

Merged
merged 6 commits into from
Nov 27, 2024
Merged

Conversation

KagemniKarimu
Copy link
Contributor

Checklist:

Important

Please review the checklist below before submitting your pull request.

  • Please open an issue before creating a PR or link to an existing issue
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas

Description

This PR restores functionality to port assignment for manuscript initializations and deployments. I removed redundant code in createDockerComposeFile function, fixed overlapping ports issue during manuscript initialization, moved port verification to a common package for better organization, added port validation before manuscript deployment, and enhanced port initialization for Docker Compose.

The MAJOR THEME was to do the following:
1- check that ports aren't already in use by docker/system before assigning
2- assure ports have been assigned with additional validation measures

More granularly, I did the following:

  • Refactored to use pkg.InitializePorts function for assigning ports, improving code maintainability.
  • Enhanced pkg.GetListeningPorts() to prevent port conflicts by considering both system and docker container
    ports.
  • Transferred all port verification logic to common_command.go in the pkg package for better code
    organization & consistency.
  • Implemented port validation before deploying manuscripts to ensure correct port assignments. (New Deployment Step)

Fixes #60

As always, please check behind my work 😅

Type of Change

  • Bug fix

This commit adds significant logging for debugging as well as port initialization if a specified port is not found in the existing config file.
This commit validates and assigns ports before deploying manuscripts, ensuring that ports for graphQL , the database, and the manuscript itself are all properly assigned.
This commit moves the port verification out of deploy manuscript and into the common_command.go file in the pkg package. The idea would be to gradually migrate common methods to a single source so that the script is easier to follow and debug.
This commit modifies GetListeningPorts() in common_command.go so as to make it more robust. Instead of just looking at  system ports. It evaluates docker container ports and system ports comprehensively to ensure that port conflicts don't occur. It also continues the migration of system functionality to the common_command.go inside pkg package for better encapsulation.
Applied principle of D.R.Y. - don't repeat yourself - to init_manuscripts.go. Now, instead of reusing similar logic to assign ports, it uses the common pkg.InitialzePorts function on the manuscript  to assign new ports. This is a significantly cleaner implementation as it means that we'll only need to change the logic  in one location going forward.
Due to previous commmits, the FindAvailablePort() is now defined in pkg/common_command.go and no longer needs to be put here in init_manuscript.go. It is now being removed for clarity.
@Liquidwe Liquidwe merged commit 7084741 into chainbase-labs:main Nov 27, 2024
1 of 2 checks passed
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.

Port Mapping Issue: Manuscript Deployment Defaults to localhost:0
2 participants