Skip to content

Commit 2cd5e79

Browse files
committed
Use latest tag as most recently updated tag
1 parent cec62fa commit 2cd5e79

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

web-server/pages/api/internal/version.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Endpoint, nullSchema } from '@/api-helpers/global';
55
const dockerRepoName = 'middlewareeng/middleware';
66
const githubOrgName = 'middlewarehq';
77
const githubRepoName = 'middleware';
8+
const latestTagName = 'latest';
89

910
const endpoint = new Endpoint(nullSchema);
1011

@@ -26,13 +27,6 @@ type CheckNewVersionResponse = {
2627
current_docker_image_build_date: Date;
2728
};
2829

29-
type DockerHubAPIResponse = {
30-
count: number;
31-
next: string | null;
32-
previous: string | null;
33-
results: TagResult[];
34-
};
35-
3630
type TagResult = {
3731
creator: number;
3832
id: number;
@@ -69,7 +63,7 @@ type DockerImage = {
6963
type TagCompressed = {
7064
name: string;
7165
last_updated: string;
72-
digest: string;
66+
digest?: string;
7367
};
7468

7569
function getProjectVersionInfo(): ProjectVersionInfo {
@@ -83,19 +77,14 @@ function getProjectVersionInfo(): ProjectVersionInfo {
8377
}
8478

8579
async function fetchDockerHubLatestTag(): Promise<TagCompressed> {
86-
const dockerHubUrl = `https://hub.docker.com/v2/repositories/${dockerRepoName}/tags?ordering=last_updated&page_size=1`;
87-
const response = await axios.get<DockerHubAPIResponse>(dockerHubUrl);
88-
89-
const latestTagName = response.data.results[0].name;
90-
91-
const tagUrl = `https://hub.docker.com/v2/repositories/${dockerRepoName}/tags/${latestTagName}`;
92-
const latestTag = (await axios.get<TagResult>(tagUrl)).data;
80+
const latestTagUrl = `https://hub.docker.com/v2/repositories/${dockerRepoName}/tags/${latestTagName}`;
81+
const latestTag = (await axios.get<TagResult>(latestTagUrl)).data;
9382

9483
const amdArchImage = latestTag.images.find((i) => i.architecture === 'amd64');
9584

9685
return {
9786
name: latestTag.name,
98-
digest: amdArchImage.digest,
87+
digest: amdArchImage?.digest,
9988
last_updated: latestTag.last_updated
10089
};
10190
}
@@ -133,7 +122,10 @@ async function checkNewImageRelease(): Promise<CheckNewVersionResponse> {
133122

134123
const latestRemoteDate = new Date(latestTag.last_updated);
135124

136-
const latestDockerImageLink = `https://hub.docker.com/layers/${dockerRepoName}/${latestTag.name}/images/${latestTag.digest}`;
125+
let latestDockerImageLink = `https://hub.docker.com/r/layers/${dockerRepoName}/tags`;
126+
if (latestTag.digest) {
127+
latestDockerImageLink = `https://hub.docker.com/layers/${dockerRepoName}/${latestTag.name}/images/${latestTag.digest}`;
128+
}
137129

138130
const githubRepLink = `https://github.com/${githubOrgName}/${githubRepoName}`;
139131

web-server/src/layouts/ExtendedSidebarLayout/Sidebar/index.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
useTheme,
88
lighten
99
} from '@mui/material';
10-
import { format } from 'date-fns';
10+
import { format, isValid } from 'date-fns';
1111
import { useContext, useMemo } from 'react';
1212

1313
import { FlexBox } from '@/components/FlexBox';
@@ -67,11 +67,9 @@ const SidebarContent = () => {
6767

6868
const imageStatus = useSelector((s) => s.app.latestImageStatus);
6969

70-
const formattedDate = imageStatus?.current_docker_image_build_date
71-
? format(
72-
new Date(imageStatus.current_docker_image_build_date),
73-
'dd MMM yyyy HH:mm:ss'
74-
)
70+
const imageBuildDate = new Date(imageStatus?.current_docker_image_build_date);
71+
const formattedDate = isValid(imageBuildDate)
72+
? format(imageBuildDate, 'dd MMM yyyy HH:mm:ss')
7573
: 'Not Available';
7674

7775
return (

0 commit comments

Comments
 (0)