项目作者: dimMaryanto93

项目描述 :
Example build springboot with gitlab-runner docker executor locally
高级语言: Java
项目地址: git://github.com/dimMaryanto93/springboot2-gitlab-ci-runner-docker-example.git


Gitlab Runner with docker

Install gitlab-runner same as host with docker.

Setup Docker

pertama. login dulu ke docker private registry

  1. docker login -u user -p passwordnya example.registry.com

will generated ~/.docker/config.json

  1. {
  2. "auths": {
  3. "example.registry.com": {
  4. "auth": "generated-base64"
  5. }
  6. }
  7. }

Setup Gitlab Runner

setelah itu register agent executor menggunakan gitlar-runner register seperti berikut example sintaxnya:

  1. sudo gitlab-runner register \
  2. --url http://host-gitlab \
  3. --registration-token TOKEN \
  4. --executor docker

setelah itu edit /etc/gitlab-runner/config.toml

  1. concurrent = 1
  2. check_interval = 0
  3. [session_server]
  4. session_timeout = 1800
  5. [[runners]]
  6. name = "gitlab-runner-docker-executor"
  7. environment = ["DOCKER_TLS_CERTDIR="]
  8. log_level = "debug"
  9. url = "http://example.gitlab.com"
  10. token = "gitlab-runner-token-from-gitlab"
  11. executor = "docker"
  12. ### Add spesific build directory
  13. build_dir = "/builds"
  14. [runners.custom_build_dir]
  15. [runners.cache]
  16. [runners.cache.s3]
  17. [runners.cache.gcs]
  18. [runners.docker]
  19. tls_verify = false
  20. image = "default.docker.image:v1.0.0"
  21. ### Add /etc/hosts to docker container
  22. extra_hosts = ["your.domain.name:XX.XX.XX.XX"]
  23. privileged = false
  24. disable_entrypoint_overwrite = false
  25. oom_kill_disable = false
  26. disable_cache = false
  27. volumes = ["/cache"]
  28. shm_size = 0
  29. [runners.machine]
  30. IdleCount = 0
  31. MachineDriver = ""
  32. MachineName = ""
  33. OffPeakTimezone = ""
  34. OffPeakIdleCount = 0
  35. OffPeakIdleTime = 0

Setup SELINUX to disabled

Setelah itu disabled selinux, edit file /etc/selinux/config

  1. ## change SELINUX to disabled
  2. SELINUX=disabled
  3. # SELINUXTYPE= can take one of three two values:
  4. # targeted - Targeted processes are protected,
  5. # minimum - Modification of targeted policy. Only selected processes are protected.
  6. # mls - Multi Level Security protection.
  7. SELINUXTYPE=targeted

setelah itu restart.

Setup gitlab environtment

Setup gitlab ci/cd for docker authentication pull from registry, add VARIABLES DOCKER_AUTH_CONFIG di PROJECT -> Settings -> CI/CD -> Variables valuenya seperti berikut

  1. {
  2. "auths": {
  3. "example.registry.com": {
  4. "auth": "generated-base64"
  5. }
  6. }
  7. }

Push with tags prefix -release

Sekarang kita push ke gitlab repository

  1. # index repository
  2. git add .
  3. # commit
  4. git commit -m "first release"
  5. # create tags
  6. git tag -a 0.0.2-release -m "gitlab ci docker with maven docker image"
  7. # push to gitlab
  8. git push --tags

