Executing postgres initialization scripts when running cypress on CI

Viewed 863

I'm trying to run Cypress on gitlab CI.

Everything works as expected, but one little thing.. my DB initialization script (which runs after every test) won't work. This problem fails my tests, as well as the CI job.

After some thinking, I've realized that the setup.sh script contains psql command which connects to db and needs postgres (on local machine the tests run successfully since I do have postgres installed locally).

I'm using cypress_included:3.8.0 image which doesn't contain postgres. Any ideas how to solve the issue? is there any workaround? should I manually try to install it myself? (if so, it would be nice to see an example)

Thanks!

1 Answers

Since cypress/included:3.8.0 image is using Debian OS, thus you can use apt-get command inside your job scripts to install some dependencies or packages.

If you want to install both PostgreSQL core database server and PostgreSQL client (psql), you can add the following commands to your CI / CD job scripts like below:

image: cypress/included:3.8.0

⋮

foo job:
    scripts:
        ...
        - apt-get update -qy && apt-get upgrade -qy
        - apt-get install -y postgresql postgresql-client postgresql-contrib
        ...
⋮    


If you just want to install PostgreSQL client (psql), remove packages postgresql and postgresql-client from the command:

image: cypress/included:3.8.0

⋮

foo job:
    scripts:
        ...
        - apt-get update -qy && apt-get upgrade -qy
        - apt-get install -y postgresql-client
        ...
⋮    
Related