Skip to content
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
40 changes: 17 additions & 23 deletions web-server/pages/api/internal/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Endpoint, nullSchema } from '@/api-helpers/global';
const dockerRepoName = 'middlewareeng/middleware';
const githubOrgName = 'middlewarehq';
const githubRepoName = 'middleware';
const latestTagName = 'latest';

const endpoint = new Endpoint(nullSchema);

Expand All @@ -26,13 +27,6 @@ type CheckNewVersionResponse = {
current_docker_image_build_date: Date;
};

type DockerHubAPIResponse = {
count: number;
next: string | null;
previous: string | null;
results: TagResult[];
};

type TagResult = {
creator: number;
id: number;
Expand Down Expand Up @@ -69,7 +63,7 @@ type DockerImage = {
type TagCompressed = {
name: string;
last_updated: string;
digest: string;
digest?: string;
};

function getProjectVersionInfo(): ProjectVersionInfo {
Expand All @@ -82,15 +76,17 @@ function getProjectVersionInfo(): ProjectVersionInfo {
};
}

async function fetchDockerHubTags(): Promise<TagCompressed[]> {
const dockerHubUrl = `https://hub.docker.com/v2/repositories/${dockerRepoName}/tags/`;
const response = await axios.get<DockerHubAPIResponse>(dockerHubUrl);
async function fetchDockerHubLatestTag(): Promise<TagCompressed> {
const latestTagUrl = `https://hub.docker.com/v2/repositories/${dockerRepoName}/tags/${latestTagName}`;
const latestTag = (await axios.get<TagResult>(latestTagUrl)).data;

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

return response.data.results.map((tag) => ({
name: tag.name,
digest: tag.images[0].digest,
last_updated: tag.last_updated
}));
return {
name: latestTag.name,
digest: amdArchImage?.digest,
last_updated: latestTag.last_updated
};
}

function isUpdateAvailable({
Expand Down Expand Up @@ -122,16 +118,14 @@ function isUpdateAvailable({
async function checkNewImageRelease(): Promise<CheckNewVersionResponse> {
const versionInfo = getProjectVersionInfo();

const [dockerRemoteTags] = await Promise.all([fetchDockerHubTags()]);
const latestTag = await fetchDockerHubLatestTag();

dockerRemoteTags.sort(
(a, b) =>
new Date(b.last_updated).getTime() - new Date(a.last_updated).getTime()
);
const latestTag = dockerRemoteTags[0];
const latestRemoteDate = new Date(latestTag.last_updated);

Comment thread
Kamlesh72 marked this conversation as resolved.
const latestDockerImageLink = `https://hub.docker.com/layers/${dockerRepoName}/${latestTag.name}/images/${latestTag.digest}`;
let latestDockerImageLink = `https://hub.docker.com/r/${dockerRepoName}/tags`;
if (latestTag.digest) {
latestDockerImageLink = `https://hub.docker.com/layers/${dockerRepoName}/${latestTag.name}/images/${latestTag.digest}`;
}

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

Expand Down
10 changes: 5 additions & 5 deletions web-server/src/layouts/ExtendedSidebarLayout/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useTheme,
lighten
} from '@mui/material';
import { format } from 'date-fns';
import { format, isValid } from 'date-fns';
import { useContext, useMemo } from 'react';

import { FlexBox } from '@/components/FlexBox';
Expand Down Expand Up @@ -67,10 +67,10 @@ const SidebarContent = () => {

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

const formattedDate = format(
new Date(imageStatus.current_docker_image_build_date),
'dd MMM yyyy HH:mm:ss'
);
const imageBuildDate = new Date(imageStatus?.current_docker_image_build_date);
const formattedDate = isValid(imageBuildDate)
? format(imageBuildDate, 'dd MMM yyyy HH:mm:ss')
: 'Not Available';

return (
<>
Expand Down