From e6e04a0237a80cbe47edbe0529cc674802cf3cc8 Mon Sep 17 00:00:00 2001
From: Piotr Maslanka <piotr.maslanka@henrietta.com.pl>
Date: Sat, 25 Mar 2017 12:24:25 +0100
Subject: [PATCH] meta

---
 .gitlab-ci.yml           | 12 +++----
 README.md                | 21 ++++++------
 cass_zk_rmq/README.md    |  6 ----
 cassandra/README.md      |  6 ----
 czr_pythons/README.md    |  6 ----
 czr_pythons_pg/README.md |  6 ----
 make.py                  | 71 +++++++++++++++++++++++++++++++++++++---
 7 files changed, 82 insertions(+), 46 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 082dd4b..2e6233f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -8,7 +8,7 @@ build_cassandra:
     - vagrant
     - develop19216822423
   before_script:
-    - python make.py
+    - python make.py meta
     - cp *.sh cassandra/
     - cp SkeletonVagrantfile cassandra/Vagrantfile
     - cd cassandra
@@ -32,7 +32,7 @@ build_cass_zk_rmq:
     - vagrant
     - develop19216822423
   before_script:
-    - python make.py
+    - python make.py meta
     - cp *.sh cass_zk_rmq/
     - cp SkeletonVagrantfile cass_zk_rmq/Vagrantfile
     - cd cass_zk_rmq
@@ -56,7 +56,7 @@ build_czr_pythons:
     - vagrant
     - develop19216822423
   before_script:
-    - python make.py
+    - python make.py meta
     - cp *.sh czr_pythons/
     - cp SkeletonVagrantfile czr_pythons/Vagrantfile
     - cd czr_pythons
@@ -80,7 +80,7 @@ build_czr_pythons_pg:
     - vagrant
     - develop19216822423
   before_script:
-    - python make.py
+    - python make.py meta
     - cp *.sh czr_pythons_pg/
     - cp SkeletonVagrantfile czr_pythons_pg/Vagrantfile
     - cd czr_pythons_pg
@@ -104,7 +104,7 @@ build_nodejs4:
     - vagrant
     - develop19216822423
   before_script:
-    - python make.py
+    - python make.py meta
     - cp *.sh nodejs4/
     - cp SkeletonVagrantfile nodejs4/Vagrantfile
     - cd nodejs4
@@ -128,7 +128,7 @@ build_nodejs5_jdk_adk25:
     - vagrant
     - develop19216822423
   before_script:
-    - python make.py
+    - python make.py meta
     - cp *.sh nodejs5_jdk_adk25/
     - cp SkeletonVagrantfile nodejs5_jdk_adk25/Vagrantfile
     - cd nodejs5_jdk_adk25
diff --git a/README.md b/README.md
index 4d6a006..54b19f5 100644
--- a/README.md
+++ b/README.md
@@ -6,16 +6,6 @@
 
 Boxes are based off *debian/contrib-jessie64*
 
