Install Plugins in Discourse

plugins

(Sam Saffron) #78

If you want to test stuff quickly you best install a dev environment.

Long term we want to make it easier to disable/enable plugins (and add a “safe mode”) options but for playing around your best option is a dev environment.


(dtbaker) #79

I have discourse running in a docker container and have been using launcher rebuild to test plugin changes. Is this classed as a “dev environment”?

Edit: found this: Development environment: Vagrant or Docker? Docker = Production, Vagrant = Dev. I’ll ditch my docker install and setup vagrant.


Beginner's Guide to Creating Discourse Plugins - Part 1
(Arran Scott) #80

@angus thanks for the changes.

I’m getting /root/.ssh/config: Directory nonexistent on the first line where it echo’s the string to the config file.

Do I need to create the /root/.ssh folder first?


(Arran Scott) #81

I’m getting an authentication error when following the steps above.

I’m using Bitbucket instead of Github, I’ve changed all mentions of github to bitbucket.

I really don’t know what I’m doing wrong. Below is my containers app.yml file:

- exec: cd /var/www/discourse && sudo -u discourse bundle install --deployment --without test --without development
- exec: mkdir /root/.ssh
- exec: ssh-keyscan -t rsa bitbucket.com > /root/.ssh/known_hosts
- exec: echo "Host bitbucket\n\tStrictHostKeyChecking no\n\tHostName bitbucket.com\n\tIdentityFile /root/.ssh/id_rsa\n" >> /root/.ssh/config
- file:
    path: /root/.ssh/id_rsa
    chmod: 600
    contents: |
       -----BEGIN RSA PRIVATE KEY-----
       ** PRIVATE KEY FROM ~/.ssh **
       -----END RSA PRIVATE KEY-----
- file:
     path: /root/.ssh/id_rsa.pub
     chmod: 600
     contents: ssh-rsa ** PUBLIC KEY FROM ~/.ssh **
- exec: cd $home/plugins && git clone git@bitbucket.org:url-for-private-plugin
- exec: cd $home && sudo -E -u discourse bundle exec rake db:migrate
- exec: cd $home && rm -fr tmp/cache
- exec: cd $home &&  sudo -E -u discourse bundle exec rake assets:precompile
- exec: rm /root/.ssh/id_rsa
- exec: rm /root/.ssh/id_rsa.pub

I’m having to create the .ssh folder at the top because it complains about the folder not being there.

The failing line is here - exec: cd $home/plugins && git clone git@bitbucket.org:url-for-private-plugin

The full error I’m getting is:

Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights


(ginger man) #82

@arrancscott You are almost there ! except for bitbucket.com…it should be bitbucket.org… the below code might help you

  - exec: touch /root/.ssh/known_hosts
  - exec: ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts


(Arran Scott) #83

Thanks! I’m one step closer.

I’m now getting:

Warning: Permanently added the RSA host key for IP address 'IP ADDRESS' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights

I’ve added the public key to the SSH keys section on Bitbucket so I know it can’t be an issue with that. Any ideas?


(ginger man) #84

did you get a chance to check by manually cloning the repo inside the container ? This looks like issue with the keys.


(Arran Scott) #85

cd /var/www/discourse/plugins and git clone...

Is that all I need to do to clone inside the container?


(ginger man) #86

yup…If the keys are rightly configured at both ends, then you should be able to clone the plugin repo with that command.


(Arran Scott) #87

Excuse me if I’m sounding dumb here, but there isn’t a /var/www folder. Where does the docker container live?


(ginger man) #88

/var/www/discourse/plugins folder resides in the container.

You should use

 ./launcher start app && ./launcher enter app 

to access the container filesystem


(Arran Scott) #90

I tested this by accessing the container filesystem and was unable to clone the plugin directly in the /plugins directory. It was returning the same error that was given when running ./launcher rebuild app.

Have you any idea what I can do from here? I’ve followed all the steps mentioned in this thread but it still doesn’t seem to be working.


(ginger man) #91

If manual git clone is not working, it clearly points to the problem in keys.

