CI 一整套服务

环境说明

  • CentOS 7.3
  • 两台机子(一台机子也是可以,内存至少要 8G)
    • 一台:Gitlab + Redis + Postgresql
      • 硬件推荐:内存 4G
      • 端口安排
        • Gitlab:10080
    • 一台:Nexus + Jenkins + SonarQube + Postgresql
      • 硬件推荐:内存 8G
      • 端口安排
        • SonarQube:19000
        • Nexus:18081
        • Jenkins:18080

Gitlab + Redis + Postgresql

  • 预计会使用内存:2G 左右
  • 这套方案来自(部分内容根据自己情况进行了修改):https://github.com/sameersbn/docker-gitlab
  • 创建宿主机挂载目录:mkdir -p /data/docker/gitlab/gitlab /data/docker/gitlab/redis /data/docker/gitlab/postgresql
  • 赋权(避免挂载的时候,一些程序需要容器中的用户的特定权限使用):chmod -R 777 /data/docker/gitlab/gitlab /data/docker/gitlab/redis /data/docker/gitlab/postgresql
  • 这里使用 docker-compose 的启动方式,所以需要创建 docker-compose.yml 文件:
  1. version: '2'
  2. services:
  3. redis:
  4. restart: always
  5. image: sameersbn/redis:latest
  6. command:
  7. - --loglevel warning
  8. volumes:
  9. - /data/docker/gitlab/redis:/var/lib/redis:Z
  10. postgresql:
  11. restart: always
  12. image: sameersbn/postgresql:9.6-2
  13. volumes:
  14. - /data/docker/gitlab/postgresql:/var/lib/postgresql:Z
  15. environment:
  16. - DB_USER=gitlab
  17. - DB_PASS=password
  18. - DB_NAME=gitlabhq_production
  19. - DB_EXTENSION=pg_trgm
  20. gitlab:
  21. restart: always
  22. image: sameersbn/gitlab:10.4.2-1
  23. depends_on:
  24. - redis
  25. - postgresql
  26. ports:
  27. - "10080:80"
  28. - "10022:22"
  29. volumes:
  30. - /data/docker/gitlab/gitlab:/home/git/data:Z
  31. environment:
  32. - DEBUG=false
  33. - DB_ADAPTER=postgresql
  34. - DB_HOST=postgresql
  35. - DB_PORT=5432
  36. - DB_USER=gitlab
  37. - DB_PASS=password
  38. - DB_NAME=gitlabhq_production
  39. - REDIS_HOST=redis
  40. - REDIS_PORT=6379
  41. - TZ=Asia/Shanghai
  42. - GITLAB_TIMEZONE=Beijing
  43. - GITLAB_HTTPS=false
  44. - SSL_SELF_SIGNED=false
  45. - GITLAB_HOST=192.168.0.105
  46. - GITLAB_PORT=10080
  47. - GITLAB_SSH_PORT=10022
  48. - GITLAB_RELATIVE_URL_ROOT=
  49. - GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alphanumeric-string
  50. - GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alphanumeric-string
  51. - GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alphanumeric-string
  52. - GITLAB_ROOT_PASSWORD=
  53. - GITLAB_ROOT_EMAIL=
  54. - GITLAB_NOTIFY_ON_BROKEN_BUILDS=true
  55. - GITLAB_NOTIFY_PUSHER=false
  56. - GITLAB_EMAIL=notifications@example.com
  57. - GITLAB_EMAIL_REPLY_TO=noreply@example.com
  58. - GITLAB_INCOMING_EMAIL_ADDRESS=reply@example.com
  59. - GITLAB_BACKUP_SCHEDULE=daily
  60. - GITLAB_BACKUP_TIME=01:00
  61. - SMTP_ENABLED=false
  62. - SMTP_DOMAIN=www.example.com
  63. - SMTP_HOST=smtp.gmail.com
  64. - SMTP_PORT=587
  65. - SMTP_USER=mailer@example.com
  66. - SMTP_PASS=password
  67. - SMTP_STARTTLS=true
  68. - SMTP_AUTHENTICATION=login
  69. - IMAP_ENABLED=false
  70. - IMAP_HOST=imap.gmail.com
  71. - IMAP_PORT=993
  72. - IMAP_USER=mailer@example.com
  73. - IMAP_PASS=password
  74. - IMAP_SSL=true
  75. - IMAP_STARTTLS=false
  76. - OAUTH_ENABLED=false
  77. - OAUTH_AUTO_SIGN_IN_WITH_PROVIDER=
  78. - OAUTH_ALLOW_SSO=
  79. - OAUTH_BLOCK_AUTO_CREATED_USERS=true
  80. - OAUTH_AUTO_LINK_LDAP_USER=false
  81. - OAUTH_AUTO_LINK_SAML_USER=false
  82. - OAUTH_EXTERNAL_PROVIDERS=
  83. - OAUTH_CAS3_LABEL=cas3
  84. - OAUTH_CAS3_SERVER=
  85. - OAUTH_CAS3_DISABLE_SSL_VERIFICATION=false
  86. - OAUTH_CAS3_LOGIN_URL=/cas/login
  87. - OAUTH_CAS3_VALIDATE_URL=/cas/p3/serviceValidate
  88. - OAUTH_CAS3_LOGOUT_URL=/cas/logout
  89. - OAUTH_GOOGLE_API_KEY=
  90. - OAUTH_GOOGLE_APP_SECRET=
  91. - OAUTH_GOOGLE_RESTRICT_DOMAIN=
  92. - OAUTH_FACEBOOK_API_KEY=
  93. - OAUTH_FACEBOOK_APP_SECRET=
  94. - OAUTH_TWITTER_API_KEY=
  95. - OAUTH_TWITTER_APP_SECRET=
  96. - OAUTH_GITHUB_API_KEY=
  97. - OAUTH_GITHUB_APP_SECRET=
  98. - OAUTH_GITHUB_URL=
  99. - OAUTH_GITHUB_VERIFY_SSL=
  100. - OAUTH_GITLAB_API_KEY=
  101. - OAUTH_GITLAB_APP_SECRET=
  102. - OAUTH_BITBUCKET_API_KEY=
  103. - OAUTH_BITBUCKET_APP_SECRET=
  104. - OAUTH_SAML_ASSERTION_CONSUMER_SERVICE_URL=
  105. - OAUTH_SAML_IDP_CERT_FINGERPRINT=
  106. - OAUTH_SAML_IDP_SSO_TARGET_URL=
  107. - OAUTH_SAML_ISSUER=
  108. - OAUTH_SAML_LABEL="Our SAML Provider"
  109. - OAUTH_SAML_NAME_IDENTIFIER_FORMAT=urn:oasis:names:tc:SAML:2.0:nameid-format:transient
  110. - OAUTH_SAML_GROUPS_ATTRIBUTE=
  111. - OAUTH_SAML_EXTERNAL_GROUPS=
  112. - OAUTH_SAML_ATTRIBUTE_STATEMENTS_EMAIL=
  113. - OAUTH_SAML_ATTRIBUTE_STATEMENTS_NAME=
  114. - OAUTH_SAML_ATTRIBUTE_STATEMENTS_FIRST_NAME=
  115. - OAUTH_SAML_ATTRIBUTE_STATEMENTS_LAST_NAME=
  116. - OAUTH_CROWD_SERVER_URL=
  117. - OAUTH_CROWD_APP_NAME=
  118. - OAUTH_CROWD_APP_PASSWORD=
  119. - OAUTH_AUTH0_CLIENT_ID=
  120. - OAUTH_AUTH0_CLIENT_SECRET=
  121. - OAUTH_AUTH0_DOMAIN=
  122. - OAUTH_AZURE_API_KEY=
  123. - OAUTH_AZURE_API_SECRET=
  124. - OAUTH_AZURE_TENANT_ID=

