Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Add tutor [dev|local|k8s] do sqlshell command #51

Closed
1 of 4 tasks
kdmccormick opened this issue Feb 23, 2022 · 10 comments
Closed
1 of 4 tasks

Add tutor [dev|local|k8s] do sqlshell command #51

kdmccormick opened this issue Feb 23, 2022 · 10 comments
Assignees

Comments

@kdmccormick
Copy link
Collaborator

kdmccormick commented Feb 23, 2022

Background

In devstack, one could get a MySQL database prompt by:

  • entering make mysql-shell and then entering mysql at the container shell prompt.
  • entering make dev.dbshell to jump directly in.

or a MongoDB prompt by:

  • entering make mongo-shell and then entering mongo at the container shell prompt.

In Tutor, the equivalent command for MySQL is:

tutor dev exec mysql mysql --user="$(tutor config printvalue MYSQL_ROOT_USERNAME)" --password="$(tutor config printvalue MYSQL_ROOT_PASSWORD)"

and the equivalent command for Mongo is:

tutor dev exec mongodb mongo

We should make these commands simpler. Or, at the very least, we should document them.

Tasks

  • Wait unil the pluggable jobs interface is implemented.
  • Implement and document a new job (name suggestion: sqlshell) using the new CLI_DO_COMMANDS filter. The job should execute, in the mysql service:
    mysql --user='{{ MYSQL_ROOT_USERNAME }}' \
          --password='{{ MYSQL_ROOT_PASSWORD }}' \
          --host='{{ MYSQL_HOST }}' \
          --port='{{ MYSQL_PORT }}'
    
  • Test that the new job works in all three modes: tutor [dev|local|k8s] do sqlshell.
  • Document the job as a common local deployment task.
@kdmccormick
Copy link
Collaborator Author

@rgraber FYI

@kdmccormick
Copy link
Collaborator Author

@regisb This one's ready for your eyes now.

@kdmccormick kdmccormick moved this from Ungroomed (Kyle) to Ungroomed (Régis) in Tutor DevEnv Adoption (OLD BOARD) Feb 24, 2022
@regisb
Copy link

regisb commented Mar 10, 2022

Let me think out loud here:

  • run should be preferred over exec because there is no guarantee that the mysql container may be running. For instance, if the platform was not started.

  • Actually, even run may be problematic in the case when the user decided to host mysql separately (RUN_MYSQL=false). In this situation, there isn't even a "mysql" container declared in docker-compose.yml, so tutor dev run mysql would fail.

  • Thus, there is no solution that works in the general case...

  • ... but I agree that it would be very convenient to have a simple "local/dev/k8s mysqlrootshell" command.

  • Currently, the only image that comes with a mysql client is the "mysql" image. The "openedx" image does not ship with mysql-client. Thus ./manage.py lms dbshell fails.

  • If we added the "mysql-client" package to the "openedx" image we could access a db shell as root by running:

    tutor local run lms mysql --user=$(tutor config printvalue MYSQL_ROOT_USERNAME) --password=$(tutor config printvalue MYSQL_ROOT_PASSWORD) --host=$(tutor config printvalue MYSQL_HOST) --port=$(tutor config printvalue MYSQL_PORT)
    

Thus I suggest the following solution:

  1. Add the "mysql-client" to the "openedx" image.
  2. Add "local/dev/local dbshell" commands that would alias to the command above.

@kdmccormick kdmccormick moved this from Ungroomed (Régis) to Ungroomed (Kyle) in Tutor DevEnv Adoption (OLD BOARD) Mar 17, 2022
@kdmccormick kdmccormick moved this to Ungroomed (Kyle) in Tutor DevEnv Adoption May 17, 2022
@kdmccormick kdmccormick moved this from Ungroomed (Kyle) to Groomed in Tutor DevEnv Adoption May 17, 2022
@kdmccormick kdmccormick moved this from Groomed to Ungroomed (Régis) in Tutor DevEnv Adoption May 17, 2022
@kdmccormick kdmccormick moved this from Ungroomed (Régis) to Groomed in Tutor DevEnv Adoption May 17, 2022
@kdmccormick kdmccormick changed the title Explain in docs how to start a database shell Add tutor [dev|local|k8s] dbshell command Jun 23, 2022
@kdmccormick
Copy link
Collaborator Author

@regisb I like that solution. I updated the acceptance criteria, can you take a look and let me know if it still looks good?

