2017-12-24 94 views
0

私は、mysqlデータベースに接続されたspringbootアプリケーションを持っています。私はパイプラインを処理するために.gitlab-ci.ymlを使いたいです。私は以下の設定ファイルを作成しました。GitLab CI:私のテストジョブは、mysqlコンテナを取得しません。

before_script: 
- echo "Execute scripts which are required to bootstrap the application. !" 

after_script: 
- echo "Clean up activity can be done here !." 

services: 
- mysql 

stages: 
- build 
- connect 
- test 
- package 
- deploy 

variables: 
MAVEN_CLI_OPTS: "--batch-mode" 
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository" 
MYSQL_DATABASE_NAME: gyyconsortiumdb 
MYSQL_DATABASE_SCHEMA: "$CI_PROJECT_DIR/src/main/resources/static/sql/gyyconsortiumdb.sql" 
MYSQL_ROOT_PASSWORD: mysql 

cache: 
paths: 
    - .m2/repository/ 
    - target/ 

build: 
stage: build 
image: maven:latest 
script: 
    - mvn $MAVEN_CLI_OPTS clean compile 

connect: 
stage: connect 
image: mysql 
before_script: 
    - mysql --version 
script: 
    - echo "create database $MYSQL_DATABASE_NAME;" | mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql 
    - mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql $MYSQL_DATABASE_NAME < $MYSQL_DATABASE_SCHEMA 
    - mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql -e "show databases; use $MYSQL_DATABASE_NAME; show tables;" 

test: 
stage: test 
image: maven:latest 
script: 
    - mvn $MAVEN_CLI_OPTS test 

package: 
stage: package 
image: maven:latest 
script: 
    - mvn $MAVEN_CLI_OPTS package 
artifacts: 
    paths: [target/basecamp-0.0.1.war] 


deploy_test: 
stage: deploy 
script: 
- echo "######## To be defined ########" 
environment: staging 

deploy_prod: 
stage: deploy 
script: 
    - echo "######## To be defined ########" 
only: 
    - master 
environment: production 

最初のジョブが実行されているときに、ドッカーハブからmysqlイメージが取得されていますが、その理由はわかりません。私はmysqlが接続ジョブでのみ構築されるべきだと考えました。

また、接続ジョブが成功した後、テストジョブはmysqlイメージを再度プルします。そして、私のテストジョブは私のデータベースを認識しませんでしたが、サービスは正常に作成され、作成されたデータベースも見ることができました。

ビルドジョブコンソール出力:

Running with gitlab-runner 10.3.0 (5cf5e19a) 
    on docker-auto-scale (fa6cab46) 
Using Docker executor with image maven:latest ... 
Starting service mysql:latest ... 
Pulling docker image mysql:latest ... 
Using docker image mysql:latest ID=sha256:7d83a47ab2d2d0f803aa230fdac1c4e53d251bfafe9b7265a3777bcc95163755 for mysql service... 
Waiting for services to be up and running... 
Using docker image sha256:d6e999707ab00f954f4ab77c8ced4efce186099fb8318e1a0bc2f4fd8bb7bf6b for predefined container... 
Pulling docker image maven:latest ... 
Using docker image maven:latest ID=sha256:1f858e89a5843b0804a9e1498476a135f45e23a42fe673914f977e0882a6789e for build container... 
Running on runner-fa6cab46-project-4899225-concurrent-0 via runner-fa6cab46-srm-1514081729-3d654341... 
Cloning repository... 
Cloning into '/builds/user/xxx'... 
Checking out b9efb2da as 24-create-the-gitlab-ci-yml-file... 
Skipping Git submodules setup 
Checking cache for default... 
Downloading cache.zip from http://runners-cache-3-internal.gitlab.com:444/runner/project/4899225/default 
Successfully extracted cache 
$ echo "Execute scripts which are required to bootstrap the application. !" 
Execute scripts which are required to bootstrap the application. ! 
$ mvn $MAVEN_CLI_OPTS clean compile 
[INFO] Scanning for projects... 
[INFO] 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building xxx 0.0.1-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ xxx --- 
[INFO] Deleting /builds/user/xxx/target 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ xxx --- 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] Copying 4 resources 
[INFO] Copying 108 resources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ xxx --- 
[INFO] Changes detected - recompiling the module! 
[INFO] Compiling 35 source files to /builds/user/xxx/target/classes 
[WARNING] /builds/user/xxx/src/main/java/com//www/xxx/domain/Project.java: Some input files use unchecked or unsafe operations. 
[WARNING] /builds/user/xxx/src/main/java/com/xxx/www/xxx/domain/Project.java: Recompile with -Xlint:unchecked for details. 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 6.111 s 
[INFO] Finished at: 2017-12-24T02:18:07Z 
[INFO] Final Memory: 30M/71M 
[INFO] ------------------------------------------------------------------------ 
Running after script... 
$ echo "Clean up activity can be done here !." 
Clean up activity can be done here !. 
Creating cache default... 
.m2/repository/: found 1775 matching files   
target/: found 197 matching files     
Uploading cache.zip to http://runners-cache-3- 
internal.gitlab.com:444/runner/project/4899225/default 
Created cache 
Job succeeded 

接続ジョブコンソール出力

Running with gitlab-runner 10.3.0 (5cf5e19a) 
    on docker-auto-scale (e11ae361) 
