Skip to content

Commit

Permalink
Single executable
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Jan 11, 2012
1 parent 517bf42 commit 8997653
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
20 changes: 8 additions & 12 deletions reconfig.hs → Reconfig.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{-# LANGUAGE OverloadedStrings #-}
module Reconfig where

import Data.Yaml
import Data.Text (Text, unpack)
import Filesystem.Path.CurrentOS
Expand All @@ -13,7 +15,6 @@ import Control.Monad (mzero, foldM)
import qualified Data.Map as Map
import Data.Maybe (catMaybes)
import System.Cmd (rawSystem)
import System.Environment (getArgs)
import qualified Prelude

data Deploy = Deploy
Expand Down Expand Up @@ -148,19 +149,14 @@ nginxBlockStatic s = unlines
, "}"
]

main :: IO ()
main = do
args <- getArgs
(rootDir, unpackedFolder, angelConfig, nginxConfig) <-
case args of
[a, b, c, d] -> return (a, b, c, d)
_ -> error "Invalid arguments"
let unpacker = unlines
[ "unpacker {"
reconfig :: String -> String -> String -> String -> IO ()
reconfig rootDir unpackedFolder angelConfig nginxConfig = do
let deploy = unlines
[ "deploy {"
, concat
[ " exec = \""
, rootDir
, "bin/unpacker "
, "bin/deploy "
, rootDir
, "\""
]
Expand All @@ -171,7 +167,7 @@ main = do
let statics = concatMap deployStatics $ Map.elems deploys
let rootDir' = decodeString rootDir
writeFile rootDir' angelConfig
$ unpacker ++ concatMap angelBlock was
$ deploy ++ concatMap angelBlock was
writeFile rootDir' nginxConfig
$ concatMap nginxBlockWebapp was ++
concatMap nginxBlockStatic statics
Expand Down
3 changes: 1 addition & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ sudo rm -f /etc/init/yesod-deploy-angel.conf
sudo rm -f /etc/nginx/sites-enabled/yesod-deploy.conf
sudo /etc/init.d/nginx reload

ghc -Wall -Werror --make reconfig.hs && strip reconfig
ghc -Wall -Werror --make unpacker.hs && strip unpacker
ghc -Wall -Werror --make deploy.hs && strip deploy
sudo ./setup.sh
13 changes: 6 additions & 7 deletions unpacker.hs → deploy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Filesystem.Path.CurrentOS
import Filesystem
import System.IO.Error (isAlreadyExistsError)
import System.Cmd (rawSystem)
import Reconfig

main :: IO ()
main = do
Expand All @@ -30,13 +31,11 @@ unpack dir = do
dest <- getDest [1..]
let incoming = dir </> "incoming"
listDirectory incoming >>= mapM_ (unpack1 dest)
_ <- rawSystem (encodeString $ dir </> "bin" </> "reconfig")
[ encodeString dir
, encodeString dest
, encodeString $ dir </> "etc" </> "angel.conf"
, "/etc/nginx/sites-enabled/yesod-deploy.conf"
]
return ()
reconfig
(encodeString dir)
(encodeString dest)
(encodeString $ dir </> "etc" </> "angel.conf")
("/etc/nginx/sites-enabled/yesod-deploy.conf")
where
getDest :: [Int] -> IO FilePath
getDest [] = error "getDest:impossible happened"
Expand Down
4 changes: 2 additions & 2 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash -ex

mkdir -p /yesod-deploy/{bin,etc,incoming,unpacked}
cp angel reconfig unpacker /yesod-deploy/bin
cp angel deploy /yesod-deploy/bin

apt-get install nginx

cat > /yesod-deploy/etc/angel.conf <<EOF
unpacker {
exec = "/yesod-deploy/bin/unpacker /yesod-deploy/"
exec = "/yesod-deploy/bin/deploy /yesod-deploy/"
}
EOF

Expand Down

0 comments on commit 8997653

Please sign in to comment.