-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathServer.hs
More file actions
42 lines (38 loc) · 1.5 KB
/
Copy pathServer.hs
File metadata and controls
42 lines (38 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module Wasp.Cli.Command.BuildStart.Server
( buildServer,
startServer,
)
where
import qualified StrongPath as SP
import System.Process (proc)
import Wasp.Cli.Command.BuildStart.Config (BuildStartConfig)
import qualified Wasp.Cli.Command.BuildStart.Config as Config
import qualified Wasp.Cli.Command.BuildStart.Job as BuildStartJob
import qualified Wasp.Job as Job
import qualified Wasp.Job.Subprocess as Subprocess
buildServer :: BuildStartConfig -> BuildStartJob.JobExecution
buildServer config =
BuildStartJob.run (("Building the server failed with exit code: " <>) . show) $
Job.makeJob Job.Server $
Subprocess.run (proc "docker" ["build", "--tag", dockerImageName, dockerContextDir])
where
dockerContextDir = SP.fromAbsDir buildDir
buildDir = Config.buildDir config
dockerImageName = Config.dockerImageName config
startServer :: BuildStartConfig -> BuildStartJob.JobExecution
startServer config =
BuildStartJob.run (("Running the server failed with exit code: " <>) . show) $
Job.makeJob Job.Server $
Subprocess.run $
proc
"docker"
( ["run", "--name", dockerContainerName, "--rm", "--network", "host"]
<> envVarParams
<> [dockerImageName]
)
where
envVarParams = toEnvVarParams $ Config.serverEnvVars config
dockerContainerName = Config.dockerContainerName config
dockerImageName = Config.dockerImageName config
toEnvVarParams list =
list >>= \(name, value) -> ["--env", name <> "=" <> value]