Example log gitlab ci/cd

  1. Running with gitlab-runner 12.2.0 (a987417a)
  2. on docker_repository.dimas-maryanto.com Xu3xWTXe
  3. Using Docker executor with image repository.dimas-maryanto.com:8086/maven:3.6-jdk-8 ...
  4. Authenticating with credentials from $DOCKER_AUTH_CONFIG
  5. Pulling docker image repository.dimas-maryanto.com:8086/maven:3.6-jdk-8 ...
  6. Using docker image sha256:4c81be38db66edea5bb1e31e4230d78c7a8b55cf048b590afe31465ab55dd1e4 for repository.dimas-maryanto.com:8086/maven:3.6-jdk-8 ...
  7. Authenticating with credentials from $DOCKER_AUTH_CONFIG
  8. Running on runner-Xu3xWTXe-project-152-concurrent-0 via repository.dimas-maryanto.com...
  9. Authenticating with credentials from $DOCKER_AUTH_CONFIG
  10. Fetching changes with git depth set to 50...
  11. Reinitialized existing Git repository in /builds/examples/gitlab-ci-cd/springboot2-gitlab-ci-docker/.git/
  12. From http://repository.dimas-maryanto.com/examples/gitlab-ci-cd/springboot2-gitlab-ci-docker
  13. * [new tag] 0.0.2-release -> 0.0.2-release
  14. Checking out ec1037b3 as 0.0.2-release...
  15. Removing .m2/
  16. Removing pom.xml.versionsBackup
  17. Removing target/
  18. Skipping Git submodules setup
  19. Authenticating with credentials from $DOCKER_AUTH_CONFIG
  20. Checking cache for default...
  21. No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted.
  22. Successfully extracted cache
  23. Authenticating with credentials from $DOCKER_AUTH_CONFIG
  24. Authenticating with credentials from $DOCKER_AUTH_CONFIG
  25. $ mvn versions:set -DnewVersion=$CI_COMMIT_TAG
  26. 630 [INFO] Scanning for projects...
  27. 905 [INFO]
  28. 905 [INFO] ------< com.maryanto.dimas.example:springboot2-gitlab-ci-docker >-------
  29. 906 [INFO] Building springboot2-gitlab-ci-docker 0.0.1-SNAPSHOT
  30. 907 [INFO] --------------------------------[ jar ]---------------------------------
  31. 910 [INFO]
  32. 911 [INFO] --- versions-maven-plugin:2.7:set (default-cli) @ springboot2-gitlab-ci-docker ---
  33. 1358 [INFO] Searching for local aggregator root...
  34. 1359 [INFO] Local aggregation root: /builds/examples/gitlab-ci-cd/springboot2-gitlab-ci-docker
  35. 1362 [INFO] Processing change of com.maryanto.dimas.example:springboot2-gitlab-ci-docker:0.0.1-SNAPSHOT -> 0.0.2-release
  36. 1411 [INFO] Processing com.maryanto.dimas.example:springboot2-gitlab-ci-docker
  37. 1411 [INFO] Updating project com.maryanto.dimas.example:springboot2-gitlab-ci-docker
  38. 1411 [INFO] from version 0.0.1-SNAPSHOT to 0.0.2-release
  39. 1417 [INFO]
  40. 1421 [INFO] ------------------------------------------------------------------------
  41. 1422 [INFO] BUILD SUCCESS
  42. 1422 [INFO] ------------------------------------------------------------------------
  43. 1423 [INFO] Total time: 0.808 s
  44. 1423 [INFO] Finished at: 2019-09-08T03:48:09Z
  45. 1423 [INFO] ------------------------------------------------------------------------
  46. $ mvn $MAVEN_CLI_OPTS clean package
  47. Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-04T19:00:29Z)
  48. Maven home: /usr/share/maven
  49. Java version: 1.8.0_222, vendor: Oracle Corporation, runtime: /usr/local/openjdk-8/jre
  50. Default locale: en, platform encoding: UTF-8
  51. OS name: "linux", version: "3.10.0-957.27.2.el7.x86_64", arch: "amd64", family: "unix"
  52. 593 [INFO] Error stacktraces are turned on.
  53. 628 [INFO] Scanning for projects...
  54. 824 [INFO]
  55. 824 [INFO] ------< com.maryanto.dimas.example:springboot2-gitlab-ci-docker >-------
  56. 825 [INFO] Building springboot2-gitlab-ci-docker 0.0.2-release
  57. 825 [INFO] --------------------------------[ jar ]---------------------------------
  58. 1174 [INFO]
  59. 1174 [INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ springboot2-gitlab-ci-docker ---
  60. 1252 [INFO]
  61. 1252 [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ springboot2-gitlab-ci-docker ---
  62. 1351 [INFO] Using 'UTF-8' encoding to copy filtered resources.
  63. 1355 [INFO] Copying 1 resource
  64. 1361 [INFO] Copying 0 resource
  65. 1362 [INFO]
  66. 1362 [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ springboot2-gitlab-ci-docker ---
  67. 1475 [INFO] Changes detected - recompiling the module!
  68. 1477 [INFO] Compiling 1 source file to /builds/examples/gitlab-ci-cd/springboot2-gitlab-ci-docker/target/classes
  69. 2270 [INFO]
  70. 2270 [INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ springboot2-gitlab-ci-docker ---
  71. 2272 [INFO] Using 'UTF-8' encoding to copy filtered resources.
  72. 2273 [INFO] skip non existing resourceDirectory /builds/examples/gitlab-ci-cd/springboot2-gitlab-ci-docker/src/test/resources
  73. 2274 [INFO]
  74. 2274 [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ springboot2-gitlab-ci-docker ---
  75. 2279 [INFO] Changes detected - recompiling the module!
  76. 2280 [INFO] Compiling 1 source file to /builds/examples/gitlab-ci-cd/springboot2-gitlab-ci-docker/target/test-classes
  77. 2726 [INFO]
  78. 2726 [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ springboot2-gitlab-ci-docker ---
  79. 2808 [INFO] Surefire report directory: /builds/examples/gitlab-ci-cd/springboot2-gitlab-ci-docker/target/surefire-reports
  80. 2910 [INFO]
  81. 2910 [INFO] -------------------------------------------------------
  82. 2911 [INFO] T E S T S
  83. 2911 [INFO] -------------------------------------------------------
  84. 3148 [INFO] Running com.maryanto.dimas.example.GitlabCiDockerApplicationTests
  85. 03:48:13.331 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.maryanto.dimas.example.GitlabCiDockerApplicationTests]
  86. 03:48:13.335 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
  87. 03:48:13.344 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
  88. 03:48:13.358 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.maryanto.dimas.example.GitlabCiDockerApplicationTests] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
  89. 03:48:13.367 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.maryanto.dimas.example.GitlabCiDockerApplicationTests], using SpringBootContextLoader
  90. 03:48:13.369 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.maryanto.dimas.example.GitlabCiDockerApplicationTests]: class path resource [com/maryanto/dimas/example/GitlabCiDockerApplicationTests-context.xml] does not exist
  91. 03:48:13.369 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.maryanto.dimas.example.GitlabCiDockerApplicationTests]: class path resource [com/maryanto/dimas/example/GitlabCiDockerApplicationTestsContext.groovy] does not exist
  92. 03:48:13.370 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.maryanto.dimas.example.GitlabCiDockerApplicationTests]: no resource found for suffixes {-context.xml, Context.groovy}.
  93. 03:48:13.370 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.maryanto.dimas.example.GitlabCiDockerApplicationTests]: GitlabCiDockerApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
  94. 03:48:13.398 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.maryanto.dimas.example.GitlabCiDockerApplicationTests]
  95. 03:48:13.449 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [/builds/examples/gitlab-ci-cd/springboot2-gitlab-ci-docker/target/classes/com/maryanto/dimas/example/GitlabCiDockerApplication.class]
  96. 03:48:13.450 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.maryanto.dimas.example.GitlabCiDockerApplication for test class com.maryanto.dimas.example.GitlabCiDockerApplicationTests
  97. 03:48:13.518 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.maryanto.dimas.example.GitlabCiDockerApplicationTests]: using defaults.
  98. 03:48:13.518 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
  99. 03:48:13.526 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/TransactionDefinition]
  100. 03:48:13.527 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute]
  101. 03:48:13.527 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@7a69b07, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@5e82df6a, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@3f197a46, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@636be97c, org.springframework.test.context.support.DirtiesContextTestExecutionListener@50a638b5, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@1817d444, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@6ca8564a, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@50b472aa, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@31368b99, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@1725dc0f]
  102. 03:48:13.528 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.maryanto.dimas.example.GitlabCiDockerApplicationTests]
  103. 03:48:13.529 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.maryanto.dimas.example.GitlabCiDockerApplicationTests]
  104. 03:48:13.529 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.maryanto.dimas.example.GitlabCiDockerApplicationTests]
  105. 03:48:13.529 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.maryanto.dimas.example.GitlabCiDockerApplicationTests]
  106. 03:48:13.530 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.maryanto.dimas.example.GitlabCiDockerApplicationTests]
  107. 03:48:13.530 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.maryanto.dimas.example.GitlabCiDockerApplicationTests]
  108. 03:48:13.532 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@16ec5519 testClass = GitlabCiDockerApplicationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@2f7298b testClass = GitlabCiDockerApplicationTests, locations = '{}', classes = '{class com.maryanto.dimas.example.GitlabCiDockerApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@3fd7a715, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@7f13d6e, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@33f88ab, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@33c7e1bb], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].
  109. 03:48:13.533 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.maryanto.dimas.example.GitlabCiDockerApplicationTests]
  110. 03:48:13.533 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.maryanto.dimas.example.GitlabCiDockerApplicationTests]
  111. 03:48:13.552 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=-1}
  112. . ____ _ __ _ _
  113. /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
  114. ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
  115. \\/ ___)| |_)| | | | | || (_| | ) ) ) )
  116. ' |____| .__|_| |_|_| |_\__, | / / / /
  117. =========|_|==============|___/=/_/_/_/
  118. :: Spring Boot :: (v2.1.8.RELEASE)
  119. 2019-09-08 03:48:13.745 INFO 94 --- [ main] c.m.d.e.GitlabCiDockerApplicationTests : Starting GitlabCiDockerApplicationTests on runner-Xu3xWTXe-project-152-concurrent-0 with PID 94 (started by root in /builds/examples/gitlab-ci-cd/springboot2-gitlab-ci-docker)
  120. 2019-09-08 03:48:13.748 INFO 94 --- [ main] c.m.d.e.GitlabCiDockerApplicationTests : No active profile set, falling back to default profiles: default
  121. 2019-09-08 03:48:15.107 INFO 94 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
  122. 2019-09-08 03:48:15.637 INFO 94 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
  123. 2019-09-08 03:48:15.679 INFO 94 --- [ main] c.m.d.e.GitlabCiDockerApplicationTests : Started GitlabCiDockerApplicationTests in 2.12 seconds (JVM running for 2.597)
  124. 5697 [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.535 s - in com.maryanto.dimas.example.GitlabCiDockerApplicationTests
  125. 2019-09-08 03:48:15.812 INFO 94 --- [ Thread-3] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
  126. 6041 [INFO]
  127. 6041 [INFO] Results:
  128. 6041 [INFO]
  129. 6041 [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
  130. 6041 [INFO]
  131. 6048 [INFO]
  132. 6048 [INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) @ springboot2-gitlab-ci-docker ---
  133. 6181 [INFO] Building jar: /builds/examples/gitlab-ci-cd/springboot2-gitlab-ci-docker/target/springboot2-gitlab-ci-docker-0.0.2-release.jar
  134. 6208 [INFO]
  135. 6209 [INFO] --- spring-boot-maven-plugin:2.1.8.RELEASE:repackage (repackage) @ springboot2-gitlab-ci-docker ---
  136. 6535 [INFO] Replacing main artifact with repackaged archive
  137. 6535 [INFO] ------------------------------------------------------------------------
  138. 6535 [INFO] BUILD SUCCESS
  139. 6535 [INFO] ------------------------------------------------------------------------
  140. 6536 [INFO] Total time: 5.923 s
  141. 6536 [INFO] Finished at: 2019-09-08T03:48:16Z
  142. 6537 [INFO] ------------------------------------------------------------------------
  143. Authenticating with credentials from $DOCKER_AUTH_CONFIG
  144. Creating cache default...
  145. .m2/repository: found 2814 matching files
  146. Archive is up to date!
  147. Created cache
  148. Authenticating with credentials from $DOCKER_AUTH_CONFIG
  149. Uploading artifacts...
  150. target/*.jar: found 1 matching files
  151. Uploading artifacts to coordinator... ok id=79 responseStatus=201 Created token=pt2u7RVQ
  152. Job succeeded