Skip to content

Extract host and port from DB_HOST also support DB_PORT to test connection instead of only use default port 3306 #136

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

Merged
merged 15 commits into from
Dec 22, 2022

Conversation

thohng
Copy link
Contributor

@thohng thohng commented Sep 23, 2022

linuxserver.io


  • I have read the contributing guideline and understand that I have made the correct modifications

Description:

Improve Bookstack app startup from 30 seconds delayed and trying if the connection to MySQL DB_HOST use the non default port 3306.

Benefits of this PR and context:

To fix issue #135
It will extract the actual host and port from DB_HOST and provide to the nc process.
This will support DB_HOST using the endpoint format or host only (with default port 3306):

  • DB_HOST=hostOrFQDN
  • DB_HOST=hostOrFQDN:port

Limitations: not support host IPv6

How Has This Been Tested?

Has been tested by mount the new file to the file in docker container

environment:
  - APP_URL=https://domain
  - DB_HOST=10.109.0.2:25060
  - DB_USER=user
  - DB_PASS=password
  - DB_DATABASE=database_name
volumes:
  - /opt/bookstack/config:/config
  - /opt/bookstack/develop/50-config:/etc/cont-init.d/50-config

Logs after fixed

.....
Running config - db_user set
/var/run/s6/etc/cont-init.d/50-config: line 98: warning: command substitution: ignored null byte in input
/var/run/s6/etc/cont-init.d/50-config: line 98: warning: command substitution: ignored null byte in input
Nothing to migrate.
[cont-init.d] 50-config: exited 0.
....

image

Source / References:

N/A

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thanks for opening this pull request! Be sure to follow the pull request template!

@LinuxServer-CI
Copy link
Collaborator

@thohng
Copy link
Contributor Author

thohng commented Sep 23, 2022

Properly support specific non default port 3306 in DB_HOST and also improve experience for these issues #31, #86 and #88 without working around.

@drizuid
Copy link
Member

drizuid commented Oct 4, 2022

I'm a bit unsure why we didn't have DB_PORT as an envvar like other similar containers, and while I like this change a lot, it's inconsistent with our other containers which would have the user specify db_port in compose. we'll discuss this a bit internally.

@thohng
Copy link
Contributor Author

thohng commented Oct 8, 2022

If we prefer to use DB_PORT, I can submit the PR to support DB_PORT and also solve the 30s delay. I just checked on BookStack, it support both DB_PORT or DB_HOST with port, and port in DB_HOST will take precedence.

https://github.com/BookStackApp/BookStack/blob/development/app/Config/database.php#L45

// MYSQL
// Split out port from host if set
$mysql_host = env('DB_HOST', 'localhost');
$mysql_host_exploded = explode(':', $mysql_host);
$mysql_port = env('DB_PORT', 3306);
if (count($mysql_host_exploded) > 1) {
    $mysql_host = $mysql_host_exploded[0];
    $mysql_port = intval($mysql_host_exploded[1]);
}

@drizuid
Copy link
Member

drizuid commented Oct 8, 2022

that would be fine i think. If you take a look at netbox (we have others but netbox is the only one popping into my mind right now) you can see how we are handling DB_PORT, obviously consistency is our goal. I'll make sure this repo is marked for hacktoberfest too, so you can get some credit :)

@LinuxServer-CI
Copy link
Collaborator

@thohng
Copy link
Contributor Author

thohng commented Oct 8, 2022

Update PR to support DB_PORT

  • Insert default line DB_PORT=3306 to .env if missing. The current .env.example does not have line DB_PORT=3306
  • Use port from DB_HOST if any
  • If no port on DB_HOST, will use DB_PORT if provided, or DB_PORT will be default 3306

The issue #135 is fixed both case port on DB_HOST or DB_PORT provided

image

@thohng thohng changed the title Extract host and port from DB_HOST to test connection instead of only use default port 3306 Extract host and port from DB_HOST also support DB_PORT to test connection instead of only use default port 3306 Oct 8, 2022
@LinuxServer-CI
Copy link
Collaborator

@LinuxServer-CI
Copy link
Collaborator

@LinuxServer-CI
Copy link
Collaborator

@drizuid drizuid requested a review from a team October 10, 2022 12:17
@LinuxServer-CI
Copy link
Collaborator

@LinuxServer-CI
Copy link
Collaborator

@drizuid drizuid requested a review from a team October 11, 2022 11:53
@drizuid
Copy link
Member

drizuid commented Oct 11, 2022

I've asked the team to review the changes, if this was JUST adding DB_PORT i would've merged it but since it also includes the logic for <address>:<port> I'll need team consensus.

Copy link
Member

@nemchik nemchik left a comment

Choose a reason for hiding this comment

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

Please review NetLah-external#1

@thohng
Copy link
Contributor Author

thohng commented Oct 11, 2022

Please review NetLah-external#1

Hi Eric Nemchik,
I would fix the Alpine 3.15 not support grep -qP and improve the support to domain:port or [::1]:port or [1:2::7:8]:port
Please help review #141

@LinuxServer-CI
Copy link
Collaborator

1 similar comment
@LinuxServer-CI
Copy link
Collaborator

@jaytomten
Copy link

Awesome. Waiting on this update.

@LinuxServer-CI
Copy link
Collaborator

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@thohng
Copy link
Contributor Author

thohng commented Dec 15, 2022

Hi, can we help preview and merge this PR? This PR is not just improvement to support the DB_PORT but also fix the issue that connection can update from docker environment variable to file /config/www/.env. Thanks!

@LinuxServer-CI
Copy link
Collaborator

@nemchik
Copy link
Member

nemchik commented Dec 21, 2022

@thohng Please check my review comment above requesting small changes. I believe this is nearly ready. Once those changes are made we will re-review and merge this.

# Conflicts:
#	root/etc/cont-init.d/50-config
@LinuxServer-CI
Copy link
Collaborator

@thohng
Copy link
Contributor Author

thohng commented Dec 22, 2022

@thohng Please check my review comment above requesting small changes. I believe this is nearly ready. Once those changes are made we will re-review and merge this.

Hi Eric Nemchik, I actually have merged your improvement NetLah-external#1 2 months ago, and the PR is ready, but that time I have not triggered the re-review. Please help preview again.

The recent merge PR #151 actually already in my PR 2 months ago, to fix the issue that .env not update again when db info changed (like changing on host, port, username, or password after first time initialized)

I also resolved the conflicts by the PR 151 recently.

@thohng thohng requested a review from nemchik December 22, 2022 03:37
@nemchik
Copy link
Member

nemchik commented Dec 22, 2022

Wow, I had a pending review that I did not submit. That's entirely my fault. Sorry!

Avoid grep -E, change to regex

Co-authored-by: Eric Nemchik <eric@nemchik.com>
@LinuxServer-CI
Copy link
Collaborator

@thohng thohng requested a review from nemchik December 22, 2022 14:27
Copy link
Member

@nemchik nemchik left a comment

Choose a reason for hiding this comment

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

LGTM

@thohng thohng requested a review from aptalca December 22, 2022 16:34
@LinuxServer-CI
Copy link
Collaborator

@nemchik nemchik merged commit c075b28 into linuxserver:master Dec 22, 2022
@thohng
Copy link
Contributor Author

thohng commented Dec 23, 2022

@thohng thohng deleted the improve-nc-mysql-host-port branch December 23, 2022 03:37
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.

7 participants