diff --git a/admin/app/services/docker_service.ts b/admin/app/services/docker_service.ts index d332fc3..fbfa4ac 100644 --- a/admin/app/services/docker_service.ts +++ b/admin/app/services/docker_service.ts @@ -16,7 +16,7 @@ export class DockerService { public static CYBERCHEF_SERVICE_NAME = 'nomad_cyberchef' public static FLATNOTES_SERVICE_NAME = 'nomad_flatnotes' public static KOLIBRI_SERVICE_NAME = 'nomad_kolibri' - public static NOMAD_STORAGE_ABS_PATH = '/opt/project-nomad/storage' + public static NOMAD_STORAGE_PATH = '/storage' constructor() { this.docker = new Docker({ socketPath: '/var/run/docker.sock' }) @@ -167,7 +167,7 @@ export class DockerService { // } const containerConfig = this._parseContainerConfig(service.container_config) - this._createContainer(service, containerConfig) // Don't await this method - we will use server-sent events to notify the client of progress + await this._createContainer(service, containerConfig) return { success: true, @@ -178,8 +178,7 @@ export class DockerService { /** * Handles the long-running process of creating a Docker container for a service. * NOTE: This method should not be called directly. Instead, use `createContainerPreflight` to check prerequisites first - * and return an HTTP response to the client, if needed. This method will then transmit server-sent events to the client - * to notify them of the progress. + * This method will also transmit server-sent events to the client to notify of progress. * @param serviceName * @returns */ @@ -332,7 +331,7 @@ export class DockerService { const WIKIPEDIA_ZIM_URL = 'https://github.com/Crosstalk-Solutions/project-nomad/raw/refs/heads/master/install/wikipedia_en_100_mini_2025-06.zim' const zimPath = '/zim/wikipedia_en_100_mini_2025-06.zim' - const filepath = path.join(DockerService.NOMAD_STORAGE_ABS_PATH, zimPath) + const filepath = path.join(process.cwd(), DockerService.NOMAD_STORAGE_PATH, zimPath) logger.info(`[DockerService] Kiwix Serve pre-install: Downloading ZIM file to ${filepath}`) this._broadcast( diff --git a/admin/app/utils/downloads.ts b/admin/app/utils/downloads.ts index d8fb0d4..7c36378 100644 --- a/admin/app/utils/downloads.ts +++ b/admin/app/utils/downloads.ts @@ -1,74 +1,13 @@ import { DoResumableDownloadParams, DoResumableDownloadWithRetryParams, - DoSimpleDownloadParams, } from '../../types/downloads.js' -import axios, { AxiosResponse } from 'axios' +import axios from 'axios' import { Transform } from 'stream' import { deleteFileIfExists, ensureDirectoryExists, getFileStatsIfExists } from './fs.js' import { createWriteStream } from 'fs' -import logger from '@adonisjs/core/services/logger' import path from 'path' -export async function doSimpleDownload({ - url, - filepath, - timeout = 30000, - signal, -}: DoSimpleDownloadParams): Promise { - return new Promise(async (resolve, reject) => { - let response: AxiosResponse | undefined - let writer: ReturnType | undefined - - const cleanup = (err?: Error) => { - try { - response?.data?.destroy?.() - } catch {} - try { - writer?.destroy?.() - } catch {} - if (err) { - try { - logger.error(`Download failed for ${url}: ${err.message}`) - } catch {} - reject(err) - } - } - - try { - const dirname = path.dirname(filepath) - await ensureDirectoryExists(dirname) - - response = await axios.get(url, { - responseType: 'stream', - signal, - timeout, - }) - - writer = createWriteStream(filepath) - response?.data.pipe(writer) - - response?.data.on('error', cleanup) - writer?.on('error', cleanup) - - writer?.on('finish', () => { - cleanup() - resolve(filepath) - }) - - signal?.addEventListener( - 'abort', - () => { - cleanup(new Error('Download aborted')) - }, - { once: true } - ) - } catch (error) { - cleanup(error as Error) - } - }) -} - /** * Perform a resumable download with progress tracking * @param param0 - Download parameters. Leave allowedMimeTypes empty to skip mime type checking. diff --git a/admin/database/seeders/service_seeder.ts b/admin/database/seeders/service_seeder.ts index ed30993..71f7161 100644 --- a/admin/database/seeders/service_seeder.ts +++ b/admin/database/seeders/service_seeder.ts @@ -4,17 +4,18 @@ import { BaseSeeder } from '@adonisjs/lucid/seeders' import { ModelAttributes } from '@adonisjs/lucid/types/model' export default class ServiceSeeder extends BaseSeeder { + private static NOMAD_STORAGE_ABS_PATH = '/opt/project-nomad/storage' private static DEFAULT_SERVICES: Omit, 'created_at' | 'updated_at' | 'metadata' | 'id'>[] = [ { service_name: DockerService.KIWIX_SERVICE_NAME, friendly_name: 'Kiwix', description: 'Offline Wikipedia, eBooks, and more', - container_image: 'ghcr.io/kiwix/kiwix-serve', - container_command: '*.zim --address=0.0.0.0', + container_image: 'ghcr.io/kiwix/kiwix-serve:3.8.1', + container_command: '*.zim --address=all', container_config: JSON.stringify({ HostConfig: { RestartPolicy: { Name: 'unless-stopped' }, - Binds: [`${DockerService.NOMAD_STORAGE_ABS_PATH}/zim:/data`], + Binds: [`${ServiceSeeder.NOMAD_STORAGE_ABS_PATH}/zim:/data`], PortBindings: { '8080/tcp': [{ HostPort: '8090' }] } }, ExposedPorts: { '8080/tcp': {} } @@ -33,7 +34,7 @@ export default class ServiceSeeder extends BaseSeeder { container_config: JSON.stringify({ HostConfig: { RestartPolicy: { Name: 'unless-stopped' }, - Binds: [`${DockerService.NOMAD_STORAGE_ABS_PATH}/ollama:/root/.ollama`], + Binds: [`${ServiceSeeder.NOMAD_STORAGE_ABS_PATH}/ollama:/root/.ollama`], PortBindings: { '11434/tcp': [{ HostPort: '11434' }] } }, ExposedPorts: { '11434/tcp': {} } @@ -53,7 +54,7 @@ export default class ServiceSeeder extends BaseSeeder { HostConfig: { RestartPolicy: { Name: 'unless-stopped' }, NetworkMode: 'host', - Binds: [`${DockerService.NOMAD_STORAGE_ABS_PATH}/open-webui:/app/backend/data`] + Binds: [`${ServiceSeeder.NOMAD_STORAGE_ABS_PATH}/open-webui:/app/backend/data`] }, Env: ['WEBUI_AUTH=False', 'PORT=3000', 'OLLAMA_BASE_URL=http://127.0.0.1:11434'] }), @@ -90,7 +91,7 @@ export default class ServiceSeeder extends BaseSeeder { HostConfig: { RestartPolicy: { Name: 'unless-stopped' }, PortBindings: { '8080/tcp': [{ HostPort: '8200' }] }, - Binds: [`${DockerService.NOMAD_STORAGE_ABS_PATH}/flatnotes:/data`] + Binds: [`${ServiceSeeder.NOMAD_STORAGE_ABS_PATH}/flatnotes:/data`] }, ExposedPorts: { '8080/tcp': {} }, Env: ['FLATNOTES_AUTH_TYPE=none'] @@ -110,7 +111,7 @@ export default class ServiceSeeder extends BaseSeeder { HostConfig: { RestartPolicy: { Name: 'unless-stopped' }, PortBindings: { '8080/tcp': [{ HostPort: '8300' }] }, - Binds: [`${DockerService.NOMAD_STORAGE_ABS_PATH}/kolibri:/root/.kolibri`] + Binds: [`${ServiceSeeder.NOMAD_STORAGE_ABS_PATH}/kolibri:/root/.kolibri`] }, ExposedPorts: { '8080/tcp': {} }, }), diff --git a/admin/types/downloads.ts b/admin/types/downloads.ts index 52637a2..043a787 100644 --- a/admin/types/downloads.ts +++ b/admin/types/downloads.ts @@ -1,10 +1,3 @@ -export type DoSimpleDownloadParams = { - url: string - filepath: string - timeout: number - signal?: AbortSignal -} - export type DoResumableDownloadParams = { url: string filepath: string diff --git a/install/management_compose.yaml b/install/management_compose.yaml index e66d05a..a65cd75 100644 --- a/install/management_compose.yaml +++ b/install/management_compose.yaml @@ -1,7 +1,6 @@ services: admin: image: ghcr.io/crosstalk-solutions/project-nomad:latest - pull_policy: always container_name: nomad_admin restart: unless-stopped ports: @@ -25,7 +24,7 @@ services: - DB_PASSWORD=replaceme - DB_NAME=nomad - DB_SSL=false - - REDIS_HOST=localhost + - REDIS_HOST=redis - REDIS_PORT=6379 depends_on: mysql: