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

Pass all PG settings as env vars #990

Merged
merged 3 commits into from
Oct 23, 2024
Merged

Pass all PG settings as env vars #990

merged 3 commits into from
Oct 23, 2024

Conversation

evgeni
Copy link
Member

@evgeni evgeni commented Oct 18, 2024

@evgeni evgeni marked this pull request as draft October 18, 2024 10:47
hooks/pre/10-reset_data.rb Outdated Show resolved Hide resolved
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Btw, if we don't need to ensure we've escaped the Puppet Ruby env we don't need to format the command and you could use Open3 directly

def pg_sql_statement(config, statement)
pg_command_base(config, 'psql', "-d #{config[:database]} -t -c \"#{statement}\"")
def pg_sql_statement(statement)
"psql -t -c \"#{statement}\""
Copy link
Member

Choose a reason for hiding this comment

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

I'd be tempted to pass in the statement via stdin but wonder if that works well with runuser (if we do that)

Copy link
Member Author

Choose a reason for hiding this comment

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

runuser is only used for local sql, and there we don't need statements.

Copy link
Member Author

Choose a reason for hiding this comment

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

that said, our execute helpers don't do stdin right now, so it'd need more refactoring.

"PGPASSWORD='#{config[:password]}' #{command} -U #{config[:username]} -h #{config[:host]} -p #{config[:port]} #{args}"
def pg_env(config)
{
'PGHOST' => config.fetch(:host, 'localhost'),
Copy link
Member

Choose a reason for hiding this comment

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

Do we need a default or can we trust psql to figure it out?

Copy link
Member Author

Choose a reason for hiding this comment

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

No idea, copied from your fm patch ;)

Copy link
Member

Choose a reason for hiding this comment

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

There I had it because local? compares to localhost and I didn't want to change that. Perhaps we should make it more robust so it can parse any postgresql url. I'd like to be able to use unix sockets and ident auth but now we'd break foreman-maintain

Copy link
Member Author

Choose a reason for hiding this comment

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

Here we have remote_host?(hostname) which does something very similar.

The old code just assumed config[:host] is set (the command would be wrong if it were unset), which we can do here too?

Copy link
Member

Choose a reason for hiding this comment

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

I think keeping a default for localhost is OK for now then.

@evgeni
Copy link
Member Author

evgeni commented Oct 18, 2024

Btw, if we don't need to ensure we've escaped the Puppet Ruby env we don't need to format the command and you could use Open3 directly

Yeah, but our helpers incorporate the escaping and I like helpers ;)

@ekohl
Copy link
Member

ekohl commented Oct 18, 2024

You can pass an array and avoid any escaping

@evgeni evgeni force-pushed the pgenv branch 2 times, most recently from c4d76d4 to 0447a0d Compare October 21, 2024 08:49
@evgeni
Copy link
Member Author

evgeni commented Oct 21, 2024

You can pass an array and avoid any escaping

I meant the "escaping from Puppet ruby env".

My point is:

  • We have those helpers exactly to escape the Puppet ruby env, because we need it sometimes.
  • They also have logging and stuff wired in, which is nice
  • Our code is standardized on using those helpers
  • I do not want to have a special code that does not use the helpers, just because I don't need puppet-env-escaping.

So if we can drop the "puppet-env-escaping" all together, cool (but I think we can't, as we call f-m and f-rake, which need system ruby), but scope-creep. Here I just want to pass in PG things via env :)

@evgeni
Copy link
Member Author

evgeni commented Oct 21, 2024

/packit build

expect(context).to have_received(:'execute!').with("runuser -l postgres -c 'PGSETUP_INITDB_OPTIONS=\"--lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8 --locale=en_US.UTF-8\" postgresql-setup --upgrade'", false, true)
expect(context).to have_received(:'execute!').with("runuser -l postgres -c 'PGSETUP_INITDB_OPTIONS=\"--lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8 --locale=en_US.UTF-8\" postgresql-setup --upgrade'", false, true, {})
Copy link
Member Author

Choose a reason for hiding this comment

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

runuser -l clears the environment, so that's why I did not use the env stuff here too.

@evgeni evgeni marked this pull request as ready for review October 21, 2024 09:17
Gemfile Outdated Show resolved Hide resolved
@ekohl ekohl changed the title move PGPASSWORD to env Pass all PG settings as env vars Oct 22, 2024
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

I would appreciate a Redmine issue for this.

@evgeni
Copy link
Member Author

evgeni commented Oct 22, 2024

@ekohl done

@ekohl ekohl merged commit 97487cf into develop Oct 23, 2024
8 checks passed
@ekohl ekohl deleted the pgenv branch October 23, 2024 18:02
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.

2 participants