rivet-simple-deploy (empty) → 0.1.0.0
raw patch · 4 files changed
+148/−0 lines, 4 filesdep +basedep +configuratordep +mtlsetup-changed
Dependencies added: base, configurator, mtl, rivet-core, text
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- rivet-simple-deploy.cabal +27/−0
- src/Rivet/Lib/SimpleDeploy.hs +89/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2014, Daniel Patterson++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Daniel Patterson nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ rivet-simple-deploy.cabal view
@@ -0,0 +1,27 @@+name: rivet-simple-deploy+version: 0.1.0.0+synopsis: Basic deployment support for project management tool.+-- description:+homepage: https://github.com/dbp/rivet+license: BSD3+license-file: LICENSE+author: Daniel Patterson+maintainer: dbp@dbpmail.net+-- copyright:+-- category:+build-type: Simple+-- extra-source-files:+cabal-version: >=1.10++library+ exposed-modules:+ Rivet.Lib.SimpleDeploy+ -- other-modules:+ -- other-extensions:+ build-depends: base >=4.7 && <5+ , rivet-core+ , mtl+ , configurator+ , text+ hs-source-dirs: src+ default-language: Haskell2010
+ src/Rivet/Lib/SimpleDeploy.hs view
@@ -0,0 +1,89 @@+module Rivet.Lib.SimpleDeploy where++import Prelude hiding ((++))++import Control.Monad (void)+import Control.Monad.Trans (liftIO)+import Data.Configurator+import Data.Configurator.Types+import qualified Data.Text as T+import Rivet.Common++tasks :: [Task]+tasks = [Task "deploy:status" 0 deployStatus ""+ ,Task "deploy:migrate" 0 deployMigrate ""+ ,Task "deploy:migrate:status" 0 deployMigrateStatus ""+ ,Task "deploy:migrate:down" 0 deployMigrateDown ""+ ,Task "deploy:rollout" 0 deployRollout ""+ ,Task "deploy:rollback" 1 deployRollback "SHA (short)"+ ,Task "deploy:stage" 1 deployStage "SHA (short)"+ ]+++deployMigrate proj conf _ =+ do stageHost <- liftIO $ require conf (T.pack "stage-host")+ prodImage <- liftIO $ require conf (T.pack "production-image")+ tag <- getDockerTag proj stageHost "stage"+ if length tag < 5+ then liftIO $ putStrLn "Couldn't get tag from staging."+ else do let c = "docker run -w /srv -i -t -v /srv/data:/srv/data -v /var/run/postgresql/.s.PGSQL.5432:/var/run/postgresql/.s.PGSQL.5432 -v /srv/prod_" ++ tag ++ ".cfg:/srv/Rivetfile " ++ prodImage ++ ":" ++ tag ++ " rivet db:migrate prod"+ void $ exec $ "ssh " ++ stageHost ++ " " ++ c++deployMigrateStatus proj conf _ =+ do stageHost <- liftIO $ require conf (T.pack "stage-host")+ prodImage <- liftIO $ require conf (T.pack "production-image")+ tag <- getDockerTag proj stageHost "stage"+ if length tag < 5+ then liftIO $ putStrLn "Couldn't get tag from staging."+ else do let c = "docker run -w /srv -i -t -v /srv/data:/srv/data -v /var/run/postgresql/.s.PGSQL.5432:/var/run/postgresql/.s.PGSQL.5432 -v /srv/prod_" ++ tag ++ ".cfg:/srv/Rivetfile " ++ prodImage ++ ":" ++ tag ++ " rivet db:status prod"+ void $ exec $ "ssh " ++ stageHost ++ " " ++ c++deployMigrateDown proj conf _ =+ do stageHost <- liftIO $ require conf (T.pack "stage-host")+ prodImage <- liftIO $ require conf (T.pack "production-image")+ tag <- getDockerTag proj stageHost "stage"+ if length tag < 5+ then liftIO $ putStrLn "Couldn't get tag from staging."+ else do let c = "docker run -w /srv -i -t -v /srv/data:/srv/data -v /var/run/postgresql/.s.PGSQL.5432:/var/run/postgresql/.s.PGSQL.5432 -v /srv/prod_" ++ tag ++ ".cfg:/srv/Rivetfile " ++ prodImage ++ ":" ++ tag ++ " rivet db:migrate:down prod"+ void $ exec $ "ssh " ++ stageHost ++ " " ++ c++deployStatus proj conf _ =+ do stageHost <- liftIO $ require conf (T.pack "stage-host")+ prodHost <- liftIO $ require conf (T.pack "prod-host")+ stageTag <- getDockerTag proj stageHost "stage"+ prodTag <- getDockerTag proj prodHost "prod"+ if length stageTag < 5+ then liftIO $ putStrLn "Couldn't get staging tag."+ else do liftIO $ putStrLn "Staging is running..."+ void $ exec $ "git rev-list --format=%B --max-count=1 " ++ stageTag+ if length prodTag < 5+ then liftIO $ putStrLn "Couldn't get production tag."+ else do liftIO $ putStrLn "Production is running..."+ void $ exec $ "git rev-list --format=%B --max-count=1 " ++ prodTag++deployRollout proj conf _ =+ do stageHost <- liftIO $ require conf (T.pack "stage-host")+ prodHost <- liftIO $ require conf (T.pack "prod-host")+ prodImage <- liftIO $ require conf (T.pack "production-image")+ prodInstances <- liftIO $ lookupDefault (1 :: Int) conf (T.pack "production-instances")+ tag <- getDockerTag proj stageHost "stage"+ if length tag < 5+ then liftIO $ putStrLn "Couldn't get tag from staging."+ else do liftIO $ putStrLn "Deploying..."+ exec $ "git rev-list --format=%B --max-count=1 " ++ tag+ void $ exec $ "ssh " ++ prodHost ++ " /srv/deploy.sh " ++ proj ++ " prod " ++ prodImage ++ " " ++ tag ++ " " ++ (show prodInstances)++deployRollback proj conf (tag:_) =+ do prodHost <- liftIO $ require conf (T.pack "prod-host")+ prodImage <- liftIO $ require conf (T.pack "production-image")+ prodInstances <- liftIO $ lookupDefault (1 :: Int) conf (T.pack "production-instances")+ liftIO $ putStrLn $ "Rolling back to " ++ tag ++ "..."+ exec $ "git rev-list --format=%B --max-count=1 " ++ tag+ void $ exec $ "ssh " ++ prodHost ++ " /srv/deploy.sh " ++ proj ++ " prod " ++ prodImage ++ " " ++ tag ++ " " ++ (show prodInstances)++deployStage proj conf (tag:_) =+ do stageHost <- liftIO $ require conf (T.pack "stage-host")+ prodImage <- liftIO $ require conf (T.pack "production-image")+ liftIO $ putStrLn $ "Deploying stage to " ++ tag ++ "..."+ exec $ "git rev-list --format=%B --max-count=1 " ++ tag+ void $ exec $ "ssh " ++ stageHost ++ " /srv/deploy.sh " ++ proj ++ " stage " ++ prodImage ++ " " ++ tag ++ " 1"