smartmachine 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (229) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.rdoc +0 -0
  3. data/README.rdoc +87 -0
  4. data/bin/buildpacker +8 -0
  5. data/bin/prereceiver +8 -0
  6. data/bin/smartmachine +81 -0
  7. data/bin/smartrunner +28 -0
  8. data/lib/smart_machine.rb +24 -0
  9. data/lib/smart_machine/apps.rb +14 -0
  10. data/lib/smart_machine/apps/app.rb +182 -0
  11. data/lib/smart_machine/apps/rails.rb +250 -0
  12. data/lib/smart_machine/base.rb +11 -0
  13. data/lib/smart_machine/boot.rb +31 -0
  14. data/lib/smart_machine/buildpacker.rb +106 -0
  15. data/lib/smart_machine/credentials.rb +126 -0
  16. data/lib/smart_machine/docker.rb +144 -0
  17. data/lib/smart_machine/engine.rb +82 -0
  18. data/lib/smart_machine/engine/Dockerfile +27 -0
  19. data/lib/smart_machine/engine/buildpacks/rails/Dockerfile +21 -0
  20. data/lib/smart_machine/gem_version.rb +17 -0
  21. data/lib/smart_machine/grids.rb +15 -0
  22. data/lib/smart_machine/grids/elasticsearch.rb +97 -0
  23. data/lib/smart_machine/grids/elasticsearch/.keep +0 -0
  24. data/lib/smart_machine/grids/minio.rb +77 -0
  25. data/lib/smart_machine/grids/minio/.keep +0 -0
  26. data/lib/smart_machine/grids/mysql.rb +66 -0
  27. data/lib/smart_machine/grids/mysql/docker-entrypoint-initdb.d/.keep +0 -0
  28. data/lib/smart_machine/grids/nginx.rb +137 -0
  29. data/lib/smart_machine/grids/nginx/.keep +0 -0
  30. data/lib/smart_machine/grids/prereceiver.rb +170 -0
  31. data/lib/smart_machine/grids/prereceiver/Dockerfile +20 -0
  32. data/lib/smart_machine/grids/prereceiver/fcgiwrap/APKBUILD +49 -0
  33. data/lib/smart_machine/grids/prereceiver/fcgiwrap/fcgiwrap.confd +6 -0
  34. data/lib/smart_machine/grids/prereceiver/fcgiwrap/fcgiwrap.initd +43 -0
  35. data/lib/smart_machine/grids/prereceiver/fcgiwrap/fcgiwrap.pre-install +7 -0
  36. data/lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/APKINDEX.tar.gz +0 -0
  37. data/lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/fcgiwrap-1.1.1-r4.apk +0 -0
  38. data/lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/fcgiwrap-doc-1.1.1-r4.apk +0 -0
  39. data/lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/fcgiwrap-openrc-1.1.1-r4.apk +0 -0
  40. data/lib/smart_machine/grids/redis.rb +58 -0
  41. data/lib/smart_machine/grids/redis/.keep +0 -0
  42. data/lib/smart_machine/grids/solr.rb +99 -0
  43. data/lib/smart_machine/grids/solr/config/.keep +0 -0
  44. data/lib/smart_machine/grids/solr/config/README.txt +77 -0
  45. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/contractions_ca.txt +8 -0
  46. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/contractions_fr.txt +15 -0
  47. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/contractions_ga.txt +5 -0
  48. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/contractions_it.txt +23 -0
  49. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/hyphenations_ga.txt +5 -0
  50. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stemdict_nl.txt +6 -0
  51. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stoptags_ja.txt +420 -0
  52. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_ar.txt +125 -0
  53. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_bg.txt +193 -0
  54. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_ca.txt +220 -0
  55. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_cz.txt +172 -0
  56. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_da.txt +110 -0
  57. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_de.txt +294 -0
  58. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_el.txt +78 -0
  59. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_en.txt +54 -0
  60. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_es.txt +356 -0
  61. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_eu.txt +99 -0
  62. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_fa.txt +313 -0
  63. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_fi.txt +97 -0
  64. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_fr.txt +186 -0
  65. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_ga.txt +110 -0
  66. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_gl.txt +161 -0
  67. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_hi.txt +235 -0
  68. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_hu.txt +211 -0
  69. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_hy.txt +46 -0
  70. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_id.txt +359 -0
  71. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_it.txt +303 -0
  72. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_ja.txt +127 -0
  73. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_lv.txt +172 -0
  74. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_nl.txt +119 -0
  75. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_no.txt +194 -0
  76. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_pt.txt +253 -0
  77. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_ro.txt +233 -0
  78. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_ru.txt +243 -0
  79. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_sv.txt +133 -0
  80. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_th.txt +119 -0
  81. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/stopwords_tr.txt +212 -0
  82. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/lang/userdict_ja.txt +29 -0
  83. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/managed-schema +1007 -0
  84. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/params.json +20 -0
  85. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/protwords.txt +21 -0
  86. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/solrconfig.xml +1355 -0
  87. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/stopwords.txt +14 -0
  88. data/lib/smart_machine/grids/solr/config/configsets/_default/conf/synonyms.txt +29 -0
  89. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/_rest_managed.json +1 -0
  90. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/_schema_analysis_stopwords_english.json +38 -0
  91. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/_schema_analysis_synonyms_english.json +11 -0
  92. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/clustering/carrot2/README.txt +11 -0
  93. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/clustering/carrot2/kmeans-attributes.xml +19 -0
  94. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/clustering/carrot2/lingo-attributes.xml +24 -0
  95. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/clustering/carrot2/stc-attributes.xml +19 -0
  96. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/currency.xml +67 -0
  97. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/elevate.xml +42 -0
  98. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/contractions_ca.txt +8 -0
  99. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/contractions_fr.txt +15 -0
  100. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/contractions_ga.txt +5 -0
  101. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/contractions_it.txt +23 -0
  102. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/hyphenations_ga.txt +5 -0
  103. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stemdict_nl.txt +6 -0
  104. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stoptags_ja.txt +420 -0
  105. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_ar.txt +125 -0
  106. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_bg.txt +193 -0
  107. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_ca.txt +220 -0
  108. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_ckb.txt +136 -0
  109. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_cz.txt +172 -0
  110. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_da.txt +110 -0
  111. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_de.txt +294 -0
  112. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_el.txt +78 -0
  113. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_en.txt +54 -0
  114. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_es.txt +356 -0
  115. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_eu.txt +99 -0
  116. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_fa.txt +313 -0
  117. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_fi.txt +97 -0
  118. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_fr.txt +186 -0
  119. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_ga.txt +110 -0
  120. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_gl.txt +161 -0
  121. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_hi.txt +235 -0
  122. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_hu.txt +211 -0
  123. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_hy.txt +46 -0
  124. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_id.txt +359 -0
  125. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_it.txt +303 -0
  126. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_ja.txt +127 -0
  127. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_lv.txt +172 -0
  128. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_nl.txt +119 -0
  129. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_no.txt +194 -0
  130. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_pt.txt +253 -0
  131. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_ro.txt +233 -0
  132. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_ru.txt +243 -0
  133. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_sv.txt +133 -0
  134. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_th.txt +119 -0
  135. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/stopwords_tr.txt +212 -0
  136. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/lang/userdict_ja.txt +29 -0
  137. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/managed-schema +1187 -0
  138. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/mapping-FoldToASCII.txt +3813 -0
  139. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/mapping-ISOLatin1Accent.txt +246 -0
  140. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/params.json +11 -0
  141. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/protwords.txt +21 -0
  142. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/solrconfig.xml +1616 -0
  143. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/spellings.txt +2 -0
  144. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/stopwords.txt +14 -0
  145. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/synonyms.txt +29 -0
  146. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/update-script.js +53 -0
  147. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/README.txt +101 -0
  148. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/VM_global_library.vm +186 -0
  149. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/browse.vm +33 -0
  150. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/cluster.vm +19 -0
  151. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/cluster_results.vm +31 -0
  152. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/debug.vm +28 -0
  153. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/did_you_mean.vm +11 -0
  154. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/error.vm +11 -0
  155. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/facet_fields.vm +24 -0
  156. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/facet_pivot.vm +12 -0
  157. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/facet_queries.vm +12 -0
  158. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/facet_ranges.vm +23 -0
  159. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/facets.vm +10 -0
  160. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/footer.vm +43 -0
  161. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/head.vm +37 -0
  162. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/header.vm +7 -0
  163. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/hit.vm +25 -0
  164. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/hit_grouped.vm +43 -0
  165. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/hit_plain.vm +25 -0
  166. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/join_doc.vm +20 -0
  167. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/jquery.autocomplete.css +48 -0
  168. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/jquery.autocomplete.js +763 -0
  169. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/layout.vm +24 -0
  170. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/main.css +231 -0
  171. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/mime_type_lists.vm +68 -0
  172. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/pagination_bottom.vm +22 -0
  173. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/pagination_top.vm +29 -0
  174. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/product_doc.vm +32 -0
  175. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/query.vm +42 -0
  176. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/query_form.vm +64 -0
  177. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/query_group.vm +43 -0
  178. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/query_spatial.vm +75 -0
  179. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/results_list.vm +22 -0
  180. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/richtext_doc.vm +153 -0
  181. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/suggest.vm +8 -0
  182. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/velocity/tabs.vm +50 -0
  183. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/xslt/example.xsl +132 -0
  184. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/xslt/example_atom.xsl +67 -0
  185. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/xslt/example_rss.xsl +66 -0
  186. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/xslt/luke.xsl +337 -0
  187. data/lib/smart_machine/grids/solr/config/configsets/sample_techproducts_configs/conf/xslt/updateXml.xsl +70 -0
  188. data/lib/smart_machine/grids/solr/config/configsets/sunspot/conf/_rest_managed.json +1 -0
  189. data/lib/smart_machine/grids/solr/config/configsets/sunspot/conf/admin-extra.html +31 -0
  190. data/lib/smart_machine/grids/solr/config/configsets/sunspot/conf/currency.xml +67 -0
  191. data/lib/smart_machine/grids/solr/config/configsets/sunspot/conf/elevate.xml +36 -0
  192. data/lib/smart_machine/grids/solr/config/configsets/sunspot/conf/lang/stopwords_en.txt +54 -0
  193. data/lib/smart_machine/grids/solr/config/configsets/sunspot/conf/mapping-ISOLatin1Accent.txt +246 -0
  194. data/lib/smart_machine/grids/solr/config/configsets/sunspot/conf/protwords.txt +21 -0
  195. data/lib/smart_machine/grids/solr/config/configsets/sunspot/conf/schema.xml +278 -0
  196. data/lib/smart_machine/grids/solr/config/configsets/sunspot/conf/scripts.conf +24 -0
  197. data/lib/smart_machine/grids/solr/config/configsets/sunspot/conf/solrconfig.xml +632 -0
  198. data/lib/smart_machine/grids/solr/config/configsets/sunspot/conf/spellings.txt +2 -0
  199. data/lib/smart_machine/grids/solr/config/configsets/sunspot/conf/synonyms.txt +29 -0
  200. data/lib/smart_machine/grids/solr/config/lib/.keep +0 -0
  201. data/lib/smart_machine/grids/solr/config/solr.xml +53 -0
  202. data/lib/smart_machine/grids/solr/config/zoo.cfg +31 -0
  203. data/lib/smart_machine/grids/solr/docker-entrypoint-initdb.d/.keep +0 -0
  204. data/lib/smart_machine/grids/solr/sunspot/conf/schema.xml +278 -0
  205. data/lib/smart_machine/grids/solr/sunspot/conf/solrconfig.xml +632 -0
  206. data/lib/smart_machine/logger.rb +35 -0
  207. data/lib/smart_machine/machine.rb +192 -0
  208. data/lib/smart_machine/ssh.rb +43 -0
  209. data/lib/smart_machine/sync.rb +108 -0
  210. data/lib/smart_machine/templates/dotsmartmachine/apps/containers/.keep +0 -0
  211. data/lib/smart_machine/templates/dotsmartmachine/apps/repositories/.keep +0 -0
  212. data/lib/smart_machine/templates/dotsmartmachine/config/environment.rb +18 -0
  213. data/lib/smart_machine/templates/dotsmartmachine/config/users.yml +4 -0
  214. data/lib/smart_machine/templates/dotsmartmachine/grids/elasticsearch/data/.keep +0 -0
  215. data/lib/smart_machine/templates/dotsmartmachine/grids/elasticsearch/logs/.keep +0 -0
  216. data/lib/smart_machine/templates/dotsmartmachine/grids/minio/data/.keep +0 -0
  217. data/lib/smart_machine/templates/dotsmartmachine/grids/mysql/data/.keep +0 -0
  218. data/lib/smart_machine/templates/dotsmartmachine/grids/nginx/certificates/.keep +0 -0
  219. data/lib/smart_machine/templates/dotsmartmachine/grids/nginx/fastcgi.conf +11 -0
  220. data/lib/smart_machine/templates/dotsmartmachine/grids/nginx/htpasswd/.keep +0 -0
  221. data/lib/smart_machine/templates/dotsmartmachine/grids/nginx/nginx.tmpl +373 -0
  222. data/lib/smart_machine/templates/dotsmartmachine/grids/prereceiver/pre-receive +17 -0
  223. data/lib/smart_machine/templates/dotsmartmachine/grids/redis/data/.keep +0 -0
  224. data/lib/smart_machine/templates/dotsmartmachine/grids/solr/solr/.keep +0 -0
  225. data/lib/smart_machine/templates/dotsmartmachine/tmp/.keep +0 -0
  226. data/lib/smart_machine/user.rb +38 -0
  227. data/lib/smart_machine/version.rb +10 -0
  228. metadata +297 -12
  229. data/README.md +0 -9
