Skip to content

Create wasp build start command #2796

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

Merged
Show file tree
Hide file tree
Changes from 90 commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
3e05664
wip
cprecioso May 26, 2025
9ea053f
Use common abstractions
cprecioso Jun 2, 2025
e06a292
Remove build
cprecioso Jun 2, 2025
5e7c8c3
Remove unused imports
cprecioso Jun 2, 2025
128f70e
Fix
cprecioso Jun 2, 2025
ddc9a32
Merge branch 'main' into 1883-implement-wasp-build-start-command-that…
cprecioso Jun 2, 2025
5b57571
Merge branch 'main' into 1883-implement-wasp-build-start-command-that…
cprecioso Jun 2, 2025
9e72db1
Just learned about `ExceptT`
cprecioso Jun 3, 2025
5b44f5c
Now it works!
cprecioso Jun 3, 2025
87734fc
Merge branch 'main' into 1883-implement-wasp-build-start-command-that…
cprecioso Jun 4, 2025
9a2831b
Allow `dbExecuteTest` to run without built .env files
cprecioso Jun 4, 2025
b1a4e97
Pass the error channel around for printing if needed
cprecioso Jun 4, 2025
30c4a7c
Print Prisma output when there's an unknown error
cprecioso Jun 4, 2025
f262562
Allow requirement to be parametrized by folder
cprecioso Jun 4, 2025
6d86658
Merge better prisma
cprecioso Jun 4, 2025
01ac717
Add checking DB connection
cprecioso Jun 4, 2025
0b91a74
Improve JobExcept abstraction
cprecioso Jun 5, 2025
a35f5a6
Correct
cprecioso Jun 5, 2025
af0772c
Add Build dir check
cprecioso Jun 5, 2025
df97486
Remove workaround for interactive Prisma
cprecioso Jun 16, 2025
c326246
Merge branch 'cprecioso/push-rmwtsrklmvrs' into cprecioso/push-yppoqw…
cprecioso Jun 16, 2025
fd4b9d5
Better env handling
cprecioso Jun 16, 2025
80e43ed
Simple
cprecioso Jun 16, 2025
39bd54e
Merge branch 'main' into cprecioso/push-yppoqwmksmyl
cprecioso Jun 17, 2025
9c35873
Add new file to cabal
cprecioso Jun 17, 2025
7794642
Add note back
cprecioso Jun 17, 2025
7b02f44
Naming changes
cprecioso Jun 17, 2025
a427e85
Return prisma path
cprecioso Jun 17, 2025
9a3d570
Merge branch 'cprecioso/push-yppoqwmksmyl' into 1883-implement-wasp-b…
cprecioso Jun 17, 2025
305987a
Come back comment
cprecioso Jun 17, 2025
b78c7b6
Stop trying to make DBConnectionEstablished happen
cprecioso Jun 17, 2025
3a0f7e6
Undo :(
cprecioso Jun 17, 2025
54a2a28
Merge commit '3a0f7e61' into 1883-implement-wasp-build-start-command-…
cprecioso Jun 17, 2025
827e6ab
Pass DATABASE_URL
cprecioso Jun 17, 2025
c69ddfc
Do not hardcode ports and urls
cprecioso Jun 17, 2025
fddbca7
Move unique id
cprecioso Jun 17, 2025
3c3327d
Use common wasp app name logic
cprecioso Jun 17, 2025
c9d389c
Change name convention to match wasp-app-runner
cprecioso Jun 17, 2025
b2f1801
Better comment
cprecioso Jun 17, 2025
1071176
Rename `DbConnectionEstablished` to `DbConnectionEstablishedFromOutDir`
cprecioso Jun 23, 2025
806c4b1
Merge
cprecioso Jun 23, 2025
670a34d
Address comments (1)
cprecioso Jun 23, 2025
512d0c9
Address review (2)
cprecioso Jun 23, 2025
64dea5f
Address review (3)
cprecioso Jun 23, 2025
edd6700
Address review (4)
cprecioso Jun 23, 2025
20f2d13
Merge branch 'main' into 1883-implement-wasp-build-start-command-that…
cprecioso Jun 23, 2025
252a269
Merge branch 'main' into 1883-implement-wasp-build-start-command-that…
cprecioso Jul 1, 2025
98be630
Address comments
cprecioso Jul 1, 2025
b0f06be
Explicit Docker lowercase
cprecioso Jul 3, 2025
d63e3f9
Merge branch 'main' into 1883-implement-wasp-build-start-command-that…
cprecioso Jul 4, 2025
05fc1b4
Refactor env variables
cprecioso Jul 4, 2025
675f760
Merge branch 'push-uuqynktmlxnr' into 1883-implement-wasp-build-start…
cprecioso Jul 4, 2025
32bb4e8
Update
cprecioso Jul 4, 2025
02de3fb
Merge branch 'main' into push-uuqynktmlxnr
cprecioso Jul 11, 2025
b9700c2
Merge branch 'push-uuqynktmlxnr' into 1883-implement-wasp-build-start…
cprecioso Jul 11, 2025
e57b2e7
Implement env args for build start
cprecioso Jul 11, 2025
369d829
Extract parseArguments
cprecioso Jul 11, 2025
92bdf6e
Update CLI help
cprecioso Jul 11, 2025
1651b84
Address reviews
cprecioso Jul 16, 2025
0462b9f
Comments
cprecioso Jul 16, 2025
3328dd8
comments
cprecioso Jul 16, 2025
810218f
Address
cprecioso Jul 16, 2025
6172984
Address
cprecioso Jul 16, 2025
2c3cbf4
Merge branch 'main' into 1883-implement-wasp-build-start-command-that…
cprecioso Jul 16, 2025
396ec95
Merge branch 'main' into push-uuqynktmlxnr
cprecioso Jul 16, 2025
6c8b47a
Merge branch 'push-uuqynktmlxnr' into 1883-implement-wasp-build-start…
cprecioso Jul 16, 2025
2220f20
Rename
cprecioso Jul 17, 2025
8d1e5a5
Remove from starter
cprecioso Jul 17, 2025
000c033
Qualify AuthG
cprecioso Jul 17, 2025
316a97a
Merge branch 'push-uuqynktmlxnr' into 1883-implement-wasp-build-start…
cprecioso Jul 17, 2025
3f2db84
Update
cprecioso Jul 17, 2025
d57b233
comments
cprecioso Jul 17, 2025
56ce5a7
Comment
cprecioso Jul 17, 2025
399f664
Comments
cprecioso Jul 17, 2025
0ea6f52
Merge branch 'main' into 1883-implement-wasp-build-start-command-that…
cprecioso Jul 18, 2025
3c1ce25
Merge branch 'main' into 1883-implement-wasp-build-start-command-that…
cprecioso Jul 18, 2025
acb5b9e
Comment
cprecioso Jul 18, 2025
f4a892e
Add comment
cprecioso Jul 18, 2025
315a5b6
Always parse env vars
cprecioso Jul 18, 2025
f10fe23
Parse env var files
cprecioso Jul 18, 2025
54e37d6
Parse env var args when creating config
cprecioso Jul 18, 2025
b75cb86
forceEnvVars impl
cprecioso Jul 18, 2025
3ebeda6
Force env vars in config
cprecioso Jul 18, 2025
6ec1329
Reorder
cprecioso Jul 18, 2025
5335604
Reorder
cprecioso Jul 18, 2025
9a31194
Reorder
cprecioso Jul 18, 2025
c38eb7f
Remove unneeded import
cprecioso Jul 18, 2025
00e6a5a
Merge branch 'main' into 1883-implement-wasp-build-start-command-that…
cprecioso Jul 22, 2025
67ff2e4
Add changelog
cprecioso Jul 22, 2025
c09269c
docs
cprecioso Jul 22, 2025
28aa46b
Fix changelog
cprecioso Jul 23, 2025
c8b5642
Move WorkingDir
cprecioso Jul 23, 2025
c8ba324
Together
cprecioso Jul 23, 2025
8a39527
Renames
cprecioso Jul 23, 2025
d8e3b2d
Add unit tests
cprecioso Jul 23, 2025
975c62c
Merge branch 'main' into 1883-implement-wasp-build-start-command-that…
cprecioso Jul 24, 2025
4580549
Remove redundant import
cprecioso Jul 24, 2025
01de580
Simplify env var file argument logic, use stdlib functions
cprecioso Jul 24, 2025
421c00c
Remove unused WorkingDir
cprecioso Jul 24, 2025
7c15c77
Simplify EnvVarFileArgument
cprecioso Jul 24, 2025
7b48205
Merge branch 'main' into 1883-implement-wasp-build-start-command-that…
cprecioso Jul 24, 2025
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
6 changes: 6 additions & 0 deletions waspc/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### 🎉 New Features

- New command: `wasp build start`. It allows you to run your built Wasp app as it would run in your production server. Useful for testing your production build locally, and making sure of passing the correct environment variables. [#2796](https://github.com/wasp-lang/wasp/pull/2796)

## 0.17.0

### ⚠️ Breaking Changes
Expand Down
4 changes: 4 additions & 0 deletions waspc/cli/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import System.Exit (exitFailure)
import Wasp.Cli.Command (runCommand)
import Wasp.Cli.Command.BashCompletion (bashCompletion, generateBashCompletionScript, printBashCompletionInstruction)
import Wasp.Cli.Command.Build (build)
import Wasp.Cli.Command.BuildStart (buildStart)
import qualified Wasp.Cli.Command.Call as Command.Call
import Wasp.Cli.Command.Clean (clean)
import Wasp.Cli.Command.Compile (compile)
Expand Down Expand Up @@ -58,6 +59,7 @@ main = withUtf8 . (`E.catch` handleInternalErrors) $ do
["uninstall"] -> Command.Call.Uninstall
["version"] -> Command.Call.Version
["build"] -> Command.Call.Build
("build" : "start" : buildStartArgs) -> Command.Call.BuildStart buildStartArgs
["telemetry"] -> Command.Call.Telemetry
["deps"] -> Command.Call.Deps
["dockerfile"] -> Command.Call.Dockerfile
Expand Down Expand Up @@ -111,6 +113,7 @@ main = withUtf8 . (`E.catch` handleInternalErrors) $ do
Command.Call.Studio -> runCommand studio
Command.Call.Uninstall -> runCommand uninstall
Command.Call.Build -> runCommand build
Command.Call.BuildStart buildStartArgs -> runCommand $ buildStart buildStartArgs
Command.Call.Telemetry -> runCommand Telemetry.telemetry
Command.Call.Deps -> runCommand deps
Command.Call.Dockerfile -> runCommand printDockerfile
Expand Down Expand Up @@ -179,6 +182,7 @@ printUsage =
cmd " clean Deletes all generated code, all cached artifacts, and the node_modules dir.",
" Wasp equivalent of 'have you tried closing and opening it again?'.",
cmd " build Generates full web app code, ready for deployment. Use when deploying or ejecting.",
cmd " build start [args] Previews the built production app locally.",
cmd " deploy Deploys your Wasp app to cloud hosting providers.",
cmd " telemetry Prints telemetry status.",
cmd " deps Prints the dependencies that Wasp uses in your project.",
Expand Down
78 changes: 78 additions & 0 deletions waspc/cli/src/Wasp/Cli/Command/BuildStart.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
module Wasp.Cli.Command.BuildStart
( buildStart,
)
where

import Control.Concurrent.Async (concurrently)
import Control.Concurrent.Chan (newChan)
import Control.Monad.Except (MonadError (throwError), runExceptT)
import Control.Monad.IO.Class (liftIO)
import Data.Function ((&))
import Wasp.Cli.Command (Command, CommandError (CommandError), require)
import Wasp.Cli.Command.BuildStart.ArgumentsParser (buildStartArgsParser)
import Wasp.Cli.Command.BuildStart.Client (buildClient, startClient)
import Wasp.Cli.Command.BuildStart.Config (BuildStartConfig, makeBuildStartConfig)
import Wasp.Cli.Command.BuildStart.Server (buildServer, startServer)
import Wasp.Cli.Command.Call (Arguments)
import Wasp.Cli.Command.Compile (analyze)
import Wasp.Cli.Command.Message (cliSendMessageC)
import Wasp.Cli.Command.Require (BuildDirExists (BuildDirExists), InWaspProject (InWaspProject))
import Wasp.Cli.Util.Parser (parseArguments)
import Wasp.Job.Except (ExceptJob)
import qualified Wasp.Job.Except as ExceptJob
import Wasp.Job.IO (readJobMessagesAndPrintThemPrefixed)
import qualified Wasp.Message as Msg

buildStart :: Arguments -> Command ()
buildStart args = do
buildStartArgs <-
parseArguments "wasp build start" buildStartArgsParser args
& either (throwError . CommandError "Parsing arguments failed") return

BuildDirExists _ <- require

InWaspProject waspProjectDir <- require
appSpec <- analyze waspProjectDir

-- TODO: Find a way to easily check we can connect to the DB. We'd like to
-- throw a clear error if not available. (See #2858)
--
-- It is not a big problem right now, because Prisma will fail shortly after
-- the server starts if the DB is not running anyway, and with a very clear
-- error message that we print.

config <- makeBuildStartConfig appSpec buildStartArgs waspProjectDir

buildAndStartServerAndClient config

buildAndStartServerAndClient :: BuildStartConfig -> Command ()
buildAndStartServerAndClient config = do
cliSendMessageC $ Msg.Start "Building client..."
runAndPrintJob "Building client failed." $
buildClient config
cliSendMessageC $ Msg.Success "Client built."

cliSendMessageC $ Msg.Start "Building server..."
runAndPrintJob "Building server failed." $
buildServer config
cliSendMessageC $ Msg.Success "Server built."

cliSendMessageC $ Msg.Start "Starting client and server..."
runAndPrintJob "Starting Wasp app failed." $
ExceptJob.race_
(startClient config)
(startServer config)
where
runAndPrintJob :: String -> ExceptJob -> Command ()
runAndPrintJob errorMessage job = do
liftIO (runAndPrintJobIO job)
>>= either (throwError . CommandError errorMessage) return

runAndPrintJobIO :: ExceptJob -> IO (Either String ())
runAndPrintJobIO job = do
chan <- newChan
(result, _) <-
concurrently
(runExceptT $ job chan)
(readJobMessagesAndPrintThemPrefixed chan)
return result
50 changes: 50 additions & 0 deletions waspc/cli/src/Wasp/Cli/Command/BuildStart/ArgumentsParser.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module Wasp.Cli.Command.BuildStart.ArgumentsParser
( buildStartArgsParser,
BuildStartArgs (..),
)
where

import qualified Options.Applicative as Opt
import Wasp.Cli.Util.EnvVarArgument (EnvVarFileArgument, envVarFileReader, envVarReader)
import Wasp.Env (EnvVar)

data BuildStartArgs = BuildStartArgs
{ clientEnvironmentVariables :: [EnvVar],
clientEnvironmentFiles :: [EnvVarFileArgument],
serverEnvironmentVariables :: [EnvVar],
serverEnvironmentFiles :: [EnvVarFileArgument]
}

buildStartArgsParser :: Opt.Parser BuildStartArgs
buildStartArgsParser =
BuildStartArgs
<$> Opt.many clientEnvironmentVariableParser
<*> Opt.many clientEnvironmentFileParser
<*> Opt.many serverEnvironmentVariableParser
<*> Opt.many serverEnvironmentFileParser
where
clientEnvironmentVariableParser =
makeEnvironmentVariableParser "client" "client-env" 'c'
clientEnvironmentFileParser =
makeEnvironmentFileParser "client" "client-env-file"

serverEnvironmentVariableParser =
makeEnvironmentVariableParser "server" "server-env" 's'
serverEnvironmentFileParser =
makeEnvironmentFileParser "server" "server-env-file"

makeEnvironmentVariableParser :: String -> String -> Char -> Opt.Parser EnvVar
makeEnvironmentVariableParser targetName longOptionName shortOptionName =
Opt.option envVarReader $
Opt.long longOptionName
<> Opt.short shortOptionName
<> Opt.metavar "NAME=VALUE"
<> Opt.help ("Set an environment variable for the " <> targetName <> " (can be used multiple times)")

makeEnvironmentFileParser :: String -> String -> Opt.Parser EnvVarFileArgument
makeEnvironmentFileParser targetName longOptionName =
Opt.option envVarFileReader $
Opt.long longOptionName
<> Opt.metavar "FILE_PATH"
<> Opt.help ("Load environment variables for the " <> targetName <> " from a file (can be used multiple times)")
<> Opt.action "file"
48 changes: 48 additions & 0 deletions waspc/cli/src/Wasp/Cli/Command/BuildStart/Client.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module Wasp.Cli.Command.BuildStart.Client
( buildClient,
startClient,
)
where

import Data.Function ((&))
import StrongPath ((</>))
import Wasp.Cli.Command.BuildStart.Config (BuildStartConfig)
import qualified Wasp.Cli.Command.BuildStart.Config as Config
import qualified Wasp.Generator.WebAppGenerator.Common as WebApp
import qualified Wasp.Job as J
import Wasp.Job.Except (ExceptJob, toExceptJob)
import Wasp.Job.Process (runNodeCommandAsJob, runNodeCommandAsJobWithExtraEnv)

buildClient :: BuildStartConfig -> ExceptJob
buildClient config =
runNodeCommandAsJobWithExtraEnv
envVars
webAppDir
"npm"
["run", "build"]
J.WebApp
& toExceptJob (("Building the client failed with exit code: " <>) . show)
where
envVars = Config.clientEnvVars config
webAppDir = buildDir </> WebApp.webAppRootDirInProjectRootDir
buildDir = Config.buildDir config

startClient :: BuildStartConfig -> ExceptJob
startClient config =
runNodeCommandAsJob
webAppDir
"npm"
[ "run",
"preview", -- `preview` launches a static file server for the built client.
"--",
"--port",
port,
"--strictPort" -- This will make it fail if the port is already in use.
]
J.WebApp
& toExceptJob (("Serving the client failed with exit code: " <>) . show)
where
port = show $ fst $ Config.clientPortAndUrl config

buildDir = Config.buildDir config
webAppDir = buildDir </> WebApp.webAppRootDirInProjectRootDir
121 changes: 121 additions & 0 deletions waspc/cli/src/Wasp/Cli/Command/BuildStart/Config.hs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wdyt about this solution? Moved all the environment variable calculation to the config creationg, so we can just pass an [EnvVar] around, and not have 4 different but very similar properties.

And split the constructor into two parts, one initial one and another where we put the envs, as that part has to be IO.

Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
module Wasp.Cli.Command.BuildStart.Config
( BuildStartConfig,
buildDir,
clientEnvVars,
clientPortAndUrl,
dockerContainerName,
dockerImageName,
makeBuildStartConfig,
serverEnvVars,
serverUrl,
)
where

import Control.Monad.Except (MonadError (throwError), MonadIO (liftIO))
import Data.Char (toLower)
import Data.List (intercalate)
import StrongPath ((</>))
import qualified StrongPath as SP
import Wasp.AppSpec (AppSpec)
import qualified Wasp.AppSpec.Valid as ASV
import Wasp.Cli.Command (Command, CommandError (CommandError))
import Wasp.Cli.Command.BuildStart.ArgumentsParser (BuildStartArgs)
import qualified Wasp.Cli.Command.BuildStart.ArgumentsParser as Args
import Wasp.Cli.Util.EnvVarArgument (EnvVarFileArgument, readEnvVarFile)
import Wasp.Env (EnvVar, forceEnvVars, nubEnvVars)
import Wasp.Generator.Common (ProjectRootDir)
import Wasp.Generator.ServerGenerator.Common (defaultDevServerUrl)
import qualified Wasp.Generator.ServerGenerator.Common as Server
import Wasp.Generator.WebAppGenerator.Common (defaultClientPort, getDefaultDevClientUrl)
import qualified Wasp.Generator.WebAppGenerator.Common as WebApp
import Wasp.Project.Common (WaspProjectDir, buildDirInDotWaspDir, dotWaspDirInWaspProjectDir, makeAppUniqueId)

data BuildStartConfig = BuildStartConfig
{ appUniqueId :: String,
clientPortAndUrl :: (Int, String),
serverEnvVars :: [EnvVar],
clientEnvVars :: [EnvVar],
buildDir :: SP.Path' SP.Abs (SP.Dir ProjectRootDir)
}

makeBuildStartConfig :: AppSpec -> BuildStartArgs -> SP.Path' SP.Abs (SP.Dir WaspProjectDir) -> Command BuildStartConfig
makeBuildStartConfig appSpec args projectDir = do
let config = makeBuildStartConfigWithoutEnvVars appSpec projectDir

serverEnvVars' <-
readAndForceEnvVars
[ (Server.clientUrlEnvVarName, show $ fst $ clientPortAndUrl config),
(Server.serverUrlEnvVarName, serverUrl config)
]
(Args.serverEnvironmentVariables args)
(Args.serverEnvironmentFiles args)

clientEnvVars' <-
readAndForceEnvVars
[ (WebApp.serverUrlEnvVarName, serverUrl config)
]
(Args.clientEnvironmentVariables args)
(Args.clientEnvironmentFiles args)

return $
config
{ serverEnvVars = serverEnvVars',
clientEnvVars = clientEnvVars'
}

makeBuildStartConfigWithoutEnvVars :: AppSpec -> SP.Path' SP.Abs (SP.Dir WaspProjectDir) -> BuildStartConfig
makeBuildStartConfigWithoutEnvVars appSpec projectDir =
BuildStartConfig
{ appUniqueId = appUniqueId',
buildDir = buildDir',
clientPortAndUrl = (clientPort, clientUrl),
serverEnvVars = [],
clientEnvVars = []
}
where
buildDir' = projectDir </> dotWaspDirInWaspProjectDir </> buildDirInDotWaspDir
appUniqueId' = makeAppUniqueId projectDir appName
(appName, _) = ASV.getApp appSpec

-- This assumes that `getDefaultDevClientUrl` uses `defaultClientPort` internally.
-- If that changes, we also need to change this.
clientPort = defaultClientPort
clientUrl = getDefaultDevClientUrl appSpec

-- NOTE(carlos): For now, creating these URLs and ports below uses the default
-- values we've hardcoded in the generator. In the future, we might want to make
-- these configurable via the Wasp app spec or command line arguments.

serverUrl :: BuildStartConfig -> String
serverUrl _ = defaultDevServerUrl

dockerImageName :: BuildStartConfig -> String
dockerImageName config =
map toLower $ -- Lowercase because Docker image names require it.
appUniqueId config <> "-server"

dockerContainerName :: BuildStartConfig -> String
dockerContainerName config =
map toLower $ -- Lowercase because Docker container names require it.
appUniqueId config <> "-server-container"

readAndForceEnvVars :: [EnvVar] -> [EnvVar] -> [EnvVarFileArgument] -> Command [EnvVar]
readAndForceEnvVars forced existing files = do
readVars <- liftIO $ readEnvVars existing files
forceEnvVarsCommand forced readVars

readEnvVars :: [EnvVar] -> [EnvVarFileArgument] -> IO [EnvVar]
readEnvVars pairs files = do
pairsFromFiles <- mapM readEnvVarFile files
let allEnvVars = pairs <> concat pairsFromFiles
return $ nubEnvVars allEnvVars

forceEnvVarsCommand :: [EnvVar] -> [EnvVar] -> Command [EnvVar]
forceEnvVarsCommand forced existing =
case forceEnvVars forced existing of
Left duplicateNames ->
throwError $
CommandError "Duplicate environment variables" $
("The following environment variables will be overwritten by Wasp and should be removed: " <>) $
intercalate ", " duplicateNames
Right combined -> return combined
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user passes an environment variable that we override, they might get confused about why we're not using their value. So we explicitly tell them we're doing it and terminate.

image

45 changes: 45 additions & 0 deletions waspc/cli/src/Wasp/Cli/Command/BuildStart/Server.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module Wasp.Cli.Command.BuildStart.Server
( buildServer,
startServer,
)
where

import Data.Function ((&))
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.Job as J
import Wasp.Job.Except (ExceptJob, toExceptJob)
import Wasp.Job.Process (runProcessAsJob)

buildServer :: BuildStartConfig -> ExceptJob
buildServer config =
runProcessAsJob
(proc "docker" ["build", "--tag", dockerImageName, dockerContextDir])
J.Server
& toExceptJob (("Building the server failed with exit code: " <>) . show)
where
dockerContextDir = SP.fromAbsDir buildDir
buildDir = Config.buildDir config
dockerImageName = Config.dockerImageName config

startServer :: BuildStartConfig -> ExceptJob
startServer config =
runProcessAsJob
( proc
"docker"
( ["run", "--name", dockerContainerName, "--rm", "--network", "host"]
<> envVarParams
<> [dockerImageName]
)
)
J.Server
& toExceptJob (("Running the server failed with exit code: " <>) . show)
where
envVarParams = toEnvVarParams $ Config.serverEnvVars config
dockerContainerName = Config.dockerContainerName config
dockerImageName = Config.dockerImageName config

toEnvVarParams list =
list >>= \(name, value) -> ["--env", name <> "=" <> value]
1 change: 1 addition & 0 deletions waspc/cli/src/Wasp/Cli/Command/Call.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ data Call
| Compile
| Db Arguments -- db args
| Build
| BuildStart Arguments
| Version
| Telemetry
| Deps
Expand Down
Loading
Loading