It is to be noted that /root/.ssh where the keys are stored should be inside the container and not the host. So you should enter the container and create the keys from there. If you don’t find the .ssh directory, then you can manually create it using mkdir (in fact we are doing the same in the above script you have pasted).

If you think you have done all of the above steps properly, it could be a problem while you were copying the key. I would suggest to delete the existing keys from /root/.ssh and try again with ssh-keygen within the container. copy the new key content (id_rsa.pub) to the bitbucket ssh settings.

Try to manually clone inside the plugins directory. If it works, then the script should work as well.


(Arran Scott) #92

Thanks for your help, really appreciated. That worked.

I was creating the ssh keys as the logged in user on the host, not in the container itself. Once I created the keys inside the container and copied the public key to the ssh keys section in Bitbucket it worked.

Thanks again.


(Alex "Rota" Freeman) #93

For me the steps (and step by steps) offered here worked perfectly with one ‘gotcha’ for devs new to python. Tabs will break the app.yml be sure to use spaces only!


#94

Thanks for your update on this guide. But I’m kind of stuck and I don’t really know where I messed up (I mean I understand the error message I got, but I don’t know how to fix it :

FAILED
--------------------
Pups::ExecError: echo "Host github\n\tStrictHostKeyChecking no\n\tHostName github.com\n\tIdentityFile /root/.ssh/github_rsa\n" >> /root/.ssh/config failed with return #<Process::Status: pid 2872 exit 2>
Location of failure: /pups/lib/pups/exec_command.rb:108:in `spawn'
exec failed with the params "echo \"Host github\\n\\tStrictHostKeyChecking no\\n\\tHostName github.com\\n\\tIdentityFile /root/.ssh/github_rsa\\n\" >> /root/.ssh/config"
1e2f40c7bbb0a94dff03030d8f00793726eed03d54d96c31e9f1e5291dc62758
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one
root@iunctis:/var/discourse#

Like you, I’ve renamed the files github_rsa & github_rsa.pub, I’ve made the command to add the key in the authorized_keys in root/.ssh/

In my root/.ssh folder I have 4 files :

  • github_rsa.pub (~ 400 bytes)
  • authorized_keys (~ 400 bytes)
  • github_rsa (~ 1600 bytes)
  • known_hosts (~ 200 bytes)

Here is the last part of my app.yml :

## Any custom commands to run after building
run:
  - exec: echo "Beginning of custom commands"
  
  - exec: cd /var/www/discourse && sudo -u discourse bundle install --deployment --without test --without development
  - exec: echo "Host github\n\tStrictHostKeyChecking no\n\tHostName github.com\n\tIdentityFile /root/.ssh/github_rsa\n" >> /root/.ssh/config
  - file:
      path: /root/.ssh/github_rsa
      chmod: 600
      contents: |
        -----BEGIN RSA PRIVATE KEY-----
        ......
        ......
        ......
        -----END RSA PRIVATE KEY-----
  - file:
      path: /root/.ssh/github_rsa.pub
      chmod: 600
      contents: ssh-rsa ...... root@iunctis
  - exec: cd $home/plugins && git clone git@github:iunctis/discourse-private.git
  - exec: cd $home && sudo -E -u discourse bundle exec rake db:migrate
  - exec: cd $home && rm -fr tmp/cache
  - exec: cd $home &&  sudo -E -u discourse bundle exec rake assets:precompile
  - exec: rm /root/.ssh/github_rsa
  - exec: rm /root/.ssh/github_rsa.pub

  - exec: echo "End of custom commands"

Do you have an idea where I messed up ?

Thanks !


(EW 👌) #95

Is it a problem to install more than one plugin at once?


(Mittineague) #96

No

A potential problem would be installing a broken plugin in the bunch.

Until and unless Discourse has a type of “installed but not activated” feature (i.e. “sandboxed”), IMHO it is better to first install one at a time to make sure it’s OK, then add another


(EW 👌) #97

:+1: Many thanks for your fast response.


(EW 👌) #98

in my running Discourse’s app.yml, there is no “- mkdir -p plugins” line. Do I need to add it when installing a new plugin as its showing in your sample app.yml?

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - mkdir -p plugins
          - git clone https://github.com/discourse/docker_manager.git