tbny tbny - 6 months ago 59
SQL Question

gitlab-ci docker executor | how to setup mysql service?

I'm trying to get a gitlab-ci build going, but I'm having trouble with the mysql setup portion. When I commit, the mysql script seems to run OK, but then the application build fails on connecting to the db. What am I missing here?

.gitlab-ci.yml

stages:
- prepare
- test

services:
- mariadb

variables:
MYSQL_ROOT_PASSWORD: "password"

connect:
stage: prepare
image: mysql
script:
- mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mariadb < "data/db/scripts/create-db.sql"
- mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mariadb < "data/db/scripts/init-db-tables.sql"

dev:
stage: test
image: java:opendjdk-8
script:
- ./gradlew assemble
- ./gradlew check


data source config

@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();

dataSource.setUrl("jdbc:mysql://mariadb:3306/rvep");
dataSource.setUsername("root");
dataSource.setPassword("password");
dataSource.setDriverClassName("com.mysql.jdbc.Driver");

return dataSource;
}


build errors
result of hibernate config not hitting db

io.abnd.rvep.RVEPTests > contextLoads FAILED
java.lang.IllegalStateException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: org.springframework.beans.BeanInstantiationException
Caused by: org.hibernate.HibernateException

io.abnd.rvep.security.rest.TestControllerTest > findAllRoleCategories FAILED
java.lang.IllegalStateException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: org.springframework.beans.BeanInstantiationException
Caused by: org.hibernate.HibernateException

io.abnd.rvep.security.rest.TestControllerTest > findAllRoles FAILED
java.lang.IllegalStateException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: org.springframework.beans.BeanInstantiationException
Caused by: org.hibernate.HibernateException

Answer

It seems installing mysql-client through apt-get, and combining scripts helps. Here is my .gitlab-ci.yml for now. build passing.

variables:
  MYSQL_ROOT_PASSWORD: "password"

dev:
  image: java:openjdk-8
  services:
    - mariadb
  script:
    - apt-get update && apt-get --assume-yes install mysql-client
    - mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mariadb < "data/db/scripts/create-db.sql"
    - mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mariadb < "data/db/scripts/init-db-tables.sql"
    - ./gradlew assemble check --info