Using Docker executor with image mysql ... 
Starting service mysql:latest ... 
Pulling docker image mysql:latest ... 
Using docker image mysql:latest ID=sha256:7d83a47ab2d2d0f803aa230fdac1c4e53d251bfafe9b7265a3777bcc95163755 for mysql service... 
Waiting for services to be up and running... 
Using docker image sha256:295a9e80fe6ae475bfeef8e318eb11db267d317fa6bc1ed8d72185dfd2adb8b7 for predefined container... 
Pulling docker image mysql ... 
Using docker image mysql ID=sha256:7d83a47ab2d2d0f803aa230fdac1c4e53d251bfafe9b7265a3777bcc95163755 for build container... 
Running on runner-e11ae361-project-4899225-concurrent-0 via runner-e11ae361-srm-1514081811-5092ac06... 
Cloning repository... 
Cloning into '/builds/yimengael/basecamp'... 
Checking out b9efb2da as 24-create-the-gitlab-ci-yml-file... 
Skipping Git submodules setup 
Checking cache for default... 
Downloading cache.zip from http://runners-cache-5-internal.gitlab.com:444/runner/project/4899225/default 
Successfully extracted cache 
$ mysql --version 
mysql Ver 14.14 Distrib 5.7.20, for Linux (x86_64) using EditLine wrapper 
$ echo "create database $MYSQL_DATABASE_NAME;" | mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql 
mysql: [Warning] Using a password on the command line interface can be insecure. 
$ mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql $MYSQL_DATABASE_NAME < $MYSQL_DATABASE_SCHEMA 
mysql: [Warning] Using a password on the command line interface can be insecure. 
$ mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql -e "show databases; use $MYSQL_DATABASE_NAME; show tables;" 
mysql: [Warning] Using a password on the command line interface can be insecure. 
Database 
information_schema 
mydb 
mysql 
performance_schema 
sys 
Tables_in_mydb 
message 
persistent_logins 
project 
project_description 
role 
user 
user_role 
Running after script... 
$ echo "Clean up activity can be done here !." 
Clean up activity can be done here !. 
Creating cache default... 
.m2/repository/: found 1775 matching files   
target/: found 197 matching files     
Archive is up to date!        
Created cache 
Job succeeded 

テストジョブが失敗しました:テストジョブを選択しない理由

2017-12-24 02:21:43.827 INFO 62 --- [   main] c.g.w.b.xxxWebApplicationTests  : Starting xxxWebApplicationTests on runner-4e4528ca-project-4899225-concurrent-0 with PID 62 (started by root in /builds/yimengael/xxx) 
2017-12-24 02:21:43.829 DEBUG 62 --- [   main] c.g.w.b.xxxWebApplicationTests  : Running with Spring Boot v1.5.8.RELEASE, Spring v4.3.12.RELEASE 
2017-12-24 02:21:43.829 INFO 62 --- [   main] c.g.w.b.xxxWebApplicationTests  : The following profiles are active: dev 
2017-12-24 02:21:45.101 INFO 62 --- [   main] o.s.w.c.s.GenericWebApplicationContext : Refreshing org.s[email protected]62e20a76: startup date [Sun Dec 24 02:21:45 UTC 2017]; root of context hierarchy 
2017-12-24 02:21:49.515 INFO 62 --- [   main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 
2017-12-24 02:21:51.533 WARN 62 --- [   main] o.a.tomcat.jdbc.pool.ConnectionPool  : maxIdle is larger than maxActive, setting maxIdle to: 50 
2017-12-24 02:21:52.448 ERROR 62 --- [   main] o.a.tomcat.jdbc.pool.ConnectionPool  : Unable to create initial connections of pool. 

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'mydb' 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 

..... 

2017-12-24 02:21:52.477 WARN 62 --- [   main] o.s.b.a.orm.jpa.DatabaseLookup   : Unable to determine jdbc url from datasource 

org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is 
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'mydb' 
    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:339) 
    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:366) 
    at org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:72) 
    at org.springframework.boot.autoconfigure.orm.jpa.JpaProperties.determineDatabase(JpaProperties.java:139) 

はあなたが私に教えてもらえます正しい方法でmysqlサービスをアップする?

ベスト、 G

答えて

0

最初の仕事は、それが ドッキングウィンドウハブからMySQLの画像を引っ張っている実行している、と私はその理由を知らないのですか?

サービスとしてMysqlを定義したためです。 GitLab CIはservicesキーワードを使用して、ドッカーのコンテナをベースイメージにリンクする必要があるかどうかを定義します。だから、それはすべての段階で実行されます。

テストジョブがmysql サービスを正しい方法で選択しない理由を教えてください。

あなたgitlabの設定ファイルでデータベース名を使用すると、ログとしてあなたの春の設定ファイルで定義されたものとは異なり、「gyyconsortiumdb」であるあなたが「MYDB」

jdbc4.MySQLSyntaxErrorExceptionに接続しようとしている示しています。不明なデータベース「MYDB」

はあなたのコメントについては、 https://docs.gitlab.com/ce/ci/services/mysql.html

+0

おかげジャヴァド詳細はリンクをたどります。それは役に立ちました。もう一つの問題は、テストとプロダクション用のデプロイジョブを実装することです。実際、Dockerクラウドを使用して、テスト環境と運用環境でアプリケーションを展開したいと考えています。私のアーキテクチャの説明は次のとおりです。テスト環境では、このlbの2つのコンテナの後ろにTomcat用のコンテナとデータベース用のコンテナの1つのロードバランサを使用します。私はDockerとDockerクラウドで多くの経験がありません。 Dockerクラウドにアプリケーションをデプロイできるように、プロセスを段階的に説明してください。 – yimson

関連する問題