Skip to content
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
98e6366
feat: add --image arg to wasp start db command
cprecioso Sep 19, 2025
02fbe50
refactor: address review feedback for --image arg feature
cprecioso Sep 19, 2025
f3e029f
refactor: use Options.Applicative for start db argument parsing
cprecioso Sep 19, 2025
071dba6
refactor: address final review comments
cprecioso Sep 19, 2025
eef03ef
style: format code for consistency
cprecioso Sep 19, 2025
cd24309
Initial impl
cprecioso Sep 19, 2025
85edcbb
Fix
cprecioso Sep 22, 2025
2644208
Rename data member
cprecioso Sep 22, 2025
7b687b9
Correct documentation
cprecioso Sep 22, 2025
fd11f79
Merge branch 'db-image-arg' into image-arg-for-wasp-app-runner
cprecioso Sep 22, 2025
7c5ce5d
More docs
cprecioso Sep 22, 2025
dcdd083
Add caveat to docs
cprecioso Sep 22, 2025
fee47c6
Format
cprecioso Sep 22, 2025
b08f5b3
Typo
cprecioso Sep 22, 2025
008b004
Add changelog
cprecioso Sep 22, 2025
4c6ddc2
Fixes
cprecioso Sep 25, 2025
f96a943
Merge branch 'main' into db-image-arg
cprecioso Sep 25, 2025
7e70d20
Comment
cprecioso Sep 25, 2025
9189200
Docs
cprecioso Sep 25, 2025
0be6c33
comment
cprecioso Sep 25, 2025
f01ae55
Rename
cprecioso Sep 25, 2025
3786a5c
Extract
cprecioso Sep 25, 2025
7b8172e
Default postgres
cprecioso Sep 25, 2025
3ad3ea1
Reorder
cprecioso Sep 25, 2025
4c4283c
Rename option
cprecioso Sep 25, 2025
de04937
Remove unneeded comments
cprecioso Sep 25, 2025
8326fae
Rename
cprecioso Sep 25, 2025
c37184d
Dots
cprecioso Sep 25, 2025
0ae96d4
Headings
cprecioso Sep 25, 2025
9a77d0f
Typo
cprecioso Sep 25, 2025
11f79b3
Explanation
cprecioso Sep 25, 2025
579006c
Extract default value
cprecioso Sep 26, 2025
f882fda
link
cprecioso Sep 26, 2025
658f0dc
Fixes
cprecioso Sep 26, 2025
211b356
Merge branch 'db-image-arg' into image-arg-for-wasp-app-runner
cprecioso Sep 22, 2025
3d8fd82
Merge branch 'db-image-arg' into image-arg-for-wasp-app-runner
cprecioso Sep 26, 2025
9d09644
Merge branch 'main' into image-arg-for-wasp-app-runner
cprecioso Sep 26, 2025
5724af6
Bring to top
cprecioso Sep 26, 2025
a301bb4
Error out if not Postgres
cprecioso Oct 1, 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
24 changes: 17 additions & 7 deletions wasp-app-runner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,18 @@ npx @wasp.sh/wasp-app-runner dev
### Options

```
npx run-wasp-app <mode> [--path-to-app <path>] [--wasp-cli-cmd <command>]
npx run-wasp-app <mode> [--path-to-app <path>] [--wasp-cli-cmd <command>] [--db-image <image>]
```

You must pass the `<mode>` as an argument, which can be either `dev` or `build`.

| Option | Description | Example |
| ---------------- | ------------------------------------------------------ | --------------- |
| `--path-to-app` | Path to your Wasp application directory (default: ".") | `./my-wasp-app` |
| `--wasp-cli-cmd` | Wasp CLI command (default: `wasp`) | `wasp-cli` |
| Option | Description | Example |
| ---------------- | ------------------------------------------------------ | ----------------- |
| `--path-to-app` | Path to your Wasp application directory (default: ".") | `./my-wasp-app` |
| `--wasp-cli-cmd` | Wasp CLI command (default: `wasp`) | `wasp-cli` |
| `--db-image` | Custom PostgreSQL Docker image (default: `postgres`) | `postgis/postgis` |

## Postgres Configuration
### Postgres Configuration

Check the `./db/postgres.ts` file to see the Postgres configuration used.

