Skip to content

Commit

Permalink
The default deploy name for a release no longer includes the zip suffix
Browse files Browse the repository at this point in the history
This means that we no longer need to drop the suffix for the directory name,
avoid problems where different deploy names differ only in the suffix
  • Loading branch information
timbod7 committed Sep 22, 2020
1 parent ac1e445 commit a50f1d4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/Commands/ProxyMode/LocalState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import Data.Foldable(for_)
import Data.Monoid
import Data.Word
import System.Directory(createDirectoryIfMissing,doesFileExist,doesDirectoryExist,withCurrentDirectory, removeDirectoryRecursive)
import System.FilePath(takeBaseName, takeDirectory, dropExtension, replaceExtension, (</>))
import System.FilePath(takeDirectory, dropExtension, replaceExtension, (</>))
import System.Process(callCommand)
import Types(IOR, REnv(..), getToolConfig, scopeInfo, info)

Expand Down Expand Up @@ -119,7 +119,7 @@ executeAction (CreateDeploy d) = do
tcfg <- getToolConfig
pm <- getProxyModeConfig
fetchConfigContext Nothing
let deployDir = T.unpack (tc_deploysDir tcfg) </> (takeBaseName (T.unpack (d_label d)))
let deployDir = getDeployDir tcfg d
liftIO $ createDirectoryIfMissing True deployDir
unpackRelease (contextWithLocalPorts pm (d_port d)) (d_release d) deployDir

Expand All @@ -131,7 +131,7 @@ executeAction (CreateDeploy d) = do
executeAction (DestroyDeploy d) = do
scopeInfo "execute DestroyDeploy" $ do
tcfg <- getToolConfig
let deployDir = T.unpack (tc_deploysDir tcfg) </> (takeBaseName (T.unpack (d_label d)))
let deployDir = getDeployDir tcfg d
rcfg <- getReleaseConfig deployDir
scopeInfo "running stop script" $ callCommandInDir deployDir (rc_stopCommand rcfg)
scopeInfo "removing directory" $ liftIO $ removeDirectoryRecursive deployDir
Expand Down Expand Up @@ -355,6 +355,9 @@ getReleaseConfig :: FilePath -> IOR ReleaseConfig
getReleaseConfig deployDir = do
liftIO $ adlFromJsonFile' (deployDir </> "release.json")

getDeployDir :: ToolConfig -> Deploy -> FilePath
getDeployDir tcfg d = T.unpack (tc_deploysDir tcfg) </> (T.unpack (d_label d))


nginxConfTemplate :: T.Text
nginxConfTemplate = T.decodeUtf8 $(embedFile "config/nginx.conf.tpl")
9 changes: 6 additions & 3 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Control.Monad.Catch(finally,catch)
import Control.Monad.IO.Class
import Control.Monad.Reader(runReaderT)
import Data.List(isPrefixOf)
import Data.Maybe(fromMaybe)
import Data.Monoid
import Data.Semigroup ((<>))
import Data.Version(showVersion)
Expand All @@ -32,7 +33,7 @@ import Paths_camus2(version)
import System.Directory(doesFileExist)
import System.Environment(getArgs, lookupEnv, getExecutablePath)
import System.Exit(exitWith,ExitCode(..))
import System.FilePath(takeDirectory, takeExtension, (</>))
import System.FilePath(takeBaseName, takeDirectory, takeExtension, (</>))
import System.Posix.Files(fileExist)
import Types(REnv(..),IOR, getToolConfig)
import Util.Aws(mkAwsEnvFn0, AwsEnv)
Expand Down Expand Up @@ -230,8 +231,7 @@ runCommand (UnpackRelease (release,toDir)) = runWithConfigAndLog (U.unpackReleas
runCommand (ExpandTemplate (templatePath,destPath)) = runWithConfigAndLog (U.injectContext id templatePath destPath)
runCommand AwsDockerLoginCmd = runWithConfigAndLog (C.awsDockerLoginCmd)
runCommand (Status showSlaves) = runWithConfig (P.showStatus showSlaves)
runCommand (Start (release,Nothing)) = runWithConfigAndLog (C.createAndStart release release)
runCommand (Start (release,Just asDeploy)) = runWithConfigAndLog (C.createAndStart release asDeploy)
runCommand (Start (release,mdeploy)) = runWithConfigAndLog (C.createAndStart release (fromMaybe (deployNameFromRelease release) mdeploy))
runCommand (Stop deploy) = runWithConfigAndLog (C.stopDeploy deploy)
runCommand (Connect (endpoint,deploy)) = runWithConfigAndLog (P.connect endpoint deploy)
runCommand (Disconnect endpoint) = runWithConfigAndLog (P.disconnect endpoint)
Expand Down Expand Up @@ -267,6 +267,9 @@ completeConfiguredEndpoints prefix = evalWithConfig $ do
return (filter (isPrefixOf prefix) endpoints)
_ -> return []

deployNameFromRelease :: T.Text -> T.Text
deployNameFromRelease release = T.pack (takeBaseName (T.unpack release))

helpCmd :: IO ()
helpCmd = do
CBS.putStrLn helpText
Expand Down
5 changes: 3 additions & 2 deletions test/httpd-proxy-local.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
tearDownTest,
zipAddReleaseJson,
writeReleaseZip,
defaultDeployName
} from "./testUtils";
import { C2Exec } from "./C2Exec";
import promiseRetry from "promise-retry";
Expand Down Expand Up @@ -137,7 +138,7 @@ describe(`Run httpd-proxy-local`, () => {
for (const rel of releases) {
console.log("c2 start release", rel.releaseName);
await c2machine.start(rel.releaseName);
await c2machine.connect(rel.endpoint, rel.releaseName);
await c2machine.connect(rel.endpoint, defaultDeployName(rel.releaseName));
}

for (const rel of releases) {
Expand Down Expand Up @@ -192,7 +193,7 @@ describe(`Run httpd-proxy-local`, () => {

for (const rel of releases) {
await c2machine!.disconnect(rel.endpoint);
await c2machine!.stop(rel.releaseName);
await c2machine!.stop(defaultDeployName(rel.releaseName));
}

// for test cleanup
Expand Down
5 changes: 3 additions & 2 deletions test/httpd-proxy-remote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
writeReleaseZip,
localstack,
makeReleaseHttpd,
defaultDeployName,
} from "./testUtils";
import { C2Exec } from "./C2Exec";
import promiseRetry from "promise-retry";
Expand Down Expand Up @@ -120,7 +121,7 @@ describe(`Run httpd-proxy-remote`, () => {
for (const rel of releases) {
console.log("c2 start release", rel.releaseName);
await c2controller.start(rel.releaseName);
await c2controller.connect(rel.endpoint, rel.releaseName);
await c2controller.connect(rel.endpoint, defaultDeployName(rel.releaseName));
}

/// In deployment this happens on target machine periodically
Expand Down Expand Up @@ -158,7 +159,7 @@ describe(`Run httpd-proxy-remote`, () => {

for (const rel of releases) {
await c2controller!.disconnect(rel.endpoint);
await c2controller!.stop(rel.releaseName);
await c2controller!.stop(defaultDeployName(rel.releaseName));
}
await c2machine.slaveUpdate();

Expand Down
4 changes: 4 additions & 0 deletions test/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,7 @@ services:
zip.file(testfilePath, testfileContents);
return zip;
}

export function defaultDeployName(releasename: string): string {
return path.parse(releasename).name;
}

0 comments on commit a50f1d4

Please sign in to comment.