Nexus + Jenkins + SonarQube

  • 预计会使用内存:4G 左右
  • 创建宿主机挂载目录:mkdir -p /data/docker/ci/nexus /data/docker/ci/jenkins /data/docker/ci/jenkins/home /data/docker/ci/sonarqube /data/docker/ci/postgresql
  • 赋权(避免挂载的时候,一些程序需要容器中的用户的特定权限使用):chmod -R 777 /data/docker/ci/nexus /data/docker/ci/jenkins /data/docker/ci/jenkins/home /data/docker/ci/sonarqube /data/docker/ci/postgresql
  • 下面有一个细节要特别注意:yml 里面不能有中文。还有就是 sonar 的挂载目录不能直接挂在 /opt/sonarqube 上,不然会启动不了。
  • 这里使用 docker-compose 的启动方式,所以需要创建 docker-compose.yml 文件:
  1. version: '3'
  2. networks:
  3. prodnetwork:
  4. driver: bridge
  5. services:
  6. sonardb:
  7. image: postgres:9.6.6
  8. restart: always
  9. ports:
  10. - "5433:5432"
  11. networks:
  12. - prodnetwork
  13. volumes:
  14. - /data/docker/ci/postgresql:/var/lib/postgresql
  15. environment:
  16. - POSTGRES_USER=sonar
  17. - POSTGRES_PASSWORD=sonar
  18. sonar:
  19. image: sonarqube:6.7.1
  20. restart: always
  21. ports:
  22. - "19000:9000"
  23. - "19092:9092"
  24. #networks:
  25. #- prodnetwork
  26. depends_on:
  27. - sonardb
  28. volumes:
  29. - /data/docker/ci/sonarqube/conf:/opt/sonarqube/conf
  30. - /data/docker/ci/sonarqube/data:/opt/sonarqube/data
  31. - /data/docker/ci/sonarqube/extension:/opt/sonarqube/extensions
  32. - /data/docker/ci/sonarqube/bundled-plugins:/opt/sonarqube/lib/bundled-plugins
  33. environment:
  34. #- SONARQUBE_JDBC_URL=jdbc:postgresql://sonardb:5433/sonar
  35. - SONARQUBE_JDBC_URL=jdbc:postgresql://192.168.0.105:5433/sonar
  36. - SONARQUBE_JDBC_USERNAME=sonar
  37. - SONARQUBE_JDBC_PASSWORD=sonar
  38. nexus:
  39. image: sonatype/nexus3
  40. restart: always
  41. ports:
  42. - "18081:8081"
  43. networks:
  44. - prodnetwork
  45. volumes:
  46. - /data/docker/ci/nexus:/nexus-data
  47. jenkins:
  48. image: jenkins:2.60.3
  49. restart: always
  50. ports:
  51. - "18080:8080"
  52. networks:
  53. - prodnetwork
  54. volumes:
  55. - /var/run/docker.sock:/var/run/docker.sock
  56. - /usr/bin/docker:/usr/bin/docker
  57. - /data/docker/ci/jenkins:/var/lib/jenkins/
  58. - /data/docker/ci/jenkins/home:/var/jenkins_home
  59. depends_on:
  60. - nexus
  61. - sonar
  62. environment:
  63. - NEXUS_PORT=8081
  64. - SONAR_PORT=9000
  65. - SONAR_DB_PORT=5432