Expand All @@ -68,6 +69,15 @@ If Postgres is used, the script automatically sets the `DATABASE_URL` env variab
DATABASE_URL=postgresql://postgres:devpass@localhost:5432/postgres
```

#### Custom database image
Copy link
Contributor

Choose a reason for hiding this comment

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

The docs should mention that this can't be used in dev mode too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Where did you get the impression that it can't be used on dev mode? It can.


You can override the Docker image used for Postgres via `--db-image`. If not provided, the default `postgres` is used.

Examples: `--db-image postgres:15`, `--db-image pgvector/pgvector:pg16`, `--db-image postgis/postgis:14-3.2`.

> [!NOTE]
> The same requirements as in `wasp start db` apply for the Postgres image used. See [Wasp docs](../web/docs/data-model/databases.md#custom-database) for more details.

### Env variables

When using the `dev` mode:
Expand All @@ -85,7 +95,7 @@ When developing, you can run the script directly from the local directory withou

```
npm install
npm run start -- <mode> [--path-to-app <path>] [--wasp-cli-cmd <command>]
npm run start -- <mode> [--path-to-app <path>] [--wasp-cli-cmd <command>] [--db-image <image>]
```

`npm run start` runs `npm run build` to build the TypeScript code and then runs the `./bin/index.js` script.
Expand Down
8 changes: 8 additions & 0 deletions wasp-app-runner/src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { Branded } from "./types.js";
export type Mode = "dev" | "build";
export type PathToApp = Branded<string, "PathToApp">;
export type WaspCliCmd = Branded<string, "WaspCliCmd">;
export type DockerImageName = Branded<string, "DockerImageName">;

export function parseArgs(): {
mode: Mode;
pathToApp: PathToApp;
waspCliCmd: WaspCliCmd;
dbImage: DockerImageName;
} {
const parsedProgram = program
.name("run-wasp-app")
Expand All @@ -22,6 +24,11 @@ export function parseArgs(): {
)
.option("--path-to-app <path>", "Path to the Wasp application", ".")
.option("--wasp-cli-cmd <command>", "Wasp CLI command to use", "wasp")
.option(
"--db-image <image>",
"Custom PostgreSQL Docker image to use",
"postgres:16",
)
.parse();

const options = parsedProgram.opts();
Expand All @@ -31,5 +38,6 @@ export function parseArgs(): {
mode,
pathToApp: options.pathToApp as PathToApp,
waspCliCmd: options.waspCliCmd as WaspCliCmd,
dbImage: options.dbImage as DockerImageName,
};
}
5 changes: 4 additions & 1 deletion wasp-app-runner/src/build/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PathToApp, WaspCliCmd } from "../args.js";
import type { DockerImageName, PathToApp, WaspCliCmd } from "../args.js";
import { DbType, setupDb } from "../db/index.js";
import { startLocalSmtpServer } from "../smtp.js";
import { type AppName, waspBuild } from "../waspCli.js";
Expand All @@ -11,11 +11,13 @@ export async function startAppInBuildMode({
pathToApp,
appName,
dbType,
dbImage,
}: {
waspCliCmd: WaspCliCmd;
pathToApp: PathToApp;
appName: AppName;
dbType: DbType;
dbImage: DockerImageName;
}) {
await waspBuild({
waspCliCmd,
Expand All @@ -26,6 +28,7 @@ export async function startAppInBuildMode({
appName,
dbType,
pathToApp,
dbImage,
});

await startLocalSmtpServer();
Expand Down
12 changes: 7 additions & 5 deletions wasp-app-runner/src/db/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { PathToApp } from "../args.js";
import type { DockerImageName, PathToApp } from "../args.js";
import type { AppName } from "../waspCli.js";
import { setupPostgres } from "./postgres.js";
import { setupSqlite } from "./sqlite.js";
import type { SetupDbFn } from "./types.js";
import type { SetupDbResult } from "./types.js";

export enum DbType {
Sqlite = "sqlite",
Expand All @@ -13,16 +13,18 @@ export function setupDb({
appName,
dbType,
pathToApp,
dbImage,
}: {
dbType: DbType;
appName: AppName;
pathToApp: PathToApp;
}): ReturnType<SetupDbFn> {
dbImage: DockerImageName;
}): Promise<SetupDbResult> {
switch (dbType) {
case DbType.Sqlite:
return setupSqlite({ appName, pathToApp });
return setupSqlite();
case DbType.Postgres:
return setupPostgres({ appName, pathToApp });
return setupPostgres({ appName, pathToApp, dbImage });
default:
dbType satisfies never;
throw new Error(`Unknown database type: ${dbType}`);
Expand Down
29 changes: 21 additions & 8 deletions wasp-app-runner/src/db/postgres.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PathToApp } from "../args.js";
import type { DockerImageName, PathToApp } from "../args.js";
import {
DbContainerName,
createAppSpecificDbContainerName,
Expand All @@ -7,18 +7,27 @@ import { createLogger } from "../logging.js";
import { spawnAndCollectOutput } from "../process.js";
import { Branded } from "../types.js";
import type { AppName } from "../waspCli.js";
import type { SetupDbFn } from "./types.js";
import type { SetupDbResult } from "./types.js";

type DatabaseConnectionUrl = Branded<string, "DatabaseConnectionUrl">;

const logger = createLogger("postgres");

export const setupPostgres: SetupDbFn = async ({ appName, pathToApp }) => {
export const setupPostgres = async ({
appName,
pathToApp,
dbImage,
}: {
appName: AppName;
pathToApp: PathToApp;
dbImage: DockerImageName;
}): Promise<SetupDbResult> => {
await ensureDockerIsRunning();

const databaseUrl = await startPostgresContainerForApp({
appName,
pathToApp,
dbImage,
});

logger.info(`Using DATABASE_URL: ${databaseUrl}`);
Expand All @@ -31,9 +40,11 @@ export const setupPostgres: SetupDbFn = async ({ appName, pathToApp }) => {
async function startPostgresContainerForApp({
appName,
pathToApp,
dbImage,
}: {
appName: AppName;
pathToApp: PathToApp;
dbImage: DockerImageName;
}): Promise<DatabaseConnectionUrl> {
const containerName = createAppSpecificDbContainerName({
appName,
Expand All @@ -42,20 +53,22 @@ async function startPostgresContainerForApp({

logger.info(`Using container name: ${containerName}`);

const databaseUrl =
await startPostgresContainerAndWaitUntilReady(containerName);
const databaseUrl = await startPostgresContainerAndWaitUntilReady(
containerName,
dbImage,
);

return databaseUrl;
}

async function startPostgresContainerAndWaitUntilReady(
containerName: DbContainerName,
dbImage: DockerImageName,
): Promise<DatabaseConnectionUrl> {
const port = 5432;
const password = "devpass";
const image = "postgres:16";

logger.info("Starting the PostgreSQL container...");
logger.info(`Starting the PostgreSQL container with image: ${dbImage}...`);

spawnAndCollectOutput({
name: "create-postgres-container",
Expand All @@ -69,7 +82,7 @@ async function startPostgresContainerAndWaitUntilReady(
"-e",
`POSTGRES_PASSWORD=${password}`,
`--rm`,
image,
dbImage,
],
})
// If we awaited here, we would block the main thread indefinitely.
Expand Down
4 changes: 2 additions & 2 deletions wasp-app-runner/src/db/sqlite.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { SetupDbFn } from "./types.js";
import type { SetupDbResult } from "./types.js";

export const setupSqlite: SetupDbFn = async (_options) => {
export const setupSqlite = async (): Promise<SetupDbResult> => {
// No need to do anything special for SQLite, just return
// an empty object for the env vars.
return {
Expand Down
14 changes: 5 additions & 9 deletions wasp-app-runner/src/db/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type { PathToApp } from "../args.js";
import type { AppName } from "../waspCli.js";

export type SetupDbFn = (options: {
appName: AppName;
pathToApp: PathToApp;
}) => Promise<{
dbEnvVars: { [envVarName: string]: string };
}>;
export type SetupDbResult = {
dbEnvVars: {
[envVarName: string]: string;
};
};
5 changes: 4 additions & 1 deletion wasp-app-runner/src/dev/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PathToApp, WaspCliCmd } from "../args.js";
import type { DockerImageName, PathToApp, WaspCliCmd } from "../args.js";
import { DbType, setupDb } from "../db/index.js";
import { type AppName, waspMigrateDb, waspStart } from "../waspCli.js";

Expand All @@ -7,16 +7,19 @@ export async function startAppInDevMode({
pathToApp,
appName,
dbType,
dbImage,
}: {
waspCliCmd: WaspCliCmd;
pathToApp: PathToApp;
appName: AppName;
dbType: DbType;
dbImage: DockerImageName;
}): Promise<void> {
const { dbEnvVars } = await setupDb({
appName,
dbType,
pathToApp,
dbImage,
});

await waspMigrateDb({
Expand Down
15 changes: 13 additions & 2 deletions wasp-app-runner/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { readdir } from "fs/promises";
import { type Mode, parseArgs, PathToApp, WaspCliCmd } from "./args.js";
import {
parseArgs,
type DockerImageName,
type Mode,
type PathToApp,
type WaspCliCmd,
} from "./args.js";
import { startAppInBuildMode } from "./build/index.js";
import { checkDependencies } from "./dependencies.js";
import { startAppInDevMode } from "./dev/index.js";
Expand All @@ -9,13 +15,14 @@ import { waspInfo, waspTsSetup } from "./waspCli.js";
const logger = createLogger("main");

export async function main(): Promise<void> {
const { mode, waspCliCmd, pathToApp } = parseArgs();
const { mode, waspCliCmd, pathToApp, dbImage } = parseArgs();

try {
await runWaspApp({
mode,
waspCliCmd,
pathToApp,
dbImage,
});
} catch (error: unknown) {
if (error instanceof Error) {
Expand All @@ -31,10 +38,12 @@ async function runWaspApp({
mode,
waspCliCmd,
pathToApp,
dbImage,
}: {
mode: Mode;
waspCliCmd: WaspCliCmd;
pathToApp: PathToApp;
dbImage: DockerImageName;
}): Promise<void> {
await checkDependencies();

Expand All @@ -61,6 +70,7 @@ async function runWaspApp({
pathToApp,
appName,
dbType,
dbImage,
});
break;

Expand All @@ -70,6 +80,7 @@ async function runWaspApp({
pathToApp,
appName,
dbType,
dbImage,
});
break;

Expand Down