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

IOError: [Errno 13] Permission denied: u'/.myclirc' #1515

Closed
jimafisk opened this issue Mar 8, 2019 · 3 comments
Closed

IOError: [Errno 13] Permission denied: u'/.myclirc' #1515

jimafisk opened this issue Mar 8, 2019 · 3 comments

Comments

@jimafisk
Copy link
Contributor

jimafisk commented Mar 8, 2019

I'm having trouble installing MyCLI in a lando database container. I was able to do this successfully with version v3.0.0-beta.47, by adding the following to my .lando.yml file:

services:
  database:
    type: mysql
    run_as_root:
      - apt-get update
      - apt-get install python-pip python-setuptools -y
      - pip install mycli

tooling:
  mycli:
    service: database
    description: "Open mycli prompt in db container: lando mycli"
    cmd: "mycli -udrupal -pdrupal"

I actually made a video on how to do this: https://www.youtube.com/watch?v=hNa7lqM4yqw.

However when I try with lando version v3.0.0-rc.13 I get the following error when trying to open a mycli prompt:

Traceback (most recent call last):
  File "/usr/local/bin/mycli", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/mycli/main.py", line 1047, in cli
    myclirc=myclirc)
  File "/usr/local/lib/python2.7/dist-packages/mycli/main.py", line 142, in __init__
    write_default_config(self.default_config_file, myclirc)
  File "/usr/local/lib/python2.7/dist-packages/mycli/config.py", line 72, in write_default_config
    shutil.copyfile(source, destination)
  File "/usr/lib/python2.7/shutil.py", line 83, in copyfile
    with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: u'/.myclirc'

I've tried manually updating file permissions but I'm not having any luck. Any insight is greatly appreciated!

@jimafisk jimafisk added the task label Mar 8, 2019
@jimafisk
Copy link
Contributor Author

jimafisk commented Mar 8, 2019

@philoSurfer solved this for me in Drupal slack.

The key was to specify the user in the tooling section (you need to explicitly call out the db as well):

  mycli:
    service: database
    description: "opens mycli command line prompt"
    cmd: "mycli --user=drupal8 --password=drupal8 --database=drupal8"
    user: root

@jimafisk
Copy link
Contributor Author

jimafisk commented Mar 8, 2019

It's a little off topic, but figured I'd share a couple of other things. You can make your MySQL output nicer using pspg, install it with the following in .lando.yml:

services:
 database:
   type: mysql
   build_as_root:
     - apt-get update
     - apt-get install python-pip python-setuptools -y
     - pip install mycli
     - apt-get install wget ca-certificates -y
     - wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
     - sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
     - apt-get update
     - apt-get install pspg
    config:
      database: lando/my-custom.cnf

Then just add a my.cnf override to enable the pspg pager by default by creating a file at lando/my-custom.cnf with these contents:

[client]
pager = 'pspg -s 16' 

Lastly, if you're output gets messed up when you scroll, it's likely because docker doesn't know the size of your screen. You can adjust it by opening the prompt like this:

docker exec -e COLUMNS="`tput cols`" -e LINES="`tput lines`" -ti projectname_database_1 mycli

or if using fish shell:

docker exec -e COLUMNS="(tput cols)" -e LINES="(tput lines)" -ti projectname_database_1 mycli

@jimafisk jimafisk closed this as completed Mar 8, 2019
@jimafisk
Copy link
Contributor Author

Another thing, in order to use mycli and pspg together, you should use the --defaults-file flag with the mycli command, see this for more details. Basically mycli will respect the [client] info in a my.cnf configuration file (this is where we are setting our pager) but it looks for that file in standard places (/etc/my.cnf, /etc/mysql/my.cnf, /usr/etc/my.cnf, ~/.my.cnf). In order to tell mycli to look for the custom my.cnf override you created, you need to tell it where lando is putting that file inside the database container. You can do that by setting up your tooling like this:

tooling:
  mycli:
    service: database
    description: "Open mycli prompt in db container: lando mycli"
    cmd: "mycli --user=drupal --password=drupal --database=drupal --defaults-file=/opt/bitnami/mysql/conf/bitnami/my_custom.cnf"
    user: root

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

No branches or pull requests

1 participant