Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: add deploy sub-command invoking docker stack deploy #257

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
devShells.default = config.devShells.haskell-package.overrideAttrs (o: {
nativeBuildInputs = o.nativeBuildInputs or [ ] ++ [
pkgs.docker-compose
pkgs.docker
pkgs.nixpkgs-fmt
config.haskellProjects.haskell-package.haskellPackages.releaser
];
Expand Down
2 changes: 1 addition & 1 deletion nix/upstreamable/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ let
mv $out/bin/arion $out/libexec
makeWrapper $out/libexec/arion $out/bin/arion \
--unset PYTHONPATH \
--prefix PATH : ${lib.makeBinPath [ pkgs.docker-compose ]} \
--prefix PATH : ${lib.makeBinPath [ pkgs.docker-compose pkgs.docker ]} \
;
'';
};
Expand Down
7 changes: 6 additions & 1 deletion src/haskell/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ parseCommand =
<> commandDC runEvalAndDC "top" "Display the running processes"
<> commandDC runEvalAndDC "unpause" "Unpause services"
<> commandDC runBuildAndDC "up" "Create and start containers"
<> commandDC runEvalAndDC "deploy" "Deploy a new stack or update an existing stack"
<> commandDC runDC "version" "Show the Docker-Compose version information"

<> metavar "DOCKER-COMPOSE-COMMAND"
Expand Down Expand Up @@ -164,7 +165,10 @@ callDC cmd dopts opts shouldLoadImages path = do
let firstOpts = projectArgs extendedInfo <> commonArgs opts
DockerCompose.run DockerCompose.Args
{ files = [path]
, otherArgs = firstOpts ++ [cmd] ++ unDockerComposeArgs dopts
, otherArgs = case cmd of
"deploy" -> unDockerComposeArgs dopts ++ toList (projectName extendedInfo)
_ -> firstOpts ++ [cmd] ++ unDockerComposeArgs dopts
, useSwarm = cmd == "deploy"
}

projectArgs :: ExtendedInfo -> [Text]
Expand Down Expand Up @@ -314,6 +318,7 @@ runExec detach privileged user noTTY index envs workDir service commandAndArgs o
DockerCompose.run DockerCompose.Args
{ files = [path]
, otherArgs = projectArgs extendedInfo <> commonArgs opts <> args
, useSwarm = False
}

main :: IO ()
Expand Down
14 changes: 10 additions & 4 deletions src/haskell/lib/Arion/DockerCompose.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ import System.Process
data Args = Args
{ files :: [FilePath]
, otherArgs :: [Text]
, useSwarm :: Bool
}

run :: Args -> IO ()
run args = do
let fileArgs = files args >>= \f -> ["--file", f]
allArgs = fileArgs ++ map toS (otherArgs args)

procSpec = proc "docker-compose" allArgs
let (executable, fileParam) = case useSwarm args of
False -> ("docker-compose", "--file")
True -> ("docker", "--compose-file")
fileArgs = files args >>= \f -> [fileParam, f]
allArgs = case useSwarm args of
False -> fileArgs ++ map toS (otherArgs args)
True -> ["stack", "deploy"] ++ fileArgs ++ map toS (otherArgs args)

procSpec = proc executable allArgs

-- hPutStrLn stderr ("Running docker-compose with " <> show allArgs :: Text)

Expand Down
2 changes: 1 addition & 1 deletion src/haskell/testdata/Arion/NixSpec/arion-compose.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
]
}
},
"version": "3.4",
"version": "3.8",
"volumes": {},
"x-arion": {
"images": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"volumes": []
}
},
"version": "3.4",
"version": "3.8",
"volumes": {},
"x-arion": {
"images": [
Expand Down
2 changes: 1 addition & 1 deletion src/haskell/testdata/docker-compose-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
]
}
},
"version": "3.4",
"version": "3.8",
"x-arion": {
"images": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/nix/modules/composition/docker-compose.nix
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ in
out.dockerComposeYamlAttrs = config.assertWarn config.docker-compose.raw;

docker-compose.raw = {
version = "3.4";
version = "3.8";
services = lib.mapAttrs (k: c: c.out.service) config.services;
x-arion = config.docker-compose.extended;
volumes = config.docker-compose.volumes;
Expand Down