compose.yaml.j2 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. services:
  2. {{ service_name }}:
  3. image: docker.io/gitlab/gitlab-ce:18.5.1-ce.0
  4. {% if not swarm_enabled %}
  5. restart: {{ restart_policy }}
  6. container_name: {{ container_name }}
  7. {% endif %}
  8. hostname: {{ container_hostname }}
  9. shm_size: '256m'
  10. {% if network_mode == 'host' %}
  11. network_mode: host
  12. {% else %}
  13. networks:
  14. {% if traefik_enabled %}
  15. {{ traefik_network }}:
  16. {% endif %}
  17. {% if network_mode == 'macvlan' %}
  18. {{ network_name }}:
  19. ipv4_address: {{ network_macvlan_ipv4_address }}
  20. {% elif network_mode == 'bridge' %}
  21. {{ network_name }}:
  22. {% endif %}
  23. {% endif %}
  24. env_file:
  25. - ./.env
  26. {% if swarm_enabled %}
  27. configs:
  28. - source: gitlab_config
  29. target: /etc/gitlab/gitlab.rb
  30. {% endif %}
  31. {% if network_mode == 'bridge' %}
  32. ports:
  33. {% if not traefik_enabled %}
  34. {% if swarm_enabled %}
  35. - target: 80
  36. published: {{ ports_http }}
  37. protocol: tcp
  38. mode: host
  39. {% else %}
  40. - "{{ ports_http }}:80"
  41. {% endif %}
  42. {% endif %}
  43. - "{{ ports_ssh }}:22"
  44. {% if registry_enabled %}
  45. - "{{ ports_registry }}:5000"
  46. {% endif %}
  47. {% endif %}
  48. volumes:
  49. {% if not swarm_enabled %}
  50. - ./config/gitlab.rb:/etc/gitlab/gitlab.rb:ro
  51. {% endif %}
  52. {% if volume_mode == 'mount' %}
  53. - {{ volume_mount_path }}/config:/etc/gitlab
  54. - {{ volume_mount_path }}/logs:/var/log/gitlab
  55. - {{ volume_mount_path }}/data:/var/opt/gitlab
  56. {% else %}
  57. - gitlab-config:/etc/gitlab
  58. - gitlab-logs:/var/log/gitlab
  59. - gitlab-data:/var/opt/gitlab
  60. {% endif %}
  61. {% if traefik_enabled and not swarm_enabled %}
  62. labels:
  63. - traefik.enable=true
  64. - traefik.docker.network={{ traefik_network }}
  65. - traefik.http.services.{{ service_name }}-web.loadBalancer.server.port=80
  66. - traefik.http.routers.{{ service_name }}-http.service={{ service_name }}-web
  67. - traefik.http.routers.{{ service_name }}-http.rule=Host(`{{ traefik_host }}.{{ traefik_domain }}`)
  68. - traefik.http.routers.{{ service_name }}-http.entrypoints={{ traefik_entrypoint }}
  69. {% if traefik_tls_enabled %}
  70. - traefik.http.routers.{{ service_name }}-https.service={{ service_name }}-web
  71. - traefik.http.routers.{{ service_name }}-https.rule=Host(`{{ traefik_host }}.{{ traefik_domain }}`)
  72. - traefik.http.routers.{{ service_name }}-https.entrypoints={{ traefik_tls_entrypoint }}
  73. - traefik.http.routers.{{ service_name }}-https.tls=true
  74. - traefik.http.routers.{{ service_name }}-https.tls.certresolver={{ traefik_tls_certresolver }}
  75. {% endif %}
  76. {% if registry_enabled %}
  77. - traefik.http.services.{{ service_name }}-registry.loadBalancer.server.port=5000
  78. - traefik.http.routers.{{ service_name }}-registry-http.service={{ service_name }}-registry
  79. - traefik.http.routers.{{ service_name }}-registry-http.rule=Host(`{{ traefik_registry_host }}`)
  80. - traefik.http.routers.{{ service_name }}-registry-http.entrypoints={{ traefik_entrypoint }}
  81. {% if traefik_tls_enabled %}
  82. - traefik.http.routers.{{ service_name }}-registry-https.service={{ service_name }}-registry
  83. - traefik.http.routers.{{ service_name }}-registry-https.rule=Host(`{{ traefik_registry_host }}`)
  84. - traefik.http.routers.{{ service_name }}-registry-https.entrypoints={{ traefik_tls_entrypoint }}
  85. - traefik.http.routers.{{ service_name }}-registry-https.tls=true
  86. - traefik.http.routers.{{ service_name }}-registry-https.tls.certresolver={{ traefik_tls_certresolver }}
  87. {% endif %}
  88. {% endif %}
  89. {% endif %}
  90. {% if swarm_enabled %}
  91. secrets:
  92. - source: {{ gitlab_root_password_secret_name }}
  93. target: /run/secrets/gitlab_root_password
  94. mode: 0400
  95. {% if registry_enabled %}
  96. - source: {{ gitlab_registry_secret_name }}
  97. target: /run/secrets/gitlab_registry_secret
  98. mode: 0400
  99. {% endif %}
  100. deploy:
  101. mode: {{ swarm_placement_mode }}
  102. {% if swarm_placement_mode == 'replicated' %}
  103. replicas: {{ swarm_replicas }}
  104. {% endif %}
  105. {% if swarm_placement_host %}
  106. placement:
  107. constraints:
  108. - node.hostname == {{ swarm_placement_host }}
  109. {% endif %}
  110. restart_policy:
  111. condition: on-failure
  112. {% if resources_enabled %}
  113. resources:
  114. limits:
  115. cpus: '{{ resources_cpu_limit }}'
  116. memory: {{ resources_memory_limit }}
  117. {% if swarm_enabled %}
  118. reservations:
  119. cpus: '{{ resources_cpu_reservation }}'
  120. memory: {{ resources_memory_reservation }}
  121. {% endif %}
  122. {% endif %}
  123. {% if swarm_enabled and traefik_enabled %}
  124. labels:
  125. - traefik.enable=true
  126. - traefik.docker.network={{ traefik_network }}
  127. - traefik.http.services.{{ service_name }}-web.loadBalancer.server.port=80
  128. - traefik.http.routers.{{ service_name }}-http.service={{ service_name }}-web
  129. - traefik.http.routers.{{ service_name }}-http.rule=Host(`{{ traefik_host }}.{{ traefik_domain }}`)
  130. - traefik.http.routers.{{ service_name }}-http.entrypoints={{ traefik_entrypoint }}
  131. {% if traefik_tls_enabled %}
  132. - traefik.http.routers.{{ service_name }}-https.service={{ service_name }}-web
  133. - traefik.http.routers.{{ service_name }}-https.rule=Host(`{{ traefik_host }}.{{ traefik_domain }}`)
  134. - traefik.http.routers.{{ service_name }}-https.entrypoints={{ traefik_tls_entrypoint }}
  135. - traefik.http.routers.{{ service_name }}-https.tls=true
  136. - traefik.http.routers.{{ service_name }}-https.tls.certresolver={{ traefik_tls_certresolver }}
  137. {% endif %}
  138. {% if registry_enabled %}
  139. - traefik.http.services.{{ service_name }}-registry.loadBalancer.server.port=5000
  140. - traefik.http.routers.{{ service_name }}-registry-http.service={{ service_name }}-registry
  141. - traefik.http.routers.{{ service_name }}-registry-http.rule=Host(`{{ traefik_registry_host }}`)
  142. - traefik.http.routers.{{ service_name }}-registry-http.entrypoints={{ traefik_entrypoint }}
  143. {% if traefik_tls_enabled %}
  144. - traefik.http.routers.{{ service_name }}-registry-https.service={{ service_name }}-registry
  145. - traefik.http.routers.{{ service_name }}-registry-https.rule=Host(`{{ traefik_registry_host }}`)
  146. - traefik.http.routers.{{ service_name }}-registry-https.entrypoints={{ traefik_tls_entrypoint }}
  147. - traefik.http.routers.{{ service_name }}-registry-https.tls=true
  148. - traefik.http.routers.{{ service_name }}-registry-https.tls.certresolver={{ traefik_tls_certresolver }}
  149. {% endif %}
  150. {% endif %}
  151. {% endif %}
  152. {% endif %}
  153. {% if volume_mode == 'local' %}
  154. volumes:
  155. gitlab-config:
  156. driver: local
  157. gitlab-logs:
  158. driver: local
  159. gitlab-data:
  160. driver: local
  161. {% elif volume_mode == 'nfs' %}
  162. volumes:
  163. gitlab-config:
  164. driver: local
  165. driver_opts:
  166. type: nfs
  167. o: addr={{ volume_nfs_server }},{{ volume_nfs_options }}
  168. device: ":{{ volume_nfs_path }}/config"
  169. gitlab-logs:
  170. driver: local
  171. driver_opts:
  172. type: nfs
  173. o: addr={{ volume_nfs_server }},{{ volume_nfs_options }}
  174. device: ":{{ volume_nfs_path }}/logs"
  175. gitlab-data:
  176. driver: local
  177. driver_opts:
  178. type: nfs
  179. o: addr={{ volume_nfs_server }},{{ volume_nfs_options }}
  180. device: ":{{ volume_nfs_path }}/data"
  181. {% endif %}
  182. {% if swarm_enabled %}
  183. configs:
  184. gitlab_config:
  185. file: ./config/gitlab.rb
  186. secrets:
  187. {{ gitlab_root_password_secret_name }}:
  188. file: ./.env.secret
  189. {% if registry_enabled %}
  190. {{ gitlab_registry_secret_name }}:
  191. file: ./.env.registry.secret
  192. {% endif %}
  193. {% endif %}
  194. {% if network_mode != 'host' %}
  195. networks:
  196. {{ network_name }}:
  197. {% if network_external %}
  198. external: true
  199. {% else %}
  200. {% if network_mode == 'macvlan' %}
  201. driver: macvlan
  202. driver_opts:
  203. parent: {{ network_macvlan_parent_interface }}
  204. ipam:
  205. config:
  206. - subnet: {{ network_macvlan_subnet }}
  207. gateway: {{ network_macvlan_gateway }}
  208. name: {{ network_name }}
  209. {% elif swarm_enabled %}
  210. driver: overlay
  211. attachable: true
  212. {% else %}
  213. driver: bridge
  214. {% endif %}
  215. {% endif %}
  216. {% if traefik_enabled %}
  217. {{ traefik_network }}:
  218. external: true
  219. {% endif %}
  220. {% endif %}