Project NOMAD is an offline-first knowledge and education server. Wikipedia, thousands of books, courses, maps, and optional local AI, all running on hardware you own with no internet required.
TypeScript
feat: version footer and fix CI version handlng
Jake Turner7acfd33d5c77
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.ymlindex 00aac1e4..fe9e5527 100644--- a/.github/workflows/docker.yml+++ b/.github/workflows/docker.yml@@ -9,22 +9,6 @@ on:type: stringjobs:- debug:- name: Debugging information- runs-on: ubuntu-latest- steps:- - name: Checkout code- uses: actions/checkout@v4- - name: List repository root contents- run: |- echo "Repository root contents:"- ls -la- echo "Looking for admin directory:"- ls -la admin/ || echo "admin directory not found"- - name: Print GitHub context- run: echo "${{ toJson(github) }}"- - name: Print workflow inputs- run: echo "${{ toJson(inputs) }}"check_authorization:name: Check authorization to publish new Docker imageruns-on: ubuntu-latest@@ -54,9 +38,7 @@ jobs:- name: Build and pushuses: docker/build-push-action@v5with:- context: ./admin- file: ./admin/Dockerfilepush: truetags: |- ghcr.io/crosstalk-solutions/project-nomad-admin:${{ inputs.version }}- ghcr.io/crosstalk-solutions/project-nomad-admin:latest+ ghcr.io/crosstalk-solutions/project-nomad:${{ inputs.version }}+ ghcr.io/crosstalk-solutions/project-nomad:latestdiff --git a/admin/Dockerfile b/Dockerfilesimilarity index 69%rename from admin/Dockerfilerename to Dockerfileindex c9929043..3e77d9d0 100644--- a/admin/Dockerfile+++ b/Dockerfile@@ -6,20 +6,20 @@ RUN apk add --no-cache bash curl# All deps stageFROM base AS depsWORKDIR /app-ADD package.json package-lock.json ./+ADD admin/package.json admin/package-lock.json ./RUN npm ci# Production only deps stageFROM base AS production-depsWORKDIR /app-ADD package.json package-lock.json ./+ADD admin/package.json admin/package-lock.json ./RUN npm ci --omit=dev# Build stageFROM base AS buildWORKDIR /appCOPY --from=deps /app/node_modules /app/node_modules-ADD . .+ADD admin/ ./RUN node ace build# Production stage@@ -28,6 +28,8 @@ ENV NODE_ENV=productionWORKDIR /appCOPY --from=production-deps /app/node_modules /app/node_modulesCOPY --from=build /app/build /app-COPY ./docs /app/docs+# Copy root package.json for version info+COPY package.json /app/version.json+COPY admin/docs /app/docsEXPOSE 8080CMD ["node", "./bin/server.js"]\ No newline at end of filediff --git a/README.md b/README.mdindex 0c1e08b7..49a08aa7 100644--- a/README.md+++ b/README.md@@ -63,7 +63,12 @@ To test internet connectivity, N.O.M.A.D. attempts to make a request to Cloudfla## About SecurityBy design, Project N.O.M.A.D. is intended to be open and available without hurdles - it includes no authentication. If you decide to connect your device to a local network after install (e.g. for allowing other devices to access it's resources), you can block/open ports to control which services are exposed.-# Helper Scripts+## Versioning+This project uses semantic versioning. The version is managed in the root `package.json`+and automatically updated by semantic-release. For simplicity's sake, the "project-nomad" container+uses the same version defined there instead of the version in `admin/package.json` (stays at 0.0.0), as it's the only container derived from the code.++## Helper ScriptsOnce installed, Project N.O.M.A.D. has a few helper scripts should you ever need to troubleshoot issues or perform maintenance that can't be done through the Command Center. All of these scripts are found in Project N.O.M.A.D.'s install directory, `/opt/project-nomad`###diff --git a/admin/app/services/system_service.ts b/admin/app/services/system_service.tsindex f18bd3fa..2cc5e573 100644--- a/admin/app/services/system_service.ts+++ b/admin/app/services/system_service.ts@@ -1,37 +1,39 @@-import Service from "#models/service"-import { inject } from "@adonisjs/core";-import { DockerService } from "#services/docker_service";-import { ServiceSlim } from "../../types/services.js";-import logger from "@adonisjs/core/services/logger";-import si from 'systeminformation';-import { SystemInformationResponse } from "../../types/system.js";+import Service from '#models/service'+import { inject } from '@adonisjs/core'+import { DockerService } from '#services/docker_service'+import { ServiceSlim } from '../../types/services.js'+import logger from '@adonisjs/core/services/logger'+import si from 'systeminformation'+import { SystemInformationResponse } from '../../types/system.js'+import { readFileSync } from 'fs'+import { join } from 'path'@inject()export class SystemService {- constructor(- private dockerService: DockerService- ) { }- async getServices({- installedOnly = true,- }: {- installedOnly?: boolean- }): Promise<ServiceSlim[]> {- const query = Service.query().orderBy('friendly_name', 'asc').select('id', 'service_name', 'installed', 'ui_location', 'friendly_name', 'description').where('is_dependency_service', false)+ private static appVersion: string | null = null++ constructor(private dockerService: DockerService) {}++ async getServices({ installedOnly = true }: { installedOnly?: boolean }): Promise<ServiceSlim[]> {+ const query = Service.query()+ .orderBy('friendly_name', 'asc')+ .select('id', 'service_name', 'installed', 'ui_location', 'friendly_name', 'description')+ .where('is_dependency_service', false)if (installedOnly) {- query.where('installed', true);+ query.where('installed', true)}- const services = await query;+ const services = await queryif (!services || services.length === 0) {- return [];+ return []}- const statuses = await this.dockerService.getServicesStatus();+ const statuses = await this.dockerService.getServicesStatus()- const toReturn: ServiceSlim[] = [];+ const toReturn: ServiceSlim[] = []for (const service of services) {- const status = statuses.find(s => s.service_name === service.service_name);+ const status = statuses.find((s) => s.service_name === service.service_name)toReturn.push({id: service.id,service_name: service.service_name,@@ -39,12 +41,36 @@ export class SystemService {description: service.description,installed: service.installed,status: status ? status.status : 'unknown',- ui_location: service.ui_location || ''- });+ ui_location: service.ui_location || '',+ })}- return toReturn;+ return toReturn+ }++ static getAppVersion(): string {+ try {+ if (this.appVersion) {+ return this.appVersion+ }++ // Return 'dev' for development environment (version.json won't exist)+ if (process.env.NODE_ENV === 'development') {+ this.appVersion = 'dev'+ return 'dev'+ }++ const packageJson = readFileSync(join(process.cwd(), 'version.json'), 'utf-8')+ const packageData = JSON.parse(packageJson)++ const version = packageData.version || '0.0.0'+ this.appVersion = version+ return version+ } catch (error) {+ logger.error('Error getting app version:', error)+ return '0.0.0'+ }}async getSystemInfo(): Promise<SystemInformationResponse | undefined> {@@ -53,18 +79,18 @@ export class SystemService {si.cpu(),si.mem(),si.osInfo(),- si.diskLayout()- ]);;+ si.diskLayout(),+ ])return {cpu,mem,os,- disk- };+ disk,+ }} catch (error) {- logger.error('Error getting system info:', error);- return undefined;+ logger.error('Error getting system info:', error)+ return undefined}}-}\ No newline at end of file+}diff --git a/admin/config/inertia.ts b/admin/config/inertia.tsindex 55ae6c7d..2bedb922 100644--- a/admin/config/inertia.ts+++ b/admin/config/inertia.ts@@ -1,3 +1,4 @@+import { SystemService } from '#services/system_service'import { defineConfig } from '@adonisjs/inertia'import type { InferSharedProps } from '@adonisjs/inertia/types'@@ -11,7 +12,7 @@ const inertiaConfig = defineConfig({* Data that should be shared with all rendered pages*/sharedData: {- // user: (ctx) => ctx.inertia.always(() => ctx.auth.user),+ appVersion: () => SystemService.getAppVersion(),},/**diff --git a/admin/inertia/components/Footer.tsx b/admin/inertia/components/Footer.tsxnew file mode 100644index 00000000..0ed85078--- /dev/null+++ b/admin/inertia/components/Footer.tsx@@ -0,0 +1,14 @@+import { usePage } from '@inertiajs/react'++export default function Footer() {+ const { appVersion } = usePage().props as unknown as { appVersion: string }+ return (+ <footer className="">+ <div className="flex justify-center border-t border-gray-900/10 py-4">+ <p className="text-sm/6 text-gray-600">+ Project N.O.M.A.D. Command Center v{appVersion}+ </p>+ </div>+ </footer>+ )+}diff --git a/admin/inertia/components/StyledSidebar.tsx b/admin/inertia/components/StyledSidebar.tsxindex f15ed9d8..23bae9fe 100644--- a/admin/inertia/components/StyledSidebar.tsx+++ b/admin/inertia/components/StyledSidebar.tsx@@ -3,6 +3,8 @@ import { Dialog, DialogBackdrop, DialogPanel, TransitionChild } from '@headlessuimport { Bars3Icon, XMarkIcon } from '@heroicons/react/24/outline'import classNames from '~/lib/classNames'import { IconArrowLeft } from '@tabler/icons-react'+import { usePage } from '@inertiajs/react'+import { UsePageProps } from '../../types/system'type SidebarItem = {name: string@@ -19,6 +21,7 @@ interface StyledSidebarProps {const StyledSidebar: React.FC<StyledSidebarProps> = ({ title, items }) => {const [sidebarOpen, setSidebarOpen] = useState(false)+ const { appVersion } = usePage().props as unknown as UsePagePropsconst currentPath = useMemo(() => {if (typeof window === 'undefined') return ''@@ -72,6 +75,9 @@ const StyledSidebar: React.FC<StyledSidebarProps> = ({ title, items }) => {</li></ul></nav>+ <div className="mb-4 text-center text-sm text-gray-600">+ <p>Project N.O.M.A.D. Command Center v{appVersion}</p>+ </div></div>)}diff --git a/admin/inertia/css/app.css b/admin/inertia/css/app.cssindex 9907589d..ff456f0c 100644--- a/admin/inertia/css/app.css+++ b/admin/inertia/css/app.css@@ -5,7 +5,8 @@--color-desert-green-light: #babaaa;--color-desert-green: #424420;--color-desert-orange: #a84a12;- --color-desert-sand: #f7eedc+ --color-desert-sand: #f7eedc;+ /* --color-desert-sand: #E2DAC2; */}body {diff --git a/admin/inertia/layouts/AppLayout.tsx b/admin/inertia/layouts/AppLayout.tsxindex ecb6da3f..86117d31 100644--- a/admin/inertia/layouts/AppLayout.tsx+++ b/admin/inertia/layouts/AppLayout.tsx@@ -1,3 +1,5 @@+import Footer from "~/components/Footer";+export default function AppLayout({ children }: { children: React.ReactNode }) {return (<div className="min-h-screen flex flex-col">@@ -17,6 +19,7 @@ export default function AppLayout({ children }: { children: React.ReactNode }) {className="text-desert-orange font-semibold text-sm italic">A project by Crosstalk Solutions</p></div> */}+ <Footer /></div>)}diff --git a/admin/inertia/layouts/SettingsLayout.tsx b/admin/inertia/layouts/SettingsLayout.tsxindex ee16e895..1d4c3ef3 100644--- a/admin/inertia/layouts/SettingsLayout.tsx+++ b/admin/inertia/layouts/SettingsLayout.tsx@@ -11,7 +11,13 @@ import { getServiceLink } from '~/lib/navigation'const navigation = [{ name: 'Apps', href: '/settings/apps', icon: CommandLineIcon, current: false },{ name: 'Legal Notices', href: '/settings/legal', icon: IconGavel, current: false },- { name: 'Service Logs & Metrics', href: getServiceLink('9999'), icon: IconDashboard, current: false, target: '_blank' },+ {+ name: 'Service Logs & Metrics',+ href: getServiceLink('9999'),+ icon: IconDashboard,+ current: false,+ target: '_blank',+ },{ name: 'ZIM Manager', href: '/settings/zim', icon: FolderIcon, current: false },{name: 'Zim Remote Explorer',diff --git a/admin/types/system.ts b/admin/types/system.tsindex 6bbf251b..da7d5896 100644--- a/admin/types/system.ts+++ b/admin/types/system.ts@@ -6,4 +6,9 @@ export type SystemInformationResponse = {mem: Systeminformation.MemDataos: Systeminformation.OsDatadisk: Systeminformation.DiskLayoutData[]+}++// Type inferrence is not working properly with usePage and shared props, so we define this type manually+export type UsePageProps = {+ appVersion: string}\ No newline at end of file