hey, currently wondering what the current pattern is for sharing a database service between containers; i have 3 services, a db service that starts, a migration service that runs migrations against it, and a app service that starts to run tests.
it seems that when the app service starts, the db service has not yet run it's migrations. wondering if the db service is detatching after the migration service runs, (and is starting a new instance when the app service starts)
here's basically what i'm trying to do; the application container complains that the tables are not present (created by the pulumiContainer)
import { connect } from "@dagger.io/dagger";
import { fileURLToPath } from "url";
import { exec } from "child_process";
import { promisify } from "util";
import * as path from "path";
const run = promisify(exec);
const dbBase = "amazon/dynamodb-local";
const dbHost = "db";
const dbPort = 8000;
const registry = "XXXXX";
const buildBase = `XXXXX`;
const userName = "AWS";
type Entry = [string, string];
// const file = __filename;
connect(
async (client) => {
const loginCmd = "aws ecr get-login-password --region us-east-2";
const cmd = await run(loginCmd, {});
const password = client.setSecret("ecr-pass", cmd.stdout);
// db container
let dbContainer = client
.container()
.from(dbBase)
.withExposedPort(dbPort)
.asService();
// pulumi container
// using .env var for now
let envVars: Array<Entry> = [
["CACHEBUSTER", new Date().toString()],
["PULUMI_CONFIG_PASSPHRASE", ""],
["DYNAMO_DB_ENDPOINT", `http://${dbHost}:8000/`],
["AWS_DEFAULT_REGION", "us-east-2"],
["AWS_ACCESS_KEY_ID", "fakepulumi"],
["AWS_SECRET_ACCESS_KEY", "fakepulumikey"],
];
let commands: Array<string> = [
'echo "PULUMI APPLY START"',
"npm install",
'aws configure set region "us-east-2"',
'mkdir .pulumi.state',
"pulumi login --local",
"pulumi stack init local",
"pulumi up -r -y",
`AWS_REGION=us-east-2 aws dynamodb list-tables --endpoint-url http://${dbHost}:8000`,
];
let pulumiContainer = client
.container()
.withRegistryAuth(registry, userName, password)
.from(buildBase)
.withWorkdir("/app")
.withServiceBinding(dbHost, dbContainer);
envVars.forEach(([name, value]) => {
pulumiContainer = pulumiContainer.withEnvVariable(name, value);
});
commands.forEach((cmd) => {
pulumiContainer = pulumiContainer.withExec(["bash", "-c", cmd]);
});
// lambda
const lambdaFolder = path.resolve(path.dirname(file), "../../");
const dir = client.host().directory(lambdaFolder);
let container = client
.container()
.build(dir)
.withServiceBinding(dbHost, dbContainer);
await pulumiContainer.stderr();
// using .env var for now
envVars = [
["CACHEBUSTER", new Date().toString()],
["DYNAMO_DB_ENDPOINT", `http://${dbHost}:8000/`],
["AWS_DEFAULT_REGION", "us-east-2"],
["AWS_ACCESS_KEY_ID", "fakerunner"],
["AWS_SECRET_ACCESS_KEY", "fakerunnerkey"],
];
commands = [
`AWS_REGION=us-east-2 aws dynamodb list-tables --endpoint-url http://${dbHost}:8000`,
"cargo run",
];
envVars.forEach(([name, value]) => {
container = container.withEnvVariable(name, value);
});
commands.forEach((cmd) => {
container = container.withExec(["bash", "-c", cmd]);
});
await container.stderr();
},
{ LogOutput: process.stdout }
);