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

sql: Apply recommended cluster settings and sql statements to Docker image via env var #134429

Open
eddumelendez opened this issue Nov 6, 2024 · 4 comments
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) O-community Originated from the community T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) X-blathers-triaged blathers was able to find an owner

Comments

@eddumelendez
Copy link

eddumelendez commented Nov 6, 2024

Is your feature request related to a problem? Please describe.
Cockroach documentation makes a recommendation regarding additional cluster settings and sql statements but those have to be applied manually. See https://www.cockroachlabs.com/docs/stable/local-testing#use-a-local-single-node-cluster-with-in-memory-storage

Describe the solution you'd like
It would be nice to have an env var that once set would apply those improvements automatically.

Describe alternatives you've considered
Always let the users declare those improvements.

Additional context
Testcontainers offers a CockroachDb module and
there is a PR in Testcontainers for Go in order to apply those improvements but a more portable solution to other Testcontainers implementation would be the env var.

Jira issue: CRDB-44078

@eddumelendez eddumelendez added the C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) label Nov 6, 2024
Copy link

blathers-crl bot commented Nov 6, 2024

Hello, I am Blathers. I am here to help you get the issue triaged.

I have CC'd a few people who may be able to assist you:

  • @cockroachdb/sql-foundations (found keywords: sql statement)

If we have not gotten back to your issue within a few business days, you can try the following:

  • Join our community slack channel and ask on #cockroachdb.
  • Try find someone from here if you know they worked closely on the area and CC them.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@blathers-crl blathers-crl bot added O-community Originated from the community X-blathers-triaged blathers was able to find an owner labels Nov 6, 2024
@ZhouXing19 ZhouXing19 added the T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) label Nov 7, 2024
@ZhouXing19 ZhouXing19 changed the title Apply recommended cluster settings and sql statements to Docker image via env var sql: Apply recommended cluster settings and sql statements to Docker image via env var Nov 7, 2024
@ZhouXing19
Copy link
Collaborator

Thanks for filing this issue, @eddumelendez! We've reviewed and triaged this feature request, and we’ll keep you updated with any progress.

As a workaround specifically for Docker containers, you can place the initialization SQL script in a file and mount it to the container. This will ensure the script runs automatically when the single-node server starts. You can find more details on this approach here.

You can optionally mount a directory of initialization scripts into the docker-entrypoint-initdb.d directory within the container. These scripts are run after CockroachDB starts and after the database and user (if specified as environment variables) have been created. The scripts run in the alphanumeric sort order imposed by your locale. The init scripts are run only if the /cockroach/cockroach-data directory within the container is empty.

For example, if you need to apply the recommended cluster settings, you can add the corresponding SQL statements to an SQL script, such as /your/path/init.sql, and mount the directory with:

-v /your/path:/docker-entrypoint-initdb.d

in your docker run command.

Let us know if this helps, and feel free to reach out with further questions!

@stevenh
Copy link

stevenh commented Nov 7, 2024

Thanks @ZhouXing19 we already have option for init scripts in other modules, so we can investigate how we could leverage that behaviour.

@eddumelendez
Copy link
Author

Thanks @ZhouXing19! There was an issue reported related to database initialization in the past in the Testcontainers for Java implementation that I just fixed it testcontainers/testcontainers-java#9505. It works for versions >= 22.1.0 because since that version we can identified when scripts were executed. So, with that users can rely on database initialization provided by the image. We need to apply this to Testcontainers for Go as well. But, would be nice if users can opt-in to this as initially suggested. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) O-community Originated from the community T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) X-blathers-triaged blathers was able to find an owner
Projects
None yet
Development

No branches or pull requests

3 participants