ref: cleanup service seeder

This commit is contained in:
Jake Turner 2025-07-25 23:22:34 -07:00 committed by Jake Turner
parent d7967d0d74
commit 5fc490715d
2 changed files with 46 additions and 11 deletions

View File

@ -9,6 +9,10 @@ import { inject } from "@adonisjs/core";
@inject()
export class DockerService {
private docker: Docker;
public static KIWIX_SERVICE_NAME = 'nomad_kiwix_serve';
public static OPENSTREETMAP_SERVICE_NAME = 'nomad_openstreetmap';
public static OLLAMA_SERVICE_NAME = 'nomad_ollama';
public static OPEN_WEBUI_SERVICE_NAME = 'nomad_open_webui';
constructor() {
this.docker = new Docker({ socketPath: '/var/run/docker.sock' });
@ -107,10 +111,10 @@ export class DockerService {
this._broadcastAndLog(service.service_name, 'created', `Docker container for service ${service.service_name} created successfully.`);
if (service.service_name === 'kiwix-serve') {
if (service.service_name === DockerService.KIWIX_SERVICE_NAME) {
await this._runPreinstallActions__KiwixServe();
this._broadcastAndLog(service.service_name, 'preinstall-complete', `Pre-install actions for Kiwix Serve completed successfully.`);
} else if (service.service_name === 'openstreetmap') {
} else if (service.service_name === DockerService.OPENSTREETMAP_SERVICE_NAME) {
await this._runPreinstallActions__OpenStreetMap(containerConfig);
this._broadcastAndLog(service.service_name, 'preinstall-complete', `Pre-install actions for OpenStreetMap completed successfully.`);
}

View File

@ -1,48 +1,79 @@
import Service from '#models/service'
import { DockerService } from '#services/docker_service'
import { BaseSeeder } from '@adonisjs/lucid/seeders'
import { ModelAttributes } from '@adonisjs/lucid/types/model'
export default class ServiceSeeder extends BaseSeeder {
private static NOMAD_STORAGE_DIR = '/opt/project-nomad/storage'
private static DEFAULT_SERVICES: Omit<ModelAttributes<Service>, 'created_at' | 'updated_at' | 'metadata' | 'id'>[] = [
{
service_name: 'kiwix-serve',
service_name: DockerService.KIWIX_SERVICE_NAME,
container_image: 'ghcr.io/kiwix/kiwix-serve',
container_command: '*.zim --address=0.0.0.0',
container_config: "{\"HostConfig\":{\"Binds\":[\"/opt/project-nomad/storage/zim:/data\"],\"PortBindings\":{\"8080/tcp\":[{\"HostPort\":\"8090\"}]}},\"ExposedPorts\":{\"8080/tcp\":{}}}",
container_config: JSON.stringify({
HostConfig: {
RestartPolicy: { Name: 'unless-stopped' },
Binds: [`${ServiceSeeder.NOMAD_STORAGE_DIR}/zim:/data`],
PortBindings: { '8080/tcp': [{ HostPort: '8090' }] }
},
ExposedPorts: { '8080/tcp': {} }
}),
ui_location: '8090',
installed: false,
is_dependency_service: false,
depends_on: null,
},
{
service_name: 'openstreetmap',
service_name: DockerService.OPENSTREETMAP_SERVICE_NAME,
container_image: 'overv/openstreetmap-tile-server',
container_command: 'run --shm-size="192m"',
container_config: "{\"HostConfig\":{\"Binds\":[\"/opt/project-nomad/storage/osm/db:/data/database\",\"/opt/project-nomad/storage/osm/tiles:/data/tiles\"],\"PortBindings\":{\"80/tcp\":[{\"HostPort\":\"9000\"}]}}}",
container_config: JSON.stringify({
HostConfig: {
RestartPolicy: { Name: 'unless-stopped' },
Binds: [
`${ServiceSeeder.NOMAD_STORAGE_DIR}/osm/db:/data/database`,
`${ServiceSeeder.NOMAD_STORAGE_DIR}/osm/tiles:/data/tiles`
],
PortBindings: { '80/tcp': [{ HostPort: '9000' }] }
}
}),
ui_location: '9000',
installed: false,
is_dependency_service: false,
depends_on: null,
},
{
service_name: 'ollama',
service_name: DockerService.OLLAMA_SERVICE_NAME,
container_image: 'ollama/ollama:latest',
container_command: 'serve',
container_config: "{\"HostConfig\":{\"Binds\":[\"/opt/project-nomad/storage/ollama:/root/.ollama\"],\"PortBindings\":{\"11434/tcp\":[{\"HostPort\":\"11434\"}]}}, \"ExposedPorts\":{\"11434/tcp\":{}}}",
container_config: JSON.stringify({
HostConfig: {
RestartPolicy: { Name: 'unless-stopped' },
Binds: [`${ServiceSeeder.NOMAD_STORAGE_DIR}/ollama:/root/.ollama`],
PortBindings: { '11434/tcp': [{ HostPort: '11434' }] }
},
ExposedPorts: { '11434/tcp': {} }
}),
ui_location: null,
installed: false,
is_dependency_service: true,
depends_on: null,
},
{
service_name: 'open-webui',
service_name: DockerService.OPEN_WEBUI_SERVICE_NAME,
container_image: 'ghcr.io/open-webui/open-webui:main',
container_command: null,
container_config: "{\"HostConfig\":{\"NetworkMode\":\"host\",\"Binds\":[\"/opt/project-nomad/storage/open-webui:/app/backend/data\"]}}",
container_config: JSON.stringify({
HostConfig: {
RestartPolicy: { Name: 'unless-stopped' },
NetworkMode: 'host',
Binds: [`${ServiceSeeder.NOMAD_STORAGE_DIR}/open-webui:/app/backend/data`]
}
}),
ui_location: '3000',
installed: false,
is_dependency_service: false,
depends_on: 'ollama',
depends_on: DockerService.OLLAMA_SERVICE_NAME,
},
]