Skip to content

Display Docker Version Details in the Update Information Box #2488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/modules/platform-tools/docker/docker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ export class DockerService {
constructor(
private readonly configService: ConfigService,
private readonly logger: Logger,
) {}
) { }

/**
* Returns the docker startup.sh script
*/
async getStartupScript() {
const script = await readFile(this.configService.startupScript, 'utf-8')
return { script }
try {
const script = await readFile(this.configService.startupScript, 'utf-8')
return { script }
} catch (error) {
this.logger.error('Error reading startup script:', error)
throw new Error('Could not read the startup script.')
}
}

/**
Expand Down
11 changes: 10 additions & 1 deletion src/modules/status/status.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class StatusGateway {
constructor(
private statusService: StatusService,
private pluginsService: PluginsService,
) {}
) { }

@SubscribeMessage('get-dashboard-layout')
async getDashboardLayout() {
Expand Down Expand Up @@ -65,6 +65,15 @@ export class StatusGateway {
}
}

@SubscribeMessage('docker-version-check')
async dockerVersionCheck() {
try {
return await this.statusService.getDockerDetails()
} catch (e) {
return new WsException(e.message)
}
}

@SubscribeMessage('nodejs-version-check')
async nodeJsVersionCheck() {
try {
Expand Down
152 changes: 152 additions & 0 deletions src/modules/status/status.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ export interface HomebridgeStatusUpdate {
pin?: string
}

interface DockerRelease {
tag_name: string
published_at: string
prerelease: boolean
body: string
}

interface DockerReleaseInfo {
version: string
publishedAt: string
isPrerelease: boolean
isTest: boolean
testTag: 'beta' | 'test' | null
isLatestStable: boolean
}

const execAsync = promisify(exec)

@Injectable()
Expand Down Expand Up @@ -592,4 +608,140 @@ export class StatusService {

return output
}

/**
* Fetches Docker package details, including version information, release body, and system details.
* Accounts for version tag formats: YYYY-MM-DD (stable), beta-YYYY-MM-DD or test-YYYY-MM-DD (test).
* If currentVersion is beta/test, latestVersion is the latest beta/test version; otherwise, it's the latest stable.
* @returns A promise resolving to the Docker details object.
*/
public async getDockerDetails() {
const currentVersion = process.env.DOCKER_HOMEBRIDGE_VERSION
let latestVersion: string | null = null
let latestReleaseBody = ''
let updateAvailable = false

try {
const { releases, rawReleases } = await this.getRecentReleases()

// Determine the type of currentVersion and select the appropriate latest version
if (currentVersion) {
const lowerCurrentVersion = currentVersion.toLowerCase()
let targetReleases: DockerReleaseInfo[] = []

if (lowerCurrentVersion.startsWith('beta-')) {
// Current version is beta; select latest beta version
targetReleases = releases
.filter(release => release.testTag === 'beta' && /^beta-\d{4}-\d{2}-\d{2}$/i.test(release.version))
.sort((a, b) => b.version.localeCompare(a.version)) // Sort by date descending
latestVersion = targetReleases[0]?.version || null
} else if (lowerCurrentVersion.startsWith('test-')) {
// Current version is test; select latest test version
targetReleases = releases
.filter(release => release.testTag === 'test' && /^test-\d{4}-\d{2}-\d{2}$/i.test(release.version))
.sort((a, b) => b.version.localeCompare(a.version)) // Sort by date descending
latestVersion = targetReleases[0]?.version || null
} else {
// Current version is stable or invalid; select latest stable version
const stableRelease = releases.find(release => release.isLatestStable)
latestVersion = stableRelease?.version || null
}

if (currentVersion && latestVersion) {
// Compare versions as dates if they match the expected format
const dateRegex = /\d{4}-\d{2}-\d{2}$/
if (dateRegex.test(currentVersion) && dateRegex.test(latestVersion)) {
const currentDate = new Date(currentVersion.match(dateRegex)![0])
const latestDate = new Date(latestVersion.match(dateRegex)![0])
updateAvailable = latestDate > currentDate
} else {
// Fallback to string comparison
updateAvailable = currentVersion !== latestVersion
}
}
} else {
// No currentVersion; default to latest stable
const stableRelease = releases.find(release => release.isLatestStable)
latestVersion = stableRelease?.version || null
}

// Fetch the release body for the latestVersion
if (latestVersion) {
const rawRelease = rawReleases.find(r => r.tag_name === latestVersion)
latestReleaseBody = rawRelease?.body || ''
}
} catch (error) {
console.error('Failed to fetch Docker details:', error instanceof Error ? error.message : error)
}

return {
currentVersion,
latestVersion,
latestReleaseBody,
updateAvailable,
}
}

private readonly DOCKER_GITHUB_API_URL = 'https://api.github.com/repos/homebridge/docker-homebridge/releases'

