/lambdacd-mongodb

LambdaCD extension which lets you use a MongoDB to persist the state of pipelines

Primary LanguageClojureMIT LicenseMIT

lambdacd-mongodb

Clojars Project

If you use LambdaCD in an environment without persistence you certainly noticed that the build history is lost after restarting LambdaCD. lambdacd-mongodb stores the state of your pipeline in a MongoDB and it restores it at the next startup.

Nice to know

  • Only builds with the same defintion can be restored (-> LambdaCD Issue #6)
  • Only builds with at least two active steps are stored because you don't need builds waiting for a trigger
  • Tested with LambdaCD version 0.8.0
  • String keys in the global map starting with the prefix ":" will be restored as keyword and not as string

Example

  1. Start your local MongoDB daemon (default port: 27017)
  2. Run lein run
  3. Let the pipeline run for a few times
  4. Stop LambdaCD by pressing strg-c in your terminal
  5. Restart LambdaCD by running lein run again
  6. The build history should still be there

Configuration

  1. To use lambdacd-mongodb you have to create a map containing your MongoDB configuration.
    • The :col key specifies the collection which is used to store all builds from one pipeline. Do not use a collection for more than one pipeline!
    • The :max-builds key is optional (default: 20) and definies how many inactive builds are restored.
    • The :ttl key is optional (default: 7) and definies how many days the builds should be stored
    • The :mark-running-steps-as is optional (default: :killed). If you set it to :failure all running steps will be marked with the status :failure. If you set to :success, running steps will me marked as :success. Please be advised that configurating something other than :success, :failure or :killed will leave your pipeline in an undefined state.
    • The :persist-the-output-of-running-steps is optional (default: false). If you set it to true the state of the pipeline will be persisted if the output of any step is changed (-> many write operations). If you set it to false the state of the pipeline will only be persisted if the status of any step is changed (-> fewer write operations).
  2. Add the mongodb configuration map to the main configuration by using the key name :mongodb-cfg
(defn -main [& args]
  (let [home-dir (util/create-temp-dir)
        mongodb-cfg {:uri          "mongodb://localhost:27017/lambdacd"
                     :db           "lambdacd"
                     :col          "test-project"
                     :max-builds   10
                     :ttl          7
                     :mark-running-steps-as :killed
                     :pipeline-def pipeline-def
                     :persist-the-output-of-running-steps false}
        config {:mongodb-cfg              mongodb-cfg
                :home-dir                 home-dir
                :dont-wait-for-completion false}
        pipeline (lambdacd.core/assemble-pipeline pipeline-def config (mongodb-state/new-mongodb-state config))
        [...]

TODO

  • Exception-Handling
  • Tests
  • More tests

License

Copyright © 2015 Simon Monecke

Distributed under MIT License