wasp
wasp copied to clipboard
Implement `wasp build start` command that runs output of `wasp build`
wasp build produces artfeacts like static files for client and Dockerfile for server, but there is no simple way to run then, you have to figure out commands to run that Dockerfile on your own, and also serve those static files correctly, set up env vars, ... .
What most frameworks have is a way to easily try out the code produced by wasp build, and we should have the same thing, it should run it for you, locally, but similarly like it would run for real, so you can that way test the built app.
How to test whether a Wasp app builds and runs correctly
I'll paste my current setup here (as discussed on Discord).
Usage
After the setup, testing a local deployment becomes as simple as:
- Run
wasp buildin the root of your project. - Run
srun <instanceName>from the project root to build and start the server in a Docker container. Choose anything you want for hteinstanceName - Open a new terminal and run
crunfrom the project root to build and start the client.
Here's a video that shows it in action:
https://github.com/wasp-lang/wasp/assets/22752307/09d0e93d-b623-4e55-864e-84ee39808a17
Setup
Step 1: The database
I recommend you keep a PostgreSQL db running in the backgorund at all times. It's easier than wasp start db because:
- It's project-agnostic.
- You can name your own databases (which saves us from ever having to worry about the
DATABASE_URL).
You set it once and forget it (until you shut down your computer, but Docker can probably take care of that too). Setting it up is pretty easy:
- Make sure you have docker running.
- Free up port
5433(The port is different than5432used bywasp start dbon purpose so you can keep using that when you want). - Execute the following command in a terminal somewhere and leave it running (you want need
sudoif you're on a Mac):
sudo docker run --rm --publish 5433:5432 -v my-app-data:/var/lib/postgresql/data --env POSTGRES_PASSWORD=devpass1234 postgres
Step 2: The srun script
This is the command we use to build and run the server using Docker. Again, you can remove all the sudos if you're on a Mac.
Put this script somewhere in your path and name it srun (I have all my personal scripts in ~/bin, which I make sure is in my path):
app_name="$1"
docker build -t "$app_name" .wasp/build/ && docker run \
--env DATABASE_URL="postgresql://postgres:devpass1234@localhost:5433/${app_name}-db" \
--env WASP_WEB_CLIENT_URL='http://localhost:3000' \
--env JWT_SECRET='your-jwt-secret' \
--env GOOGLE_CLIENT_SECRET="your-google-client-secret" \
--env GOOGLE_CLIENT_ID="your-google-client-id" \
--env KEYCLOAK_CLIENT_ID="your-keycloak-client-id" \
--env KEYCLOAK_CLIENT_SECRET="your-keycloak-client-secret" \
--env KEYCLOAK_REALM_URL="https://your-keycloak-url.com/realms/master" \
--env GITHUB_CLIENT_ID="your-github-client-id" \
--env GITHUB_CLIENT_SECRET="your-github-client-secret" \
--env WASP_SERVER_URL='http://localhost:3001' \
--env OPENAI_API_KEY="your-open-api-key" \
--env-file .env.server \
--network host \
"$app_name"
We always set ALL possible env vars to make sure all features in all apps work out of the box (although most apps don't need most of the vars).
Step 3: The crun script
This is the command we use to build the client and serve the static files.
Put this script somewhere in your path and name it crun:
#!/bin/bash
cd .wasp/build/web-app
REACT_APP_API_URL='http://localhost:3001' npm run build
cd build
npx serve --single -p 3000
CLI:
- build and run the client
- build and run docker for the server
- run db in docker?
orchestrate all this
We should look into wasp-app-runner for sure, it does (big) part of this, so that should be the starting point (@infomiho knows about it the most).
Suggestion: @infomiho , @sodic and @cprecioso do first brief, then RFC.