fix: cache images so docker-compose can work offline

This commit is contained in:
Arseniy Klempner 2025-10-09 20:05:07 -07:00
parent 0736926e37
commit 3c8cdebc18
No known key found for this signature in database
GPG Key ID: 51653F18863BD24B
2 changed files with 38 additions and 0 deletions

View File

@ -9,6 +9,7 @@ x-pg-environment: &pg_env
# Shared nwaku configuration
x-nwaku-base: &nwaku-base
image: ${NWAKU_IMAGE:-wakuorg/nwaku:v0.36.0}
pull_policy: if_not_present
restart: on-failure
logging:
driver: json-file
@ -19,6 +20,7 @@ x-nwaku-base: &nwaku-base
services:
postgres:
image: postgres:15.4-alpine3.18
pull_policy: if_not_present
restart: on-failure
environment:
<<: *pg_env

View File

@ -25,6 +25,39 @@ const colors: Colors = {
yellow: "\x1b[33m"
};
function checkAndPullImages(): void {
const nwakuImage = process.env.NWAKU_IMAGE || "wakuorg/nwaku:v0.36.0";
const postgresImage = "postgres:15.4-alpine3.18";
const images = [
{ name: nwakuImage, label: "nwaku" },
{ name: postgresImage, label: "postgres" }
];
for (const { name, label } of images) {
try {
// Check if image exists locally
const imageId = execSync(`docker images -q ${name}`, {
encoding: "utf-8"
}).trim();
if (!imageId) {
// Image doesn't exist, pull it
process.stdout.write(
`${colors.cyan}Pulling ${label} image (${name})...${colors.reset}\n`
);
execSync(`docker pull ${name}`, { stdio: "inherit" });
process.stdout.write(
`${colors.green}${colors.reset} ${label} image ready\n`
);
}
} catch (error) {
process.stderr.write(
`${colors.yellow}${colors.reset} Failed to check/pull ${label} image. Continuing anyway...\n`
);
}
}
}
async function waitWithProgress(ms: number): Promise<void> {
const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
const startTime = Date.now();
@ -55,6 +88,9 @@ process.stdout.write(
);
try {
// Check and pull images if needed
checkAndPullImages();
// Start docker compose quietly
execSync("docker compose up -d", {
stdio: ["ignore", "ignore", "pipe"],