You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Steinar Bang <sb...@dod.no> on 2020/04/21 16:36:26 UTC

My first real karaf-based docker image: sonar-collector

I have created my first real karaf-based docker image:
 https://github.com/steinarb/sonar-collector#run-the-sonar-metrics-collector-in-docker

The sonar-collector is intended as a webhook called by sonar on
completing a build, it will store key sonar measurements as a row in a
database table.  

Sonar has these numbers internally but doesn't have a way to get at
them. At first we typed these numbers manually into a spreadsheet to get
statistics on a set of analyzed programs.  But that was tedious, so we
created sonar-collector to capture the numbers instead.

The docker image is built with maven against a local docker and then
after testing, the image was pushed to docker hub:
 https://github.com/steinarb/sonar-collector#building-the-docker-image

The docker image is a very thin layer on top of the official karaf 4.2.8
docker image
 https://github.com/steinarb/sonar-collector/blob/master/docker/docker/Dockerfile#L1

It copies in two files into the image's karaf etc directory:
 1. org.apache.karaf.features.cfg
    a. Adds a feature repository for sonar-collector
        https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L28
    b. Adds two features to the boot features
       i. An enviroment variable overloadable DataSourceFactory feature
          that defaults to postgresql
            https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L52
       ii. The sonar-collector-webhook-with-postgresql feature
            https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L53

 2. org.ops4j.datasource-sonar-collector.cfg which is a modified version
    of the file generated by pax-jdbc on first start, and the JDBC
    driver name and JDBC connection info overridable by system
    environment variables
     https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.ops4j.datasource-sonar-collector.cfg#L2

This image will provision itself from maven central (sonar-collector is
released to maven-central) and will always use the latest released
version, so there is no need to build a new docker image if a new
version of sonar-collector is released to maven central.

Since the database schema is set up by liquibase and the SQL used is
trivial (inserts rows into a single table), it should in theory be
possible to use a different database than PostgreSQL, and I have
provided the possibility to override the database used when doing
"docker run" of the image.

But using other databases than PostgreSQL is something I haven't
extensively tested.


Re: My first real karaf-based docker image: sonar-collector

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Jean-Baptiste Onofre <jb...@nanthrax.net>:

> Thanks for sharing !
> I think we can improve the docker script provided by Karaf to do the same (starting from Karaf official instance).

Sounds great! :-)

Resolving a feature like at startup and providing the bundles both from
dependencies and the reactor build into system directory of the karaf in
the container in some way would also be nice.

For my particular docker image it makes sense to provision from the
latest release on maven central (I don't have to rebuild the image when
I make a new release).

But for someone creating an image containing stuff not released to maven
central or creating an image from a snapshot build, or deploying to a
docker instance that's can't reach maven central, then it would be nice
to have all of the dependecies inside the image.


Re: My first real karaf-based docker image: sonar-collector

Posted by Jean-Baptiste Onofre <jb...@nanthrax.net>.
Thanks for sharing !

I think we can improve the docker script provided by Karaf to do the same (starting from Karaf official instance).

Regards
JB

> Le 21 avr. 2020 à 18:36, Steinar Bang <sb...@dod.no> a écrit :
> 
> I have created my first real karaf-based docker image:
> https://github.com/steinarb/sonar-collector#run-the-sonar-metrics-collector-in-docker
> 
> The sonar-collector is intended as a webhook called by sonar on
> completing a build, it will store key sonar measurements as a row in a
> database table.  
> 
> Sonar has these numbers internally but doesn't have a way to get at
> them. At first we typed these numbers manually into a spreadsheet to get
> statistics on a set of analyzed programs.  But that was tedious, so we
> created sonar-collector to capture the numbers instead.
> 
> The docker image is built with maven against a local docker and then
> after testing, the image was pushed to docker hub:
> https://github.com/steinarb/sonar-collector#building-the-docker-image
> 
> The docker image is a very thin layer on top of the official karaf 4.2.8
> docker image
> https://github.com/steinarb/sonar-collector/blob/master/docker/docker/Dockerfile#L1
> 
> It copies in two files into the image's karaf etc directory:
> 1. org.apache.karaf.features.cfg
>    a. Adds a feature repository for sonar-collector
>        https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L28
>    b. Adds two features to the boot features
>       i. An enviroment variable overloadable DataSourceFactory feature
>          that defaults to postgresql
>            https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L52
>       ii. The sonar-collector-webhook-with-postgresql feature
>            https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L53
> 
> 2. org.ops4j.datasource-sonar-collector.cfg which is a modified version
>    of the file generated by pax-jdbc on first start, and the JDBC
>    driver name and JDBC connection info overridable by system
>    environment variables
>     https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.ops4j.datasource-sonar-collector.cfg#L2
> 
> This image will provision itself from maven central (sonar-collector is
> released to maven-central) and will always use the latest released
> version, so there is no need to build a new docker image if a new
> version of sonar-collector is released to maven central.
> 
> Since the database schema is set up by liquibase and the SQL used is
> trivial (inserts rows into a single table), it should in theory be
> possible to use a different database than PostgreSQL, and I have
> provided the possibility to override the database used when doing
> "docker run" of the image.
> 
> But using other databases than PostgreSQL is something I haven't
> extensively tested.
> 


Re: My first real karaf-based docker image: sonar-collector

Posted by Gerald Kallas <ca...@mailbox.org>.
Cool stuff. Like it!

> Steinar Bang <sb...@dod.no> hat am 21. April 2020 18:36 geschrieben:
> 
>  
> I have created my first real karaf-based docker image:
>  https://github.com/steinarb/sonar-collector#run-the-sonar-metrics-collector-in-docker
> 
> The sonar-collector is intended as a webhook called by sonar on
> completing a build, it will store key sonar measurements as a row in a
> database table.  
> 
> Sonar has these numbers internally but doesn't have a way to get at
> them. At first we typed these numbers manually into a spreadsheet to get
> statistics on a set of analyzed programs.  But that was tedious, so we
> created sonar-collector to capture the numbers instead.
> 
> The docker image is built with maven against a local docker and then
> after testing, the image was pushed to docker hub:
>  https://github.com/steinarb/sonar-collector#building-the-docker-image
> 
> The docker image is a very thin layer on top of the official karaf 4.2.8
> docker image
>  https://github.com/steinarb/sonar-collector/blob/master/docker/docker/Dockerfile#L1
> 
> It copies in two files into the image's karaf etc directory:
>  1. org.apache.karaf.features.cfg
>     a. Adds a feature repository for sonar-collector
>         https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L28
>     b. Adds two features to the boot features
>        i. An enviroment variable overloadable DataSourceFactory feature
>           that defaults to postgresql
>             https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L52
>        ii. The sonar-collector-webhook-with-postgresql feature
>             https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L53
> 
>  2. org.ops4j.datasource-sonar-collector.cfg which is a modified version
>     of the file generated by pax-jdbc on first start, and the JDBC
>     driver name and JDBC connection info overridable by system
>     environment variables
>      https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.ops4j.datasource-sonar-collector.cfg#L2
> 
> This image will provision itself from maven central (sonar-collector is
> released to maven-central) and will always use the latest released
> version, so there is no need to build a new docker image if a new
> version of sonar-collector is released to maven central.
> 
> Since the database schema is set up by liquibase and the SQL used is
> trivial (inserts rows into a single table), it should in theory be
> possible to use a different database than PostgreSQL, and I have
> provided the possibility to override the database used when doing
> "docker run" of the image.
> 
> But using other databases than PostgreSQL is something I haven't
> extensively tested.

Re: My first real karaf-based docker image: sonar-collector

Posted by Francois Papon <fr...@openobject.fr>.
Nice! 

Great job Steinar!

regards,

François
fpapon@apache.org

Le 21/04/2020 à 18:36, Steinar Bang a écrit :
> I have created my first real karaf-based docker image:
>  https://github.com/steinarb/sonar-collector#run-the-sonar-metrics-collector-in-docker
>
> The sonar-collector is intended as a webhook called by sonar on
> completing a build, it will store key sonar measurements as a row in a
> database table.  
>
> Sonar has these numbers internally but doesn't have a way to get at
> them. At first we typed these numbers manually into a spreadsheet to get
> statistics on a set of analyzed programs.  But that was tedious, so we
> created sonar-collector to capture the numbers instead.
>
> The docker image is built with maven against a local docker and then
> after testing, the image was pushed to docker hub:
>  https://github.com/steinarb/sonar-collector#building-the-docker-image
>
> The docker image is a very thin layer on top of the official karaf 4.2.8
> docker image
>  https://github.com/steinarb/sonar-collector/blob/master/docker/docker/Dockerfile#L1
>
> It copies in two files into the image's karaf etc directory:
>  1. org.apache.karaf.features.cfg
>     a. Adds a feature repository for sonar-collector
>         https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L28
>     b. Adds two features to the boot features
>        i. An enviroment variable overloadable DataSourceFactory feature
>           that defaults to postgresql
>             https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L52
>        ii. The sonar-collector-webhook-with-postgresql feature
>             https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.apache.karaf.features.cfg#L53
>
>  2. org.ops4j.datasource-sonar-collector.cfg which is a modified version
>     of the file generated by pax-jdbc on first start, and the JDBC
>     driver name and JDBC connection info overridable by system
>     environment variables
>      https://github.com/steinarb/sonar-collector/blob/master/docker/docker/org.ops4j.datasource-sonar-collector.cfg#L2
>
> This image will provision itself from maven central (sonar-collector is
> released to maven-central) and will always use the latest released
> version, so there is no need to build a new docker image if a new
> version of sonar-collector is released to maven central.
>
> Since the database schema is set up by liquibase and the SQL used is
> trivial (inserts rows into a single table), it should in theory be
> possible to use a different database than PostgreSQL, and I have
> provided the possibility to override the database used when doing
> "docker run" of the image.
>
> But using other databases than PostgreSQL is something I haven't
> extensively tested.
>