/**
* Fetches the most recent releases (up to 100) of the homebridge/docker-homebridge package from GitHub,
* tagging test versions (tags starting with 'beta-' or 'test-') and the latest stable version (YYYY-MM-DD format).
* Includes a testTag field for test versions.
* @returns A promise resolving to an object with processed releases and raw release data, or empty arrays if an error occurs.
*/
public async getRecentReleases(): Promise<{ releases: DockerReleaseInfo[], rawReleases: DockerRelease[] }> {
try {
// Fetch the first page of up to 100 releases
const response = await fetch(`${this.DOCKER_GITHUB_API_URL}?per_page=100`, {
headers: {
Accept: 'application/vnd.github.v3+json',
// Optional: Add GitHub token for higher rate limits
// 'Authorization': `Bearer ${process.env.GITHUB_TOKEN}`,
},
})

if (!response.ok) {
console.error(`GitHub API error: ${response.status} ${response.statusText}`)
return { releases: [], rawReleases: [] }
}

const data: DockerRelease[] = await response.json()

if (!Array.isArray(data)) {
console.error('Invalid response from GitHub API: Expected an array')
return { releases: [], rawReleases: [] }
}

// Find the latest stable release by sorting YYYY-MM-DD tags
const stableReleases = data
.filter(release => /^\d{4}-\d{2}-\d{2}$/.test(release.tag_name)) // Stable: YYYY-MM-DD
.sort((a, b) => b.tag_name.localeCompare(a.tag_name)) // Sort descending (most recent first)
const latestStableTag = stableReleases[0]?.tag_name || null

const releases = data.map((release) => {
const tagName = release.tag_name.toLowerCase()
let testTag: 'beta' | 'test' | null = null
if (tagName.startsWith('beta-')) {
testTag = 'beta'
} else if (tagName.startsWith('test-')) {
testTag = 'test'
}

return {
version: release.tag_name,
publishedAt: release.published_at,
isPrerelease: release.prerelease,
isTest: testTag !== null,
testTag,
isLatestStable: release.tag_name === latestStableTag,
}
})

return { releases, rawReleases: data }
} catch (error) {
console.error('Failed to fetch docker-homebridge releases:', error instanceof Error ? error.message : error)
return { releases: [], rawReleases: [] }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ <h5 class="mb-3" [innerHTML]="subtitle"></h5>
<p class="mb-0" [innerHTML]="message"></p>
@if (message2) {
<p class="mb-0 mt-3" [innerHTML]="message2"></p>
} @if (markdownMessage2) {
<markdown class="plugin-md" [data]="markdownMessage2"></markdown>
}
</div>
<div class="modal-footer justify-content-between">
Expand Down
100 changes: 100 additions & 0 deletions ui/src/app/core/components/information/information.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
:host {
::ng-deep .plugin-md {
display: block !important;
/* Ensure markdown container is a block element */
background-color: #f6f8fa !important;
/* Grey background matching GitHub table header */
border-radius: 6px !important;
/* Rounded corners */
padding: 16px !important;
/* Padding inside the grey box */
margin: 16px auto !important;
/* Center the box */
width: 100% !important;
/* Full width to match content */
max-width: 632px !important;
/* Match table max-width (600px) + padding (16px * 2) */

table {
width: 100%;
max-width: 600px;
margin: 0 auto !important;
/* Center table within the grey box */
border-collapse: collapse;
border: 1px solid #d0d7de !important;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif !important;
font-size: 14px !important;
color: #24292e !important;
/* Dark text color */
}

th,
td {
padding: 6px 13px !important;
border: 1px solid #d0d7de !important;
text-align: left;
color: #24292e !important;
/* Dark text color */
}

th {
background-color: #f6f8fa !important;
font-weight: 600 !important;
text-align: center !important;
}

td[align='center'] {
text-align: center !important;
}

tr {
color: #24292e !important;
/* Dark text color */
}

tr:nth-child(odd) {
background-color: #ffffff !important;
}

tr:nth-child(even) {
background-color: #f6f8fa !important;
}

tr:hover {
background-color: #f0f2f5 !important;
}
}

/* Dark mode support for the greyed box */
body.dark-mode .plugin-md {
background-color: #2b2b2b !important;
/* Darker grey for dark mode */
color: #ffffff !important;
/* White text for dark mode */

table,
tr,
th,
td {
color: #ffffff !important;
/* White text for dark mode */
}

th {
background-color: #3c3c3c !important;
/* Slightly darker header in dark mode */
}

tr:nth-child(odd) {
background-color: #323232 !important;
}

tr:nth-child(even) {
background-color: #2b2b2b !important;
}

tr:hover {
background-color: #454545 !important;
}
}
}
11 changes: 10 additions & 1 deletion ui/src/app/core/components/information/information.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { Component, inject, Input } from '@angular/core'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
import { TranslatePipe } from '@ngx-translate/core'
import { NgxMdModule } from 'ngx-md'

import { PluginsMarkdownDirective } from '@/app/core/directives/plugins.markdown.directive'

@Component({
templateUrl: './information.component.html',
styleUrls: ['./information.component.scss'],
standalone: true,
imports: [TranslatePipe],
imports: [
TranslatePipe,
NgxMdModule,
PluginsMarkdownDirective,
],
})
export class InformationComponent {
private $activeModal = inject(NgbActiveModal)
Expand All @@ -17,6 +25,7 @@ export class InformationComponent {
@Input() ctaButtonLabel?: string
@Input() ctaButtonLink?: string
@Input() faIconClass: string
@Input() markdownMessage2?: string

public dismissModal() {
this.$activeModal.dismiss('Dismiss')
Expand Down
Loading