github.com/searchspring/haus@v0.1.8-0.20200414161854-a7ca8bb9ea93/README.md (about)

     1  haus
     2  ========
     3  
     4  Keep your haus in order.  Haus gives you an easy way to recreate your docker development environments from scratch and share them with others.  With a simple Yaml config, and a series of templates, haus will dynamically build RepoTsar and Docker-Compose config files for you. 
     5  
     6  Docker
     7  ======
     8  Instead of building or installing haus, it's simplest to run haus via docker.  Follow instructions here https://hub.docker.com/r/searchspring/haus/ 
     9  
    10  Installing
    11  ==========
    12  
    13  There are static binary packages for OSX and Debian in releases.  If you would like to build haus yourself, follow the instructions below.
    14  
    15  # Requirements
    16  This project is written in go.
    17  
    18  ### Go
    19  
    20  https://golang.org/doc/install
    21  
    22  Don't forget to set your GOPATH and add the locations of the go bin to your PATH.  You should also ensure that your PKG_CONFIG_PATH is set for compiling purposes later on.  Something like this in your .bashrc :
    23  
    24  ```bash
    25  export GOPATH=$HOME/code/go
    26  export PATH=$PATH:$GOPATH/bin:/usr/local/go/bin/
    27  export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig
    28  ```
    29  
    30  ### Docker
    31  
    32  If you're on OSX or Windows checkout boot2docker http://boot2docker.io/
    33  
    34  ### Installing git2go
    35  
    36  This project requires git2go.v22, which in turn requires libgit2.  If you want SSH support with this application, ensure you have libssh2 installed as well.  A recent version of cmake is required to build libgit2 http://www.cmake.org/download/ .  You'll need to commandline tools for cmake, if you're on OSX and you've installed the GUI, goto Tools->Install for Command Line Use.  This may throw an error about failing to create symlinks.  This is a permissions error, you can create this links by hand.
    37  
    38  ```bash
    39  /usr/bin/
    40  cmake -> /Applications/CMake.app/Contents/bin/cmake
    41  cmake-gui -> /Applications/CMake.app/Contents/bin/cmake-gui
    42  cmakexbuild -> /Applications/CMake.app/Contents/bin/cmakexbuild
    43  ```
    44  
    45  Follow instructions at https://github.com/libgit2/git2go to build libgit2 and git2go.
    46  
    47  #### Installing yaml
    48  
    49  This project also requires yaml.v2
    50  
    51  ```bash
    52  go get gopkg.in/yaml.v2
    53  ```
    54  
    55  #### Installing RepoTsar
    56  
    57  ```bash
    58  go get github.com/searchspring/repo-tsar
    59  ``` 
    60  
    61  Usage
    62  =====
    63  
    64  # ~/.hauscfg.yml
    65  
    66  If haus is run in an empty directory it will pull the config from ~/.hauscfg.yml.  The following is an example of what that file should look like.
    67  
    68  ```yaml
    69  name: "Your Name"
    70  email: email@address.com
    71  hausrepo: git@bitbucket.org:yourrepo/haus-yaml.git
    72  ```
    73  
    74  The **hausrepo** option should be configured with a repo containing haus config files.  Haus will **one time** checkout this repo and then run haus.  Anytime a haus.yml file exists in the current directory, this setting is ignored.  If you pass *-branch* **branchname** as an argument, haus will checkout that specific branch.
    75  
    76  
    77  # haus.yml
    78  Haus will look in the current directory for a haus.yml file.  This file defines the architecture you want to build.  Here is an example:
    79  
    80  ```yaml
    81  
    82  # Git Signature Info
    83  name: "Your Name"
    84  email: email@address.com
    85  
    86  # Global Defaults
    87  variables:
    88    dns1: 172.17.42.1
    89    dns2: 8.8.8.8
    90  
    91  # Environment Definitions
    92  environments:
    93    mysql_latest:
    94    redis_latest:
    95    elasticsearch_1.3.4:
    96      variables:
    97        name: "ESTest1"
    98        clustername: "test-cluster1"
    99        port: 9201
   100    elasticsearch_1.1.1:
   101      variables:
   102        name: "ESTest2"
   103        clustername: "test-cluster2"
   104        port: 9202
   105    consul:
   106    registrator:
   107      requirements:
   108          - consul
   109  ```
   110  
   111  The 'name' and 'email' fields will be used in your git signature for any checkouts that are required.  Each element under 'environments' corresponds to a template in a templates directory in the current path.  The template file name will match the element name up to an `_`, plus .yml.tmpl as a suffix.  Example, in the above config, the template file for elasticsearch_1.3.4 will be
   112  `./templates/elasticsearch.yml.tmpl`
   113  If there is an `_` in the name element, it will be passed to the template as the variable 'Version'.  Any additional variables you would like to pass to the template can be defined under 'Variables' and 'Branch'.  Requirements is completely optional, it is an array of names, requiring that those definitions exist in this document.  This allows you to show a relationship between different definitions.  In the example above, the registrator definition requires that a consul definition exists.
   114  
   115  # Templates
   116  
   117  Templates live in a directory `templates` in your current path.  Each template defines either a git repository for RepoTsar to manage and/or a docker instance.
   118  
   119  Here is an example of a docker only template
   120  ```yaml
   121  docker:
   122    {{.Variables.name}}ES:
   123      image: searchspring/elasticsearch:consul-config-{{.Version}}
   124      dns:
   125        - {{.Variables.dns1}}
   126        - {{.Variables.dns2}}
   127      ports:
   128        - "{{.Variables.port}}:9200"
   129      expose:
   130        - "9200"
   131      environment:
   132        - SERVICE_9200_NAME=es
   133        - CLUSTERNAME={{.Variables.clustername}}
   134  ```
   135  
   136  
   137  Here is an example of a template with a repo for the dockers instance and for an application.  This is generate a docker-compose.yml that will build the docker image from the repo and then mount a volume with the application code from the application repo.
   138  
   139  ```yaml
   140  repotsar: 
   141    nodejs:
   142      url: ssh://git@github.com/joyent/docker-node.git
   143      path: {{.Path}}/src/docker-node/
   144      branch: {{.Branch}}
   145    ghost:
   146      url: ssh://git@github.com/TryGhost/Ghost.git
   147      path: {{.Path}}/src/docker-node/src/ghost
   148      branch: {{.Branch}}
   149  docker:
   150    test:
   151      build: {{.Path}}/src/docker-node/
   152      ports:
   153          - "80:2368"
   154      expose:
   155          - "2368"
   156      dns:
   157          - {{.Variables.dns1}}
   158          - {{.Variables.dns2}}
   159      volumes:
   160          - {{.Path}}/src/docker-node/src/ghost/:/usr/src/ghost/
   161      environment:
   162          - SERVICE_2368_NAME=ghost
   163          - SERVICE_TAG=ghost
   164      
   165      net: "bridge"
   166      command: "npm install --production&& npm start --production"
   167  ```
   168  
   169  Inside the templates the following variables may be used
   170  
   171  * .Path - This will be the value supplied to the command line arguement -path (default ./hauscfg)
   172  * .Version / .Branch - This will be any value after the first `_` in the name of the environment
   173  * .Variables - Any variable defined under the `variables` section of the enviroment definition
   174  * .Env - Any shell environment variables 
   175  
   176  
   177  # User Config
   178  
   179  Haus looks in ~/.hauscfg.yml for user configuration.  This a YAML file that should look like the following.  The variables section in this file will override the global defaults section in the haus.yml.
   180  
   181  ```YAML
   182  name: "Your Name"
   183  email: email@domain.com
   184  hausrepo: git@github.com:searchspring/haus.git
   185  
   186  variables:
   187    dns1: 172.17.42.1
   188    dns2: 8.8.8.8
   189  
   190  ```
   191  
   192  The name and email settings are used as your git signature.  The hausrepo setting should be the git address of a repo where you have a haus.yml and templates for haus.  If you use the haus command in a empty directory the repo specified in hausrepo will be cloned into the current directory and then haus will use that haus.yml config.  You may also specify -branch with the haus command to checkout a specific branch of the repo you configured hausrepo for.
   193  
   194  # Syntax
   195  
   196  ## Usage of haus:
   197  ```
   198    -branch="master": git branch for hausrepo
   199    -config="haus.yml": YAML config file
   200    -path="./hauscfg": Path to generate files in
   201    -variables=map[]: variables passed to templates
   202    -version=false: haus version
   203  ```
   204  
   205  ### branch
   206    This option allows you to specify what branch haus should use when cloning from the hausrepo specified in your ~/.hauscfg.yml
   207  
   208  ### config
   209    This option allows you to tell haus to use a haus.yml file in a different location other than current directory.
   210  
   211  ### path
   212    This option specifies a different location for haus config files to be created in rather than ./hauscfg.
   213  
   214  ### variables
   215    Using this option allows you to override variables in the templates from the command line.  Example:
   216    ```bash
   217    bash-3.2$ haus -variables dns1=1.1.1.1 -variables dns2=2.2.2.2
   218    ```
   219  ### version
   220    Prints the version of haus and exits.
   221  
   222  License and Author
   223  ==================
   224  
   225  * Author:: Greg Hellings (<greg@thesub.net>)
   226  
   227  
   228  Copyright 2014, B7 Interactive, LLC.
   229  
   230  Licensed under the Apache License, Version 2.0 (the "License");
   231  you may not use this file except in compliance with the License.
   232  You may obtain a copy of the License at
   233  
   234      http://www.apache.org/licenses/LICENSE-2.0
   235  
   236  Unless required by applicable law or agreed to in writing, software
   237  distributed under the License is distributed on an "AS IS" BASIS,
   238  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   239  See the License for the specific language governing permissions and
   240  limitations under the License.