@@ -0,0 +1,35 @@
1
+ require "logger"
2
+
3
+ $stdout.sync = true
4
+
5
+ module SmartMachine
6
+ module Logger
7
+ def logger
8
+ @logger ||= SmartMachine::Logger.logger_for(self.class.name)
9
+ end
10
+
11
+ # Use a hash class-ivar to cache a unique Logger per class:
12
+ @loggers = {}
13
+
14
+ def self.included(base)
15
+ class << base
16
+ def logger
17
+ @logger ||= SmartMachine::Logger.logger_for(self.name)
18
+ end
19
+ end
20
+ end
21
+
22
+ class << self
23
+ def logger_for(classname)
24
+ @loggers[classname] ||= configure_logger_for(classname)
25
+ end
26
+
27
+ def configure_logger_for(classname)
28
+ logger = ::Logger.new($stdout)
29
+ logger.level = ::Logger.const_get("#{SmartMachine.config.logger_level}".upcase)
30
+ logger.progname = classname
31
+ logger
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,192 @@
1
+ require "net/ssh"
2
+
3
+ # The main SmartMachine Machine driver
4
+ module SmartMachine
5
+ class Machine < SmartMachine::Base
6
+ def initialize
7
+ end
8
+
9
+ def create(*args)
10
+ args.flatten!
11
+
12
+ raise "Please specify a machine name" if args.empty?
13
+
14
+ name = args.shift
15
+ pathname = File.expand_path "./#{name}"
16
+
17
+ self.setup_dotsmartmachine(pathname)
18
+
19
+ puts "New machine #{name} has been created."
20
+ end
21
+
22
+ def init_local(*args)
23
+ args.flatten!
24
+
25
+ pathname = File.expand_path "~/.smartmachine"
26
+
27
+ if args.delete("--force")
28
+ puts "Removing all the data to reinitialize."
29
+ FileUtils.rmtree(pathname)
30
+ end
31
+
32
+ if Dir.exist?(pathname)
33
+ puts "SmartMachine Local already initialized. If you want to delete all the data and reinitialize, please use the --force option."
34
+ return
35
+ end
36
+
37
+ self.setup_dotsmartmachine(pathname)
38
+
39
+ puts "SmartMachine Local Initialised."
40
+ end
41
+
42
+ def installer(*args)
43
+ args.flatten!
44
+
45
+ action = args.shift
46
+
47
+ if args.empty? || args.include?("docker")
48
+ docker = SmartMachine::Docker.new
49
+ docker.public_send(action)
50
+ end
51
+
52
+ if args.empty? || args.include?("engine")
53
+ engine = SmartMachine::Engine.new
54
+ engine.public_send(action)
55
+ end
56
+
57
+ if args.empty? || args.include?("buildpacker")
58
+ buildpacker = SmartMachine::Buildpacker.new
59
+ buildpacker.public_send(action)
60
+ end
61
+
62
+ if args.empty? || args.include?("prereceiver")
63
+ prereceiver = SmartMachine::Grids::Prereceiver.new
64
+ prereceiver.public_send(action)
65
+ end
66
+
67
+ if args.empty? || args.include?("elasticsearch")
68
+ elasticsearch = SmartMachine::Grids::Elasticsearch.new
69
+ elasticsearch.public_send(action)
70
+ end
71
+ end
72
+
73
+ def grids(*args)
74
+ args.flatten!
75
+
76
+ if args.delete("--local")
77
+ exec "smartmachine runner grids #{args.join(" ")}"
78
+ else
79
+ ssh = SmartMachine::SSH.new
80
+ ssh.run "smartmachine runner grids #{args.join(" ")}"
81
+ end
82
+ end
83
+
84
+ def apps(*args)
85
+ args.flatten!
86
+
87
+ if args.delete("--local")
88
+ exec "smartmachine runner apps #{args.join(" ")}"
89
+ else
90
+ ssh = SmartMachine::SSH.new
91
+ ssh.run "smartmachine runner apps #{args.join(" ")}"
92
+ end
93
+ end
94
+
95
+ def ps(*args)
96
+ args.flatten!
97
+
98
+ if args.delete("--local")
99
+ exec "docker ps #{args.join(' ')}"
100
+ else
101
+ ssh = SmartMachine::SSH.new
102
+ ssh.run "docker ps #{args.join(' ')}"
103
+ end
104
+ end
105
+
106
+ def logs(*args)
107
+ args.flatten!
108
+
109
+ if args.delete("--local")
110
+ exec "docker logs #{args.join(' ')}"
111
+ else
112
+ ssh = SmartMachine::SSH.new
113
+ ssh.run "docker logs #{args.join(' ')}"
114
+ end
115
+ end
116
+
117
+ def ssh
118
+ ssh = SmartMachine::SSH.new
119
+ ssh.login
120
+ end
121
+
122
+ def getting_started
123
+ # puts 'You may be prompted to make a menu selection when the Grub package is updated on Ubuntu. If prompted, select keep the local version currently installed.'
124
+
125
+ # apt-get update && apt-get upgrade
126
+
127
+ # hostnamectl set-hostname example_hostname
128
+
129
+ # /etc/hosts
130
+ # 127.0.0.1 localhost.localdomain localhost
131
+ # 203.0.113.10 hostname.example.com hostname
132
+ # 2600:3c01::a123:b456:c789:d012 hostname.example.com hostname
133
+ # Add DNS records for IPv4 and IPv6 for ip addresses and their fully qualified domain names FQDN
134
+
135
+ # dpkg-reconfigure tzdata
136
+ # date
137
+ end
138
+
139
+ def securing_your_server
140
+ # sudo apt install unattended-upgrades
141
+
142
+ # sudo nano /etc/apt/apt.conf.d/20auto-upgrades
143
+ # APT::Periodic::Update-Package-Lists "1";
144
+ # APT::Periodic::Download-Upgradeable-Packages "1";
145
+ # APT::Periodic::AutocleanInterval "7";
146
+ # APT::Periodic::Unattended-Upgrade "1";
147
+
148
+ # sudo apt install apticron
149
+ # /etc/apticron/apticron.conf
150
+ # EMAIL="root@example.com"
151
+
152
+ # adduser example_user
153
+ # adduser example_user sudo
154
+
155
+ # mkdir -p ~/.ssh && sudo chmod -R 700 ~/.ssh/
156
+ # scp ~/.ssh/id_rsa.pub example_user@203.0.113.10:~/.ssh/authorized_keys
157
+ # sudo chmod -R 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys
158
+
159
+ # sudo nano /etc/ssh/sshd_config
160
+ # PermitRootLogin no
161
+ # PasswordAuthentication no
162
+ # echo 'AddressFamily inet' | sudo tee -a /etc/ssh/sshd_config
163
+ # sudo systemctl restart sshd
164
+
165
+ # sudo apt-get update && sudo apt-get upgrade -y
166
+ # sudo apt-get install fail2ban
167
+ # sudo apt-get install sendmail
168
+ # sudo ufw allow ssh
169
+ # sudo ufw enable
170
+ # sudo cp /etc/fail2ban/fail2ban.conf /etc/fail2ban/fail2ban.local
171
+ # sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
172
+ # Change destmail, sendername, sender
173
+ # Change action = %(action_mwl)s
174
+ # sudo fail2ban-client reload
175
+ # sudo fail2ban-client status
176
+ end
177
+
178
+ def in_local_machine_dir?
179
+ File.file?("./config/master.key")
180
+ end
181
+
182
+ def setup_dotsmartmachine(pathname)
183
+ FileUtils.mkdir pathname
184
+ FileUtils.cp_r "#{SmartMachine.config.root_path}/lib/smart_machine/templates/dotsmartmachine/.", pathname
185
+ FileUtils.chdir pathname do
186
+ credentials = SmartMachine::Credentials.new
187
+ credentials.create
188
+ system("git init && git add . && git commit -m 'initial commit'")
189
+ end
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,43 @@
1
+ require "net/ssh"
2
+
3
+ # The main SmartMachine SSH driver
4
+ module SmartMachine
5
+ class SSH < SmartMachine::Base
6
+ def initialize
7
+ end
8
+
9
+ def run(*commands)
10
+ commands.flatten!
11
+ Net::SSH.start(SmartMachine.credentials.machine[:address], SmartMachine.credentials.machine[:username], { port: SmartMachine.credentials.machine[:port], password: SmartMachine.credentials.machine[:password] }) do |ssh|
12
+ channel = ssh.open_channel do |channel, success|
13
+ channel.request_pty do |channel, success|
14
+ channel.exec commands.join(';') do |channel, success|
15
+ raise "Could not execute command" unless success
16
+
17
+ channel.on_data do |channel, data|
18
+ $stdout.print data
19
+
20
+ if data =~ /^\[sudo\] password for /
21
+ channel.send_data "#{SmartMachine.credentials.machine[:password]}\n"
22
+ end
23
+ end
24
+
25
+ channel.on_extended_data do |channel, type, data|
26
+ $stderr.print data
27
+ end
28
+
29
+ channel.on_close do |channel|
30
+ # puts "done!"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ channel.wait
36
+ end
37
+ end
38
+
39
+ def login
40
+ exec "ssh #{SmartMachine.credentials.machine[:username]}@#{SmartMachine.credentials.machine[:address]}"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,108 @@
1
+ module SmartMachine
2
+ class Sync < SmartMachine::Base
3
+
4
+ def run(**params)
5
+ puts "-----> Syncing SmartMachine"
6
+
7
+ only = params[:only] ? Array(params[:only]).flatten : [:push, :pull]
8
+
9
+ pull if only.include? :pull
10
+ yield if block_given?
11
+ push if only.include? :push
12
+
13
+ puts "-----> Syncing SmartMachine Complete"
14
+ end
15
+
16
+ private
17
+
18
+ def pull
19
+ print "-----> Sync pulling ... "
20
+ system("rsync -azumv --delete --include={#{pull_files_list}} --exclude=* -e ssh #{SmartMachine.credentials.machine[:username]}@#{SmartMachine.credentials.machine[:address]}:~/.smartmachine/ .")
21
+ puts "done"
22
+ end
23
+
24
+ def push
25
+ print "-----> Sync pushing ... "
26
+ system("rsync -azumv --delete --include={#{push_files_list}} --exclude=* -e ssh ./ #{SmartMachine.credentials.machine[:username]}@#{SmartMachine.credentials.machine[:address]}:~/.smartmachine")
27
+ puts "done"
28
+ end
29
+
30
+ def pull_files_list
31
+ files = [
32
+ 'apps/***',
33
+
34
+ 'bin/***',
35
+
36
+ 'grids',
37
+
38
+ 'grids/elasticsearch',
39
+ 'grids/elasticsearch/data/***',
40
+ 'grids/elasticsearch/logs/***',
41
+
42
+ 'grids/minio',
43
+ 'grids/minio/data/***',
44
+
45
+ 'grids/mysql',
46
+ 'grids/mysql/data/***',
47
+
48
+ 'grids/nginx',
49
+ 'grids/nginx/certificates/***',
50
+
51
+ 'grids/solr',
52
+ 'grids/solr/solr/***',
53
+ ]
54
+ files.join(',')
55
+ end
56
+
57
+ def push_files_list
58
+ files = [
59
+ 'apps',
60
+ 'apps/containers',
61
+ 'apps/containers/.keep',
62
+ 'apps/repositories',
63
+ 'apps/repositories/.keep',
64
+
65
+ 'config',
66
+ 'config/credentials.yml.enc',
67
+ 'config/environment.rb',
68
+
69
+ 'grids',
70
+
71
+ 'grids/elasticsearch',
72
+ 'grids/elasticsearch/data',
73
+ 'grids/elasticsearch/data/.keep',
74
+ 'grids/elasticsearch/logs',
75
+ 'grids/elasticsearch/logs/.keep',
76
+
77
+ 'grids/minio',
78
+ 'grids/minio/data',
79
+ 'grids/minio/data/.keep',
80
+
81
+ 'grids/mysql',
82
+ 'grids/mysql/data',
83
+ 'grids/mysql/data/.keep',
84
+
85
+ 'grids/nginx',
86
+ 'grids/nginx/certificates',
87
+ 'grids/nginx/certificates/.keep',
88
+ 'grids/nginx/htpasswd/***',
89
+ 'grids/nginx/fastcgi.conf',
90
+ 'grids/nginx/nginx.tmpl',
91
+
92
+ 'grids/prereceiver',
93
+ 'grids/prereceiver/pre-receive',
94
+
95
+ 'grids/redis',
96
+ 'grids/redis/data',
97
+ 'grids/redis/data/.keep',
98
+
99
+ 'grids/solr',
100
+ 'grids/solr/solr',
101
+ 'grids/solr/solr/.keep',
102
+
103
+ 'tmp/***',
104
+ ]
105
+ files.join(',')
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,18 @@
1
+ # => NOTE: Ensure that the specified top-level domains are pointing to this server ip address using DNS records.
2
+ # => Be sure to restart your server when you modify this file.
3
+
4
+ # Top-level naked domain to be used for subdomains of apps.
5
+ SmartMachine.config.apps_domain = "yourdomain.com"
6
+
7
+ # domain to be used for git prereceiver
8
+ SmartMachine.config.git_domain = "git.yourdomain.com"
9
+
10
+ # Sysadmin email id.
11
+ SmartMachine.config.sysadmin_email = "admin@yourdomain.com"
12
+
13
+ # letsencrypt test boolean to be used
14
+ SmartMachine.config.letsencrypt_test = false
15
+
16
+ # logger level
17
+ # DEBUG, INFO, WARN, ERROR, FATAL, UNKNOWN
18
+ SmartMachine.config.logger_level = "INFO"
@@ -0,0 +1,4 @@
1
+ # The username and password will be used by nginx to provide htpasswd based authentication for each of the domains specified.
2
+
3
+ git.yourdomain.com:
4
+ yourname@yourdomain.com: yourpassword
@@ -0,0 +1,11 @@
1
+ client_max_body_size 0; # Git pushes can be massive, just to make sure nginx doesn't suddenly cut the connection add this. Setting to 0 disables checking of client_max_body_size
2
+ fastcgi_buffering off; # disables buffering of responses from the FastCGI server on nginx
3
+
4
+ include fastcgi_params; # Include the default fastcgi configs
5
+
6
+ fastcgi_param NO_BUFFERING 1; # disables buffering on fcgiwrap
7
+ fastcgi_param SCRIPT_FILENAME /usr/libexec/git-core/git-http-backend; # Tells fastcgi to pass the request to the git http backend executable.
8
+ fastcgi_param PATH_INFO $uri; # Takes the capture group from our location directive and gives git that.
9
+ fastcgi_param REMOTE_USER $remote_user; # Forward REMOTE_USER as we want to know when we are authenticated
10
+
11
+ # IMPORTANT NOTE: Other required fastcgi_params have been defined as environment variables in the prereceiver container and hence need not be passed here.
@@ -0,0 +1,373 @@
1
+ {{ $CurrentContainer := where $ "ID" .Docker.CurrentContainerID | first }}
2
+
3
+ {{ define "upstream" }}
4
+ {{ if .Address }}
5
+ {{/* If we got the containers from swarm and this container's port is published to host, use host IP:PORT */}}
6
+ {{ if and .Container.Node.ID .Address.HostPort }}
7
+ # {{ .Container.Node.Name }}/{{ .Container.Name }}
8
+ server {{ .Container.Node.Address.IP }}:{{ .Address.HostPort }};
9
+ {{/* If there is no swarm node or the port is not published on host, use container's IP:PORT */}}
10
+ {{ else if .Network }}
11
+ # {{ .Container.Name }}
12
+ server {{ .Network.IP }}:{{ .Address.Port }};
13
+ {{ end }}
14
+ {{ else if .Network }}
15
+ # {{ .Container.Name }}
16
+ {{ if .Network.IP }}
17
+ server {{ .Network.IP }} down;
18
+ {{ else }}
19
+ server 127.0.0.1 down;
20
+ {{ end }}
21
+ {{ end }}
22
+
23
+ {{ end }}
24
+
25
+ # If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
26
+ # scheme used to connect to this server
27
+ map $http_x_forwarded_proto $proxy_x_forwarded_proto {
28
+ default $http_x_forwarded_proto;
29
+ '' $scheme;
30
+ }
31
+
32
+ # If we receive X-Forwarded-Port, pass it through; otherwise, pass along the
33
+ # server port the client connected to
34
+ map $http_x_forwarded_port $proxy_x_forwarded_port {
35
+ default $http_x_forwarded_port;
36
+ '' $server_port;
37
+ }
38
+
39
+ # If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any
40
+ # Connection header that may have been passed to this server
41
+ map $http_upgrade $proxy_connection {
42
+ default upgrade;
43
+ '' close;
44
+ }
45
+
46
+ # Apply fix for very long server names
47
+ server_names_hash_bucket_size 128;
48
+
49
+ # Default dhparam
50
+ {{ if (exists "/etc/nginx/dhparam/dhparam.pem") }}
51
+ ssl_dhparam /etc/nginx/dhparam/dhparam.pem;
52
+ {{ end }}
53
+
54
+ # Set appropriate X-Forwarded-Ssl header
55
+ map $scheme $proxy_x_forwarded_ssl {
56
+ default off;
57
+ https on;
58
+ }
59
+
60
+ gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
61
+
62
+ log_format vhost '$host $remote_addr - $remote_user [$time_local] '
63
+ '"$request" $status $body_bytes_sent '
64
+ '"$http_referer" "$http_user_agent"';
65
+
66
+ access_log off;
67
+ server_tokens off;
68
+
69
+ # Default is client_max_body_size 1M
70
+ client_max_body_size 5M;
71
+
72
+ {{ if $.Env.RESOLVERS }}
73
+ resolver {{ $.Env.RESOLVERS }};
74
+ {{ end }}
75
+
76
+ {{ if (exists "/etc/nginx/proxy.conf") }}
77
+ include /etc/nginx/proxy.conf;
78
+ {{ else }}
79
+ # HTTP 1.1 support
80
+ proxy_http_version 1.1;
81
+ proxy_buffering off;
82
+ proxy_set_header Host $http_host;
83
+ proxy_set_header Upgrade $http_upgrade;
84
+ proxy_set_header Connection $proxy_connection;
85
+ proxy_set_header X-Real-IP $remote_addr;
86
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
87
+ proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
88
+ proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl;
89
+ proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port;
90
+
91
+ # Mitigate httpoxy attack (see README for details)
92
+ proxy_set_header Proxy "";
93
+ {{ end }}
94
+
95
+ {{ $enable_ipv6 := eq (or ($.Env.ENABLE_IPV6) "") "true" }}
96
+ server {
97
+ server_name _; # This is just an invalid value which will never trigger on a real hostname.
98
+ listen 80;
99
+ {{ if $enable_ipv6 }}
100
+ listen [::]:80;
101
+ {{ end }}
102
+ access_log /var/log/nginx/access.log vhost;
103
+ return 503;
104
+ }
105
+
106
+ {{ if (and (exists "/etc/nginx/certs/default.crt") (exists "/etc/nginx/certs/default.key")) }}
107
+ server {
108
+ server_name _; # This is just an invalid value which will never trigger on a real hostname.
109
+ listen 443 ssl http2;
110
+ {{ if $enable_ipv6 }}
111
+ listen [::]:443 ssl http2;
112
+ {{ end }}
113
+ access_log /var/log/nginx/access.log vhost;
114
+ return 503;
115
+
116
+ ssl_session_tickets off;
117
+ ssl_certificate /etc/nginx/certs/default.crt;
118
+ ssl_certificate_key /etc/nginx/certs/default.key;
119
+ }
120
+ {{ end }}
121
+
122
+ {{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }}
123
+
124
+ {{ $host := trim $host }}
125
+ {{ $is_regexp := hasPrefix "~" $host }}
126
+ {{ $upstream_name := when $is_regexp (sha1 $host) $host }}
127
+
128
+ # {{ $host }}
129
+ upstream {{ $upstream_name }} {
130
+
131
+ {{ range $container := $containers }}
132
+ {{ $addrLen := len $container.Addresses }}
133
+
134
+ {{ range $knownNetwork := $CurrentContainer.Networks }}
135
+ {{ range $containerNetwork := $container.Networks }}
136
+ {{ if (and (ne $containerNetwork.Name "ingress") (or (eq $knownNetwork.Name $containerNetwork.Name) (eq $knownNetwork.Name "host"))) }}
137
+ ## Can be connected with "{{ $containerNetwork.Name }}" network
138
+
139
+ {{/* If only 1 port exposed, use that */}}
140
+ {{ if eq $addrLen 1 }}
141
+ {{ $address := index $container.Addresses 0 }}
142
+ {{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork) }}
143
+ {{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var, falling back to standard web port 80 */}}
144
+ {{ else }}
145
+ {{ $port := coalesce $container.Env.VIRTUAL_PORT "80" }}
146
+ {{ $address := where $container.Addresses "Port" $port | first }}
147
+ {{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork) }}
148
+ {{ end }}
149
+ {{ else }}
150
+ # Cannot connect to network of this container
151
+ server 127.0.0.1 down;
152
+ {{ end }}
153
+ {{ end }}
154
+ {{ end }}
155
+ {{ end }}
156
+ }
157
+
158
+ {{ $default_host := or ($.Env.DEFAULT_HOST) "" }}
159
+ {{ $default_server := index (dict $host "" $default_host "default_server") $host }}
160
+
161
+ {{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost, falling back to "http" */}}
162
+ {{ $proto := trim (or (first (groupByKeys $containers "Env.VIRTUAL_PROTO")) "http") }}
163
+
164
+ {{/* Get the NETWORK_ACCESS defined by containers w/ the same vhost, falling back to "external" */}}
165
+ {{ $network_tag := or (first (groupByKeys $containers "Env.NETWORK_ACCESS")) "external" }}
166
+
167
+ {{/* Get the HTTPS_METHOD defined by containers w/ the same vhost, falling back to "redirect" */}}
168
+ {{ $https_method := or (first (groupByKeys $containers "Env.HTTPS_METHOD")) "redirect" }}
169
+
170
+ {{/* Get the SSL_POLICY defined by containers w/ the same vhost, falling back to "Mozilla-Intermediate" */}}
171
+ {{ $ssl_policy := or (first (groupByKeys $containers "Env.SSL_POLICY")) "Mozilla-Intermediate" }}
172
+
173
+ {{/* Get the HSTS defined by containers w/ the same vhost, falling back to "max-age=31536000" */}}
174
+ {{ $hsts := or (first (groupByKeys $containers "Env.HSTS")) "max-age=31536000" }}
175
+
176
+ {{/* Get the VIRTUAL_ROOT By containers w/ use fastcgi root */}}
177
+ {{ $vhost_root := or (first (groupByKeys $containers "Env.VIRTUAL_ROOT")) "/var/www/public" }}
178
+
179
+
180
+ {{/* Get the first cert name defined by containers w/ the same vhost */}}
181
+ {{ $certName := (first (groupByKeys $containers "Env.CERT_NAME")) }}
182
+
183
+ {{/* Get the best matching cert by name for the vhost. */}}
184
+ {{ $vhostCert := (closest (dir "/etc/nginx/certs") (printf "%s.crt" $host))}}
185
+
186
+ {{/* vhostCert is actually a filename so remove any suffixes since they are added later */}}
187
+ {{ $vhostCert := trimSuffix ".crt" $vhostCert }}
188
+ {{ $vhostCert := trimSuffix ".key" $vhostCert }}
189
+
190
+ {{/* Use the cert specified on the container or fallback to the best vhost match */}}
191
+ {{ $cert := (coalesce $certName $vhostCert) }}
192
+
193
+ {{ $is_https := (and (ne $https_method "nohttps") (ne $cert "") (exists (printf "/etc/nginx/certs/%s.crt" $cert)) (exists (printf "/etc/nginx/certs/%s.key" $cert))) }}
194
+
195
+ {{ if $is_https }}
196
+
197
+ {{ if eq $https_method "redirect" }}
198
+ server {
199
+ server_name {{ $host }};
200
+ listen 80 {{ $default_server }};
201
+ {{ if $enable_ipv6 }}
202
+ listen [::]:80 {{ $default_server }};
203
+ {{ end }}
204
+ access_log /var/log/nginx/access.log vhost;
205
+ return 301 https://$host$request_uri;
206
+ }
207
+ {{ end }}
208
+
209
+ server {
210
+ server_name {{ $host }};
211
+ listen 443 ssl http2 {{ $default_server }};
212
+ {{ if $enable_ipv6 }}
213
+ listen [::]:443 ssl http2 {{ $default_server }};
214
+ {{ end }}
215
+ access_log /var/log/nginx/access.log vhost;
216
+
217
+ {{ if eq $network_tag "internal" }}
218
+ # Only allow traffic from internal clients
219
+ include /etc/nginx/network_internal.conf;
220
+ {{ end }}
221
+
222
+ {{ if eq $ssl_policy "Mozilla-Modern" }}
223
+ ssl_protocols TLSv1.2 TLSv1.3;
224
+ ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
225
+ {{ else if eq $ssl_policy "Mozilla-Intermediate" }}
226
+ ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
227
+ ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:!DSS';
228
+ {{ else if eq $ssl_policy "Mozilla-Old" }}
229
+ ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
230
+ ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:DES-CBC3-SHA:HIGH:SEED:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!RSAPSK:!aDH:!aECDH:!EDH-DSS-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!SRP';
231
+ {{ else if eq $ssl_policy "AWS-TLS-1-2-2017-01" }}
232
+ ssl_protocols TLSv1.2 TLSv1.3;
233
+ ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:AES128-GCM-SHA256:AES128-SHA256:AES256-GCM-SHA384:AES256-SHA256';
234
+ {{ else if eq $ssl_policy "AWS-TLS-1-1-2017-01" }}
235
+ ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
236
+ ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA';
237
+ {{ else if eq $ssl_policy "AWS-2016-08" }}
238
+ ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
239
+ ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA';
240
+ {{ else if eq $ssl_policy "AWS-2015-05" }}
241
+ ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
242
+ ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA:DES-CBC3-SHA';
243
+ {{ else if eq $ssl_policy "AWS-2015-03" }}
244
+ ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
245
+ ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA:DHE-DSS-AES128-SHA:DES-CBC3-SHA';
246
+ {{ else if eq $ssl_policy "AWS-2015-02" }}
247
+ ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
248
+ ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA:DHE-DSS-AES128-SHA';
249
+ {{ end }}
250
+
251
+ ssl_prefer_server_ciphers on;
252
+ ssl_session_timeout 5m;
253
+ ssl_session_cache shared:SSL:50m;
254
+ ssl_session_tickets off;
255
+
256
+ ssl_certificate /etc/nginx/certs/{{ (printf "%s.crt" $cert) }};
257
+ ssl_certificate_key /etc/nginx/certs/{{ (printf "%s.key" $cert) }};
258
+
259
+ {{ if (exists (printf "/etc/nginx/certs/%s.dhparam.pem" $cert)) }}
260
+ ssl_dhparam {{ printf "/etc/nginx/certs/%s.dhparam.pem" $cert }};
261
+ {{ end }}
262
+
263
+ {{ if (exists (printf "/etc/nginx/certs/%s.chain.pem" $cert)) }}
264
+ ssl_stapling on;
265
+ ssl_stapling_verify on;
266
+ ssl_trusted_certificate {{ printf "/etc/nginx/certs/%s.chain.pem" $cert }};
267
+ {{ end }}
268
+
269
+ {{ if (and (ne $https_method "noredirect") (ne $hsts "off")) }}
270
+ add_header Strict-Transport-Security "{{ trim $hsts }}" always;
271
+ {{ end }}
272
+
273
+ {{ if (exists (printf "/etc/nginx/vhost.d/%s" $host)) }}
274
+ include {{ printf "/etc/nginx/vhost.d/%s" $host }};
275
+ {{ else if (exists "/etc/nginx/vhost.d/default") }}
276
+ include /etc/nginx/vhost.d/default;
277
+ {{ end }}
278
+
279
+ location / {
280
+ {{ if eq $proto "uwsgi" }}
281
+ include uwsgi_params;
282
+ uwsgi_pass {{ trim $proto }}://{{ trim $upstream_name }};
283
+ {{ else if eq $proto "fastcgi" }}
284
+ root {{ trim $vhost_root }};
285
+ include fastcgi.conf;
286
+ fastcgi_pass {{ trim $upstream_name }};
287
+ {{ else }}
288
+ set {{`$proxy_pass_url`}} {{ trim $proto }}://{{ trim $upstream_name }};
289
+ if ({{`$cookie_appenv`}}) {
290
+ set {{`$proxy_pass_url`}} {{ trim $proto }}://{{`$cookie_appenv`}}.{{ trim $upstream_name }};
291
+ }
292
+ proxy_pass {{`$proxy_pass_url`}};
293
+ {{ end }}
294
+
295
+ {{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
296
+ auth_basic "Restricted {{ $host }}";
297
+ auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }};
298
+ {{ end }}
299
+ {{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }}
300
+ include {{ printf "/etc/nginx/vhost.d/%s_location" $host}};
301
+ {{ else if (exists "/etc/nginx/vhost.d/default_location") }}
302
+ include /etc/nginx/vhost.d/default_location;
303
+ {{ end }}
304
+ }
305
+ }
306
+
307
+ {{ end }}
308
+
309
+ {{ if or (not $is_https) (eq $https_method "noredirect") }}
310
+
311
+ server {
312
+ server_name {{ $host }};
313
+ listen 80 {{ $default_server }};
314
+ {{ if $enable_ipv6 }}
315
+ listen [::]:80 {{ $default_server }};
316
+ {{ end }}
317
+ access_log /var/log/nginx/access.log vhost;
318
+
319
+ {{ if eq $network_tag "internal" }}
320
+ # Only allow traffic from internal clients
321
+ include /etc/nginx/network_internal.conf;
322
+ {{ end }}
323
+
324
+ {{ if (exists (printf "/etc/nginx/vhost.d/%s" $host)) }}
325
+ include {{ printf "/etc/nginx/vhost.d/%s" $host }};
326
+ {{ else if (exists "/etc/nginx/vhost.d/default") }}
327
+ include /etc/nginx/vhost.d/default;
328
+ {{ end }}
329
+
330
+ location / {
331
+ {{ if eq $proto "uwsgi" }}
332
+ include uwsgi_params;
333
+ uwsgi_pass {{ trim $proto }}://{{ trim $upstream_name }};
334
+ {{ else if eq $proto "fastcgi" }}
335
+ root {{ trim $vhost_root }};
336
+ include fastcgi.conf;
337
+ fastcgi_pass {{ trim $upstream_name }};
338
+ {{ else }}
339
+ set {{`$proxy_pass_url`}} {{ trim $proto }}://{{ trim $upstream_name }};
340
+ if ({{`$cookie_appenv`}}) {
341
+ set {{`$proxy_pass_url`}} {{ trim $proto }}://{{`$cookie_appenv`}}.{{ trim $upstream_name }};
342
+ }
343
+ proxy_pass {{`$proxy_pass_url`}};
344
+ {{ end }}
345
+ {{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
346
+ auth_basic "Restricted {{ $host }}";
347
+ auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }};
348
+ {{ end }}
349
+ {{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }}
350
+ include {{ printf "/etc/nginx/vhost.d/%s_location" $host}};
351
+ {{ else if (exists "/etc/nginx/vhost.d/default_location") }}
352
+ include /etc/nginx/vhost.d/default_location;
353
+ {{ end }}
354
+ }
355
+ }
356
+
357
+ {{ if (and (not $is_https) (exists "/etc/nginx/certs/default.crt") (exists "/etc/nginx/certs/default.key")) }}
358
+ server {
359
+ server_name {{ $host }};
360
+ listen 443 ssl http2 {{ $default_server }};
361
+ {{ if $enable_ipv6 }}
362
+ listen [::]:443 ssl http2 {{ $default_server }};
363
+ {{ end }}
364
+ access_log /var/log/nginx/access.log vhost;
365
+ return 500;
366
+
367
+ ssl_certificate /etc/nginx/certs/default.crt;
368
+ ssl_certificate_key /etc/nginx/certs/default.key;
369
+ }
370
+ {{ end }}
371
+
372
+ {{ end }}
373
+ {{ end }}