mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-04-04 07:46:16 +02:00
fix(Kiwix): initial download and setup
This commit is contained in:
parent
ce8dbd91ab
commit
2ff7b055b5
|
|
@ -16,7 +16,7 @@ export class DockerService {
|
||||||
public static CYBERCHEF_SERVICE_NAME = 'nomad_cyberchef'
|
public static CYBERCHEF_SERVICE_NAME = 'nomad_cyberchef'
|
||||||
public static FLATNOTES_SERVICE_NAME = 'nomad_flatnotes'
|
public static FLATNOTES_SERVICE_NAME = 'nomad_flatnotes'
|
||||||
public static KOLIBRI_SERVICE_NAME = 'nomad_kolibri'
|
public static KOLIBRI_SERVICE_NAME = 'nomad_kolibri'
|
||||||
public static NOMAD_STORAGE_ABS_PATH = '/opt/project-nomad/storage'
|
public static NOMAD_STORAGE_PATH = '/storage'
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.docker = new Docker({ socketPath: '/var/run/docker.sock' })
|
this.docker = new Docker({ socketPath: '/var/run/docker.sock' })
|
||||||
|
|
@ -167,7 +167,7 @@ export class DockerService {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const containerConfig = this._parseContainerConfig(service.container_config)
|
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 {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
|
|
@ -178,8 +178,7 @@ export class DockerService {
|
||||||
/**
|
/**
|
||||||
* Handles the long-running process of creating a Docker container for a service.
|
* 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
|
* 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
|
* This method will also transmit server-sent events to the client to notify of progress.
|
||||||
* to notify them of the progress.
|
|
||||||
* @param serviceName
|
* @param serviceName
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
|
|
@ -332,7 +331,7 @@ export class DockerService {
|
||||||
const WIKIPEDIA_ZIM_URL =
|
const WIKIPEDIA_ZIM_URL =
|
||||||
'https://github.com/Crosstalk-Solutions/project-nomad/raw/refs/heads/master/install/wikipedia_en_100_mini_2025-06.zim'
|
'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 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}`)
|
logger.info(`[DockerService] Kiwix Serve pre-install: Downloading ZIM file to ${filepath}`)
|
||||||
|
|
||||||
this._broadcast(
|
this._broadcast(
|
||||||
|
|
|
||||||
|
|
@ -1,74 +1,13 @@
|
||||||
import {
|
import {
|
||||||
DoResumableDownloadParams,
|
DoResumableDownloadParams,
|
||||||
DoResumableDownloadWithRetryParams,
|
DoResumableDownloadWithRetryParams,
|
||||||
DoSimpleDownloadParams,
|
|
||||||
} from '../../types/downloads.js'
|
} from '../../types/downloads.js'
|
||||||
import axios, { AxiosResponse } from 'axios'
|
import axios from 'axios'
|
||||||
import { Transform } from 'stream'
|
import { Transform } from 'stream'
|
||||||
import { deleteFileIfExists, ensureDirectoryExists, getFileStatsIfExists } from './fs.js'
|
import { deleteFileIfExists, ensureDirectoryExists, getFileStatsIfExists } from './fs.js'
|
||||||
import { createWriteStream } from 'fs'
|
import { createWriteStream } from 'fs'
|
||||||
import logger from '@adonisjs/core/services/logger'
|
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|
||||||
export async function doSimpleDownload({
|
|
||||||
url,
|
|
||||||
filepath,
|
|
||||||
timeout = 30000,
|
|
||||||
signal,
|
|
||||||
}: DoSimpleDownloadParams): Promise<string> {
|
|
||||||
return new Promise(async (resolve, reject) => {
|
|
||||||
let response: AxiosResponse<any> | undefined
|
|
||||||
let writer: ReturnType<typeof createWriteStream> | 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
|
* Perform a resumable download with progress tracking
|
||||||
* @param param0 - Download parameters. Leave allowedMimeTypes empty to skip mime type checking.
|
* @param param0 - Download parameters. Leave allowedMimeTypes empty to skip mime type checking.
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,18 @@ import { BaseSeeder } from '@adonisjs/lucid/seeders'
|
||||||
import { ModelAttributes } from '@adonisjs/lucid/types/model'
|
import { ModelAttributes } from '@adonisjs/lucid/types/model'
|
||||||
|
|
||||||
export default class ServiceSeeder extends BaseSeeder {
|
export default class ServiceSeeder extends BaseSeeder {
|
||||||
|
private static NOMAD_STORAGE_ABS_PATH = '/opt/project-nomad/storage'
|
||||||
private static DEFAULT_SERVICES: Omit<ModelAttributes<Service>, 'created_at' | 'updated_at' | 'metadata' | 'id'>[] = [
|
private static DEFAULT_SERVICES: Omit<ModelAttributes<Service>, 'created_at' | 'updated_at' | 'metadata' | 'id'>[] = [
|
||||||
{
|
{
|
||||||
service_name: DockerService.KIWIX_SERVICE_NAME,
|
service_name: DockerService.KIWIX_SERVICE_NAME,
|
||||||
friendly_name: 'Kiwix',
|
friendly_name: 'Kiwix',
|
||||||
description: 'Offline Wikipedia, eBooks, and more',
|
description: 'Offline Wikipedia, eBooks, and more',
|
||||||
container_image: 'ghcr.io/kiwix/kiwix-serve',
|
container_image: 'ghcr.io/kiwix/kiwix-serve:3.8.1',
|
||||||
container_command: '*.zim --address=0.0.0.0',
|
container_command: '*.zim --address=all',
|
||||||
container_config: JSON.stringify({
|
container_config: JSON.stringify({
|
||||||
HostConfig: {
|
HostConfig: {
|
||||||
RestartPolicy: { Name: 'unless-stopped' },
|
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' }] }
|
PortBindings: { '8080/tcp': [{ HostPort: '8090' }] }
|
||||||
},
|
},
|
||||||
ExposedPorts: { '8080/tcp': {} }
|
ExposedPorts: { '8080/tcp': {} }
|
||||||
|
|
@ -33,7 +34,7 @@ export default class ServiceSeeder extends BaseSeeder {
|
||||||
container_config: JSON.stringify({
|
container_config: JSON.stringify({
|
||||||
HostConfig: {
|
HostConfig: {
|
||||||
RestartPolicy: { Name: 'unless-stopped' },
|
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' }] }
|
PortBindings: { '11434/tcp': [{ HostPort: '11434' }] }
|
||||||
},
|
},
|
||||||
ExposedPorts: { '11434/tcp': {} }
|
ExposedPorts: { '11434/tcp': {} }
|
||||||
|
|
@ -53,7 +54,7 @@ export default class ServiceSeeder extends BaseSeeder {
|
||||||
HostConfig: {
|
HostConfig: {
|
||||||
RestartPolicy: { Name: 'unless-stopped' },
|
RestartPolicy: { Name: 'unless-stopped' },
|
||||||
NetworkMode: 'host',
|
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']
|
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: {
|
HostConfig: {
|
||||||
RestartPolicy: { Name: 'unless-stopped' },
|
RestartPolicy: { Name: 'unless-stopped' },
|
||||||
PortBindings: { '8080/tcp': [{ HostPort: '8200' }] },
|
PortBindings: { '8080/tcp': [{ HostPort: '8200' }] },
|
||||||
Binds: [`${DockerService.NOMAD_STORAGE_ABS_PATH}/flatnotes:/data`]
|
Binds: [`${ServiceSeeder.NOMAD_STORAGE_ABS_PATH}/flatnotes:/data`]
|
||||||
},
|
},
|
||||||
ExposedPorts: { '8080/tcp': {} },
|
ExposedPorts: { '8080/tcp': {} },
|
||||||
Env: ['FLATNOTES_AUTH_TYPE=none']
|
Env: ['FLATNOTES_AUTH_TYPE=none']
|
||||||
|
|
@ -110,7 +111,7 @@ export default class ServiceSeeder extends BaseSeeder {
|
||||||
HostConfig: {
|
HostConfig: {
|
||||||
RestartPolicy: { Name: 'unless-stopped' },
|
RestartPolicy: { Name: 'unless-stopped' },
|
||||||
PortBindings: { '8080/tcp': [{ HostPort: '8300' }] },
|
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': {} },
|
ExposedPorts: { '8080/tcp': {} },
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,3 @@
|
||||||
export type DoSimpleDownloadParams = {
|
|
||||||
url: string
|
|
||||||
filepath: string
|
|
||||||
timeout: number
|
|
||||||
signal?: AbortSignal
|
|
||||||
}
|
|
||||||
|
|
||||||
export type DoResumableDownloadParams = {
|
export type DoResumableDownloadParams = {
|
||||||
url: string
|
url: string
|
||||||
filepath: string
|
filepath: string
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
services:
|
services:
|
||||||
admin:
|
admin:
|
||||||
image: ghcr.io/crosstalk-solutions/project-nomad:latest
|
image: ghcr.io/crosstalk-solutions/project-nomad:latest
|
||||||
pull_policy: always
|
|
||||||
container_name: nomad_admin
|
container_name: nomad_admin
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
|
|
@ -25,7 +24,7 @@ services:
|
||||||
- DB_PASSWORD=replaceme
|
- DB_PASSWORD=replaceme
|
||||||
- DB_NAME=nomad
|
- DB_NAME=nomad
|
||||||
- DB_SSL=false
|
- DB_SSL=false
|
||||||
- REDIS_HOST=localhost
|
- REDIS_HOST=redis
|
||||||
- REDIS_PORT=6379
|
- REDIS_PORT=6379
|
||||||
depends_on:
|
depends_on:
|
||||||
mysql:
|
mysql:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user