Documentation - How to include 3rd Party Plugins in a Docker-Setup

Must-share information (formatted with Markdown):

  • which versions are you using
    SonarQube CE 8.9
  • what are you trying to achieve
    Install a 3rd Party Plugin in a Docker Setup
  • what have you tried so far to achieve this
    Searched the documentation for clues

====

Dear all,
after having created a docker setup as documented here: Install the Server | SonarQube Docs i now would like to endulge myself in the possibly hazardous procedure of manually installing a 3rd Party Plugin.

The documentation here: Install a Plugin | SonarQube Docs does describe the steps needed for a “normal” plugin installation (i guess)

  • Am i assuming correctly that i could handle the step of copying the plugin jars inside a custom Dockerfile?
  • I already created such a Dockerfile to inject our custom certs that were needed to talk to the LDAPS.
  • So i would add more COPY commands to that Dockerfile to copy the jars into the target directories, right?

(please excuse my ping to @Tobias_Trabelsi here, i hope i am assuming correctly that he might be quite knowledgeable concerning these container things? :innocent: )

cheers
Daniel

//edit:
P.S.: Maybe it might be helpful to extend the documentation by mentioning how to handle the (manual) installation of 3rd party plugins in a docker based setup

Hi,

Please don’t ping people who aren’t involved in your thread. :slight_smile:

Have you checked the install docs?

I believe this is going to be about setting up your extensions volume & putting the plugin jars there.

 
Ann

Hi Ann, sorry i know.

But i think these things might be of use for Tobias, too. Give and take.

I already mentioned the install docs you qoted in my OP, so obviously i was not able to make the distinction about my question clear enough.

Handling the volumes is not easy (and not part of Install a Plugin | SonarQube Docs) … to get a glimpse of the steps you have to research please take a look at

(most of the answers needed to solve my question are seemingly taken care of there … i quote it here not only because of that, but also to enable you to realize how much of a SEP-Field you make this if you do not integrate helpful hints into your Install a Plugin | SonarQube Docs)

To have the (hopefully working) simplest answer qoted:

Here's a one-liner that copies myfile.txt from current directory to my_volume:
docker run --rm -v $PWD:/source -v my_volume:/dest -w /source alpine cp myfile.txt /dest
  • One cannot easily write to a volume, one has to create a container to manipulate the volume
  • And if i understand the documentation here correctly, contents of a directory that a volume mounts to get copied into that volume … so in the end, maybe my way of prepopulating the plugins in my own Dockerfile might be a pragmatic solution.

I am now even more under the assumption that “the sonar (preferred ) way” of interacting with a volume to manually install a plugin in a docker setup is worth being documented in Install a Plugin | SonarQube Docs to help the next person thinking about this.

cheers
Daniel

Hi @daniel ,

there are a few things here, so let me try to explain.

To install 3rd party plugins, you should in theory be able to use the marketplace. with the named volume mounted to the plugin install directory these installations should persist in case of a change of an image etc.

If you want to do it programatically you can define a additional container that downloads the jars of the plugins you want to have in the named volume (up to you).

if you want to use a local filesystem mount from your docker host, this is also possible since 8.5 where we embed the language analyzer in SQ directly. So since then you can use something like this:

version: "3"

services:
  sonarqube:
    image: sonarqube:8.9-community
    depends_on:
      - db
    environment:
      SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
      SONAR_JDBC_USERNAME: sonar
      SONAR_JDBC_PASSWORD: sonar
    volumes:
      - sonarqube_data:/opt/sonarqube/data
      - /path/to/your/plugins:/opt/sonarqube/extensions
      - sonarqube_logs:/opt/sonarqube/logs
    ports:
      - "9000:9000"
  db:
    image: postgres:12
    environment:
      POSTGRES_USER: sonar
      POSTGRES_PASSWORD: sonar
    volumes:
      - postgresql:/var/lib/postgresql
      - postgresql_data:/var/lib/postgresql/data

volumes:
  sonarqube_data:
  sonarqube_logs:
  postgresql:
  postgresql_data:

i am writing compose here, but of cause you can use the respected docker run command as well. The only thing that you need to take care about, would be that the SQ user inside the container has the correct permissions to the docker host path.

hope that helps :slight_smile:

1 Like

Hi Tobias, thank you for taking the time to create your answer!

If i may, i would like to go over your reply, so that you might be able to correct any mistakes in my perception :innocent:

The docker-compose.yml you quoted is the Docker Compose .yml file example from Install the Server | SonarQube Docs with the following one line changed, right?

  • - /path/to/your/plugins:/opt/sonarqube/extensions instead of
  • - sonarqube_extensions:/opt/sonarqube/extensions

which makes the extensions bind-mounted instead of volume mounted. If i understand correctly, then:

  • Using the bind-mount instead of the volume would embed the directories content into the container and the volume would stay empty (probably? :thinking: )

  • to get the plugin(s) into the volume i [c|w]ould

    • run the docker-compose with volumes and install plugins via marketplace (works for CE, but not for DE/EE/DCE because there plugins now have to be installed manually, if i understand correctly) so that they get stored in the mounted volume

    • create a dummy-container and in that process could inject them into the volume

    • create my own Dockerfile/image based on “FROM sonarqube:$tag” where i COPY all plugin-jars to the right directories (because on first mount, any contents of the directory get copied into the volume)

Anything obviously wrong in that summary? :nerd_face:

cheers
Daniel

P.S.: I still would like to suggest that an addition to Install a Plugin | SonarQube Docs would be beneficial to everyone trying to install plugins while using docker. (And even more when not on CE, because then you have to install them manually now, if i understand it correctly)

Hi @daniel ,

yep this is correct :+1:

yep but this is not bad in this case. this used to be a problem before 8.5 but now when the filesystem permissions are correct, SQ will create the required folders.

no the installation via the marketplace is working with CE/DE and EE. only on DCE this is not possible and needs to be done manually. how do you come to this conclusion?

This is also why we don’t document this directly. there are only edge cases where you need to install plugins manually. the majority of the use cases are just click install on the web UI and restart sonarqube (also from the web ui).

Hi @Tobias_Trabelsi and thank you for your detailed answer!

Actually that is my understanding of https://jira.sonarsource.com/browse/MMF-2301 … to quote from there (the whole MMF is interesting, i am just highlighting to focus on my current assumption):

If i combine the consequences of this, i assume something has to be performed manually/automatically to make the plugins available to a volume that SQ in the container uses. (if i bind-mount, the process is more clear. i understand that.)

Only in the CE i can just fire up a compose with volumes only and install via Marketplace that then persists inside the volume, if understood correctly. I would be glad if i missed something there.

Hi @daniel ,

i stand corrected. sorry i was working on something else and did not notice the change. i checked and your understanding is correct.
with this in mind i now better understand where your are coming from and that there is a lack of documentation here. thank you for pointing that out.

can you manage now to install a plugin manually or do you need additional help with the procedure?

1 Like

Hi @Tobias_Trabelsi , thank you for clarification.

I am currently in the process of manufacturing my own internal Dockerfile

I will then find out how well that will work together with the “default” docker-compose.yml + volume-mounts.

TYVM for asking! Will come back here to talk about my findings (and possible followup-questions) after the experiment :nerd_face: :+1: