-
Notifications
You must be signed in to change notification settings - Fork 511
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
Add initial support for PostgreSQL #920
Conversation
do | ||
iter=$(( iter+1 )) | ||
if [[ $iter -gt 30 ]]; then | ||
echo "notaryserver database failed to come up within 30 seconds" | ||
exit 1; | ||
fi | ||
echo "waiting for notarymysql to come up." | ||
echo "waiting for $DB_URL to come up." |
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.
Looks like you're using spaces here (and a couple of other places), should be tabs in shell scripts 😄
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.
there goes my secret plan to convert tabs to spaces.
Thanks! I'll leave code-review to the notary team, but I like PostgreSQL, so 😍 |
6236002
to
961d11f
Compare
@dqminh thank you for adding this feature! Could you please rebase? I think you're hitting a linter CI issue that we addressed a few days ago. We should have a testing infrastructure for postgres if we choose to support it - I think a good starting point would be adding a case to |
@riyazdf i cant get the integration test to pass in my local environment. Is there any special tricks ? Here is part of the build failure with rethinkdb as an example:
For mysql, it's either this or it timed out when trying to reach the server. |
Actually ignore my comment - totally misread, sorry. :( |
Could you instead change: https://github.com/docker/notary/blob/master/buildscripts/testclient.py#L100 to say
This should hopefully print out debug output for the client so we can see why it can't connect with the server, although the client debug logs and the actual client output may be slightly out of sync. |
So it looks like something is probably wrong with DNS inside my VM. Amazingly enough when i tried it with Docker for Mac it works 😵 |
) | ||
|
||
func init() { | ||
// Get the MYSQL connection string from an environment variable |
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.
nit typo: "PostgreSQL"
5b77699
to
c791dfd
Compare
jenkins, test this please |
}, | ||
"storage": { | ||
"backend": "postgres", | ||
"db_url": "postgres://server@serverdb:5432/notaryserver?sslmode=disable" |
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.
Non-blocking: if you know of a good/easy way to add SSL certs to the postgres server, that would be awesome, but from reading the docs it looks like we'd probably have to set the PGDATA
directory to a local volume, and I'm not sure whether that's a good idea.
LGTM! Thank you adding this! |
DB_URL: postgres://signer@signerdb:5432/notarysigner?sslmode=disable | ||
depends_on: | ||
- signerdb | ||
serverdb: |
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.
Would be good for consistency to handle these the same way we do with MySQL, a single DB container with multiple databases.
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.
i would argue that this setup is actually better in term of separation. After all the official docs says that signer and server db should be separated :p
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.
If we can agree these compose files are for dev and testing, which they are, then having a single database server instance makes it much more convenient for us to inspect state and even docker commit
a single running database container to preserve specific states we may want to share for debugging/demonstration purposes.
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.
using single image also means that we need to bootstrap two different database with extra scripts similar to notarymysql
. But the CHANGELOG also stated that:
+ Update `docker-compose` configuration to use official mariadb image
+ deprecate `notarymysql`
+ default to using a volume for `data` directory
+ use separate databases for `notary-server` and `notary-signer` with separate users
I can add extra bootstrap scripts, but i just think its cleaner this way. I also dont think commiting two databases are much harder than one.
But IANAM, Let me know what you think.
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.
What we want as maintainers is a consistent way to do things, and in this instance, you have created something that differs from the most similar existing example in the repo, mariadb.
You should have no reason to create a notarypostgres
image, and we would ask you to change it if you did. We deprecated notarymysql
(which was at one point a custom database image) because there was no need for us to use a custom built image when we could simply use the official images and their built in bootstrapping, speeding up our build and test times. Postgres has this same built in boostrapping as mariadb, you can find the instructions under "How to extend this image", and an example of our basic setup for mariadb, which should be very similar, here.
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.
updated. PTAL.
Thank you for updating the postgres database setup. I realize I probably seem like I'm being unreasonably pedantic, but as a maintainer, we are responsible for all the code in the repo, including that contributed by external contributors who may not be available in the future to make changes. As such, we have to make conscious efforts to reduce variation, which is unnecessary complexity, so we can mentally stay on top of all the necessary complexity. We're taking a look at why the ineffassign checks are suddenly failing. I have some time already scheduled tomorrow afternoon to do some related style housekeeping so I'll open a PR to fix those assuming we don't find some other reason ineffassign started raising errors. |
@dqminh thanks for your work on this! Could you please rebase? I think that should handle the unrelated CI issues :) This LGTM on green, though I'd like @endophage to take a last look before merge |
@@ -90,7 +91,7 @@ func getStore(configuration *viper.Viper, hRegister healthRegister, doBootstrap | |||
switch backend { | |||
case notary.MemoryBackend: | |||
return storage.NewMemStorage(), nil | |||
case notary.MySQLBackend, notary.SQLiteBackend: | |||
case notary.MySQLBackend, notary.SQLiteBackend, notary.PostgresBackend: |
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.
Hi @dqminh would you mind also update the relative configuration docs about this backend, it's OK to do it in a separated PR, but we may forget to update it.
} | ||
|
||
for i := 0; i < 30; i++ { | ||
gormDB, err := gorm.Open("postgres", dburl) |
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.
same here
Thanks for your contribution @dqminh ! It seems need a rebase here :) |
af8fda8
to
ef46d84
Compare
@dqminh sorry we're taking a while to merge this. If you want to enable the new GH feature that lets maintainers modify your branch we'll happily do the last rebase and work out any failures so we can get it merged. |
@endophage @HuKeping i already did that :p not sure if how its reflected on your side though. |
Hmmm, yeah, not seeing anything on my end. I guess I have to just try and push and see if it works. |
ef46d84
to
6d6f8e0
Compare
this adds support for specifying backend=postgres in storage option in addition to mysql and sqlite. Since notary uses gorm and doesnt use any fancy column type, this probably should work out of the box. Signed-off-by: Daniel Dao <dqminh89@gmail.com>
- this changes migrate.sh script to accept a custom migration path and db url ( defaults to mysql settings) to we can inject postgresql settings to it. - add migration files for postgresql. - add compose file for postgresql. Run it with `docker-compose -f docker-compose.postgresql.yml`. Signed-off-by: Daniel Dao <dqminh89@gmail.com>
Signed-off-by: Daniel Dao <dqminh89@gmail.com>
Signed-off-by: Daniel Dao <dqminh89@gmail.com>
Signed-off-by: Daniel Dao <dqminh89@gmail.com>
- add a few entrypoint scripts for postgresql - rename existing notarymysql folders Signed-off-by: Daniel Dao <dqminh89@gmail.com>
Signed-off-by: Daniel Dao <dqminh89@gmail.com>
…g directly Signed-off-by: Daniel Dao <dqminh89@gmail.com>
Signed-off-by: Daniel Dao <dqminh89@gmail.com>
Signed-off-by: Hu Keping <hukeping@huawei.com>
875f661
to
12ec489
Compare
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, pending CI
gormDB, err := gorm.Open("mysql", dburl) | ||
if err == nil { | ||
err := gormDB.DB().Ping() | ||
if err == nil { | ||
break | ||
} | ||
} | ||
if i == 29 { | ||
if i == 30 { |
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.
This was already correctly retrying 30 times. The updated version will attempt 31 times. The iteration is zero indexed so when you reach line 33, gorm.Open
at line 26 will have been called i + 1
times for any given iteration. Therefore, when i == 29
, gorm.Open
has been attempted 30 times.
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.
@endophage you are right about the iteration, no matter using 30
or 29
, I think it is used for line 34 to log out how much time has been past.
Because of the sleep statement
is at the end of this for
loop, so when i == 30
and the process reaches line 34 to log out sth, we may have just sleep 30 times, thus 60 seconds.
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.
Yeah, I'm not overly bothered which it is in this case, just wanted to be clear the commit message isn't correct and it's a somewhat superfluous commit.
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.
I'm agree with you @endophage , the commit message"properly retry 30 times in mysql|postgresql_test" is not correct.
LGTM |
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.
And LGTM again because new GH features :-/
Thank you for your work on this @dqminh ! |
Closes #600
As title stated :)
A quick run with
docker-compose -f docker-compose.postgresql.yml up
and testing with a local docker client pushing to local registry doesn't show any errors so hopefully i didn't miss anything.cc @thaJeztah @endophage