-## List o'boxes
-
-Click on particular boxes to see description and how to use:
-* [Sun Java 8 + Cassandra](/cassandra)
-* [Cassandra + ZooKeeper + RabbitMQ](/cass_zk_rmq)
-* [Cassandra + ZooKeeper + RabbitMQ + Python](/czr_pythons)
-* [Cassandra + ZooKeeper + RabbitMQ + Python + PostgreSQL](/czr_pythons_pg)
-* [NodeJS 4.x + bower + gulp](/nodejs4)
-* [NodeJS 5.x + JDK + ADT + cordova](/nodejs5_jdk_adk25)
-
 # How to rebuild
 
 ```bash
@@ -31,4 +21,13 @@ and a dash, eg. **cassandra-something**.
 Only it will then rebuild upon commit.
 
 Boxes, after being built, will be automatically available at
-[http://dev.dms-serwis.com.pl/vagrant/](http://dev.dms-serwis.com.pl/vagrant/)
\ No newline at end of file
+[http://dev.dms-serwis.com.pl/vagrant/](http://dev.dms-serwis.com.pl/vagrant/)
+
+# Box index
+
+    * **cassandra**: [Debian Jessie x86_64 with Cassandra 3.0.9](/cassandra/README.md)
+* **cass_zk_rmq**: [Cassandra, ZooKeeper, RabbitMQ](/cass_zk_rmq/README.md)
+* **czr_pythons**: [Cassandra, ZooKeeper, RabbitMQ and assorted Pythons](/czr_pythons/README.md)
+* **czr_pythons_pg**: [czr_pythons but with PostgreSQL](/czr_pythons_pg/README.md)
+* **nodejs4**: [NodeJS 4 + bower + gulp](/nodejs4/README.md)
+* **nodejs5_jdk_adk25**: [odeJS 5.x + JDK + ADT + cordova](/nodejs5_jdk_adk25/README.md)
diff --git a/cass_zk_rmq/README.md b/cass_zk_rmq/README.md
index 8610983..e1a7693 100644
--- a/cass_zk_rmq/README.md
+++ b/cass_zk_rmq/README.md
@@ -6,9 +6,3 @@ Added:
 * Apache Cassandra 3.0.9
 * ZooKeeper
 * RabbitMQ 3.3.5 (management plugin disabled)
-
-Use like:
-```
-config.vm.box = "henrietta/cass_zk_rmq"
-config.vm.box_url = "http://dev.dms-serwis.com.pl/vagrant/cass_zk_rmq.box"
-```
diff --git a/cassandra/README.md b/cassandra/README.md
index cae1cce..1d056c2 100644
--- a/cassandra/README.md
+++ b/cassandra/README.md
@@ -5,9 +5,3 @@ Added:
 * curl
 * Sun Java 8
 * Apache Cassandra 3.0.9
-
-Use like:
-```
-config.vm.box = "henrietta/cassandra"
-config.vm.box_url = "http://dev.dms-serwis.com.pl/vagrant/cassandra.box"
-```
diff --git a/czr_pythons/README.md b/czr_pythons/README.md
index 2d90a85..f97e172 100644
--- a/czr_pythons/README.md
+++ b/czr_pythons/README.md
@@ -6,9 +6,3 @@ It's [cass_zk_rmq](/cass_zk_rmq) but with extra:
 * Python 2.7
     * cassandra, kazoo and CoolAMQP
     * common utility and testing libraries
-    
-Use like:
-```
-config.vm.box = "henrietta/czr_pythons"
-config.vm.box_url = "http://dev.dms-serwis.com.pl/vagrant/czr_pythons.box"
-```
diff --git a/czr_pythons_pg/README.md b/czr_pythons_pg/README.md
index b3785ea..7abd432 100644
--- a/czr_pythons_pg/README.md
+++ b/czr_pythons_pg/README.md
@@ -9,9 +9,3 @@ It's [cass_zk_rmq](/cass_zk_rmq) but with extra:
 * Python 2.7
     * cassandra, kazoo and CoolAMQP
     * common utility and testing libraries
-
-Use like:
-```
-config.vm.box = "henrietta/czr_pythons_pg"
-config.vm.box_url = "http://dev.dms-serwis.com.pl/vagrant/czr_pythons_pg.box"
-```
diff --git a/make.py b/make.py
index d260067..fc5eeff 100644
--- a/make.py
+++ b/make.py
@@ -5,13 +5,14 @@ import os
 import os.path
 import sys
 
+PREFIX = 'henrietta/'
+
 if __name__ == '__main__':
     dirs = [dir for dir in os.listdir('.') if os.path.isdir(dir) or (dir != '.git')]
     exi = lambda box, sup: os.path.exists(os.path.join(box, 'build%s.sh' % (sup, )))
     boxes = [box for box in dirs if exi(box, '') or exi(box, '_as_vagrant')]
 
     if len(sys.argv) == 1:
-
         # Generate Gitlab CI file
         with open('.gitlab-ci.yml', 'wb') as ci:
             for box in boxes:
@@ -39,17 +40,64 @@ build_$BOX:
   after_script:
     - vagrant destroy -f
     - cd ..
-'''.replace('$BOX', box).replace('$PREFIX', 'henrietta/'))
+'''.replace('$BOX', box).replace('$PREFIX', PREFIX))
+        # README.md
+        index = []
+        for box in boxes:
+            with open(os.path.join(box, 'DESCRIPTION'), 'rb') as mdin:
+                description = mdin.read().strip()
 
-    if ' '.join(sys.argv).endswith('meta'):
+            index.append(
+                u'* **$BOX**: [$DESCRIPTION](/$BOX/README.md)\n'.replace('$DESCRIPTION', description).replace('$BOX',
+                                                                                                            box).replace(
+                    '$PREFIX', PREFIX))
+
+        index = [u'''# vagrant-boxen
+
+**Problem:** installing same things over and over makes builds long
+
+**Solution:** make Vagrant images with common things preinstalled
+
+Boxes are based off *debian/contrib-jessie64*
+
+# How to rebuild
+
+```bash
+python make.py
+git add --all
+git commit -m "dfdf"
+git push origin master
+```
+
+Boxes are automatically regenerated upon a push to master.
+If you want to develop a single box, just make a branch that starts with it's name
+and a dash, eg. **cassandra-something**.
+Only it will then rebuild upon commit.
+
+Boxes, after being built, will be automatically available at
+[http://dev.dms-serwis.com.pl/vagrant/](http://dev.dms-serwis.com.pl/vagrant/)
+
+# Box index
 
+    '''] + index
+
+        with open('README.md', 'wb') as wo:
+            wo.write(u''.join(index).encode('utf8'))
+
+
+
+
+
+    if ' '.join(sys.argv).endswith('meta'):
+        box = os.path.split(os.getcwd())[-1]
         with open('DESCRIPTION', 'rb') as mdin, open('metadata.json', 'wb') as mdout:
             description = mdin.read().strip()
 
+
             mdout.write('''{
     "description": "$DESCRIPTION",
     "short_description": "$DESCRIPTION",
-    "name": "henrietta/$BOX",
+    "name": "$PREFIX/$BOX",
     "versions": [{
         "version": "1",
         "status": "active",
@@ -61,5 +109,18 @@ build_$BOX:
         }]
     }]
 }
-'''.replace('$DESCRIPTION', description).replace('$BOX', os.path.split(os.getcwd())[-1]))
+'''.replace('$DESCRIPTION', description).replace('$BOX', box).replace('$PREFIX', PREFIX))
+
+
+        with open('README.md', 'rb') as rin:
+            readme = rin.read()
+
+        readme = readme + '''Use like:
+```
+config.vm.box = "$PREFIX/$BOX"
+config.vm.box_url = "http://dev.dms-serwis.com.pl/vagrant/$BOX.box"
+```
+'''.replace('$BOX', box).replace('$PREFIX', PREFIX)
 
+        with open('README.md', 'wb') as fo:
+            fo.write(readme)
-- 
GitLab