@kdmccormick kdmccormick moved this from Backlog to Next Up in Tutor DevEnv Adoption Jun 23, 2022
@regisb
Copy link

regisb commented Jul 4, 2022

I thought about this again, and I changed my mind about the recommended solution. The problem with a dedicated tutor local/dev/k8s dbshell command is that it's not convenient to add ad-hoc commands both to compose.py and k8s.py. Well, it's certainly possible, but every extra command requires quite a bit of work. Also, it's not really possible to use this approach in plugins.

An alternative that I would like to suggest is to add a dbshell script to the openedx Docker image. To do that, add a dbshell file to tutor/templates/build/openedx/bin/. The file will be copied at build-time and made executable. It should contain the mysql command described above. In order to make it work, we would still have to install the mysql-client in the openedx Docker image. That way, users would be able to open a root MySQL shell by running tutor local run lms dbshell or tutor k8s exec lms dbshell.

Alternatives that I've considered:

  1. Creating a dedicated dbshell compose service, accessible with tutor local run dbshell: this will not work on Kubernetes.
  2. Create a pluggable tasks interface: this would be the "right" solution but it requires quite a bit more work.
  3. Running tutor local run ./manage.py lms shell: this works, but is actually a bit different than what we need, as it does not open a MySQL shell with root access.

EDIT: the year is 2023, we have pluggable tasks, and (2) is the right way to implement this.

@kdmccormick kdmccormick moved this from Next Up to Backlog in Tutor DevEnv Adoption Jul 8, 2022
@kdmccormick kdmccormick moved this from Backlog to Next Up in Tutor DevEnv Adoption Jul 8, 2022
@kdmccormick
Copy link
Collaborator Author

this would be the "right" solution but it requires quite a bit more work.

If you feel that pluggable tasks is the right way to solve it, then let's do that! We have at least two other reasons to build the task interface, anyway.

I'll consider this ticket as blocked by #75.

@kdmccormick kdmccormick moved this from Next Up to Blocked in Tutor DevEnv Adoption Jul 8, 2022
@kdmccormick kdmccormick added enhancement Relates to new features or improvements to existing features and removed docs labels Sep 14, 2022
@kdmccormick kdmccormick moved this from 👀 In Review to ⚠️ Blocked in Tutor DevEnv Adoption Oct 27, 2022
@kdmccormick kdmccormick moved this from ⚠️ Blocked to 📋 Refined in Developer Experience Working Group Jan 10, 2023
@kdmccormick kdmccormick moved this from 📋 Refined to 📥 New in Developer Experience Working Group Jan 11, 2023
@kdmccormick kdmccormick changed the title Add tutor [dev|local|k8s] dbshell command Add tutor [dev|local|k8s] sqlshell command Jan 11, 2023
@kdmccormick
Copy link
Collaborator Author

@regisb I updated this issue now that we have do-jobs. Can you check that the tasks look right to you?

I'm also curious if you have a pref between do dbshell and do sqlshell. For what it's worth, I was going to make a follow-up ticket for do mongoshell as well.

@kdmccormick
Copy link
Collaborator Author

fyi @Carlos-Muniz , since you might be the one to pick this up.

@regisb
Copy link

regisb commented Jan 26, 2023

Can you check that the tasks look right to you?

They do. I think that we should add a --db option to connect to a database by default. By default, the mysql client should not connect to a database, so the end user will have to run use openedx or something similar.

I prefer "sqlshell" because it's clearer than "dbshell".

@kdmccormick kdmccormick added ⭐ feature and removed enhancement Relates to new features or improvements to existing features labels Mar 6, 2023
@regisb regisb changed the title Add tutor [dev|local|k8s] sqlshell command Add tutor [dev|local|k8s] do sqlshell command Apr 4, 2023
regisb added a commit to overhangio/tutor that referenced this issue Apr 4, 2023
An optional `--db=openedx` argument can be passed to the job command.

This should close
openedx-unsupported/wg-developer-experience#51
regisb added a commit to overhangio/tutor that referenced this issue Apr 4, 2023
An optional `--db=openedx` argument can be passed to the job command.

This should close
openedx-unsupported/wg-developer-experience#51
@github-project-automation github-project-automation bot moved this from ⚠️ Blocked to 🚀 Closed in Tutor DevEnv Adoption Apr 26, 2023
@github-project-automation github-project-automation bot moved this from 📥 New to 🚀 Closed in Developer Experience Working Group Apr 26, 2023
@kdmccormick
Copy link
Collaborator Author

🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants