How to configure a Jenkinsfile pipeline for a Rails project with a PostgreSQL DB in Docker?

327 views
Skip to first unread message

Ricardo Amaro

unread,
May 26, 2020, 1:47:47 PM5/26/20
to Jenkins Users
Hello to all,

I would like to configure a Jenkinsfile for a RoR project with a PostgreSQL database, but the syntax and the documentation is driving me crazy.

As I understand, if I want my RoR app to run in a Docker container and my Postgres Db to run in another container, I need to use something like this:

node {
  docker.image('postgres:11.3').withRun("--env POSTGRES_USER=user --env POSTGRES_PASSWORD=password -p 54321:5432") { c ->
    docker.build('test-image', './ci').inside("--link ${c.id}")
  }
}

but, if the pipeline syntax tells me that I need to declare an agent, like this:

pipeline {
  agent {
    ...
  }
  stages {
    ...
  }
}

where do I need to declare the containers I'm creating?

Am I doing this wrong? Is it impossible to have it this way, in two containers? Can someone, please, provide me with a full example of it?


Thank you in advance!

Piotr Bracha

unread,
May 27, 2020, 2:31:24 AM5/27/20
to jenkins...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/960edcc1-cd04-431a-8279-7d707062a3be%40googlegroups.com.


--
Pozdrawiam / Kind regards, 
Piotr Bracha
Vasco Electronics sp. z o.o. S.K.A.
al. Pokoju 1, CTA/350 
31-548 Kraków
NIP 677 236 91 51
 
Vasco Electronics
Vasco Electronics Spółka z ograniczoną odpowiedzialnością Spółka Komandytowo-Akcyjna, Al. Pokoju 1, CTA/350, 31-548 Kraków, Polska, NIP: 6772369151, REGON: 122581850, zarejestrowana w Sądzie Rejonowym dla Krakowa Śródmieścia XI Wydział KRS pod nr KRS: 0000421705, Kapitał zakładowy 50 000 zł (słownie: pięćdziesiąt tysięcy złotych) w całości wpłacony. Klauzula Bezpieczeństwa: treść tej wiadomości wraz z załącznikami stanowią informacje chronione przed ujawnieniem. Jeśli wiadomość ta nie jest przeznaczona dla Ciebie uprzedzamy, że ujawnianie, kopiowanie, rozpowszechnianie lub korzystanie z niej lub z załączników jest zabronione. Jeśli otrzymałeś tę wiadomość przez pomyłkę, uprzejmie prosimy o niezwłoczne zawiadomienie nadawcy i odesłanie jej z powrotem wraz z załącznikami a także usunięcie ze swoich systemów.

Ricardo Amaro

unread,
May 27, 2020, 4:08:30 AM5/27/20
to Jenkins Users
Hi Polak.

Thank you for your reply, but I don't see how the link you shared will help me. It is related with containerizing a Rails app, and doesn't refers the configuration of a Jenkinsfile.


On Wednesday, May 27, 2020 at 7:31:24 AM UTC+1, Polak wrote:
wt., 26 maj 2020 o 19:47 Ricardo Amaro <rjm...@gmail.com> napisał(a):
Hello to all,

I would like to configure a Jenkinsfile for a RoR project with a PostgreSQL database, but the syntax and the documentation is driving me crazy.

As I understand, if I want my RoR app to run in a Docker container and my Postgres Db to run in another container, I need to use something like this:

node {
  docker.image('postgres:11.3').withRun("--env POSTGRES_USER=user --env POSTGRES_PASSWORD=password -p 54321:5432") { c ->
    docker.build('test-image', './ci').inside("--link ${c.id}")
  }
}

but, if the pipeline syntax tells me that I need to declare an agent, like this:

pipeline {
  agent {
    ...
  }
  stages {
    ...
  }
}

where do I need to declare the containers I'm creating?

Am I doing this wrong? Is it impossible to have it this way, in two containers? Can someone, please, provide me with a full example of it?


Thank you in advance!

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkins...@googlegroups.com.


--
Pozdrawiam / Kind regards, 
Piotr Bracha
Vasco Electronics sp. z o.o. S.K.A.
al. Pokoju 1, CTA/350 
31-548 Kraków
NIP 677 236 91 51
 

Piotr Bracha

unread,
May 27, 2020, 5:25:13 AM5/27/20
to jenkins...@googlegroups.com
Ok, sorry. Probably I didn't understand you properly but I thought you want to run a dockerized rails app based on postgres db. Could you tell me what is a goal you want to reach?

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/36481089-02d7-417c-80ba-0f3242b2b259%40googlegroups.com.


--
Pozdrawiam / Kind regards, 
Piotr Bracha
Vasco Electronics sp. z o.o. S.K.A.
al. Pokoju 1, CTA/350 
31-548 Kraków
NIP 677 236 91 51
 

Ricardo Amaro

unread,
May 27, 2020, 5:34:16 AM5/27/20
to Jenkins Users
Ok, let me try to explain better.

I have a RoR app that uses a Postgres DB. I want to use Jenkins to automate the execution of the test suite of that RoR app. Currently, I'm being unable to configure a proper Jenkinsfile for it, because I don't understand how to tell Jenkins to use a container for the RoR app and a container for the Postgres DB.


--
Pozdrawiam / Kind regards, 
Piotr Bracha
Vasco Electronics sp. z o.o. S.K.A.
al. Pokoju 1, CTA/350 
31-548 Kraków
NIP 677 236 91 51
 

Yilmaz Gunduzalp

unread,
May 27, 2020, 5:53:39 AM5/27/20
to Jenkins Users
If you want to run integration tests against a dB you. Need to run that db yourself somewhere.Jenkins is a deployment tool not for setting up a dB.

You have to add your dB credentials in Jenkins host and connect to dB when executing tests

Or you might just mock your database in your tests so don’t need to set up a dB maybe?

Piotr Bracha

unread,
May 27, 2020, 5:54:23 AM5/27/20
to jenkins...@googlegroups.com
I did this in this way. I used Jenkinsfile with docker-compose commands inside like here - my Jenkinsfile -  https://pastebin.com/CgT1bn2K and here - my docker-compose.yml - https://pastebin.com/FfLaX1xH

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f192b8cb-b047-4053-bd32-8185f2f27684%40googlegroups.com.


--
Pozdrawiam / Kind regards, 
Piotr Bracha
Vasco Electronics sp. z o.o. S.K.A.
al. Pokoju 1, CTA/350 
31-548 Kraków
NIP 677 236 91 51
 
Reply all
Reply to author
Forward
0 new messages