feat: add BuildInfo component to display build time and update Docker workflow to pass build time as environment variable
This commit is contained in:
6
.github/workflows/docker-build.yml
vendored
6
.github/workflows/docker-build.yml
vendored
@@ -36,6 +36,10 @@ jobs:
|
|||||||
type=ref,event=branch
|
type=ref,event=branch
|
||||||
type=raw,value=latest,enable={{is_default_branch}}
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
|
|
||||||
|
- name: Get build time
|
||||||
|
id: buildtime
|
||||||
|
run: echo "BUILD_TIME=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v7
|
uses: docker/build-push-action@v7
|
||||||
with:
|
with:
|
||||||
@@ -43,5 +47,7 @@ jobs:
|
|||||||
push: true
|
push: true
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
build-args: |
|
||||||
|
BUILD_TIME=${{ steps.buildtime.outputs.BUILD_TIME }}
|
||||||
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache
|
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache
|
||||||
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max
|
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ COPY --from=dependencies /app/node_modules ./node_modules
|
|||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
|
ENV BUILD_TIME=${BUILD_TIME}
|
||||||
|
|
||||||
# Next.js collects completely anonymous telemetry data about general usage.
|
# Next.js collects completely anonymous telemetry data about general usage.
|
||||||
# Learn more here: https://nextjs.org/telemetry
|
# Learn more here: https://nextjs.org/telemetry
|
||||||
@@ -63,6 +64,7 @@ WORKDIR /app
|
|||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV PORT=3000
|
ENV PORT=3000
|
||||||
ENV HOSTNAME="0.0.0.0"
|
ENV HOSTNAME="0.0.0.0"
|
||||||
|
ENV BUILD_TIME=${BUILD_TIME}
|
||||||
|
|
||||||
# Next.js collects completely anonymous telemetry data about general usage.
|
# Next.js collects completely anonymous telemetry data about general usage.
|
||||||
# Learn more here: https://nextjs.org/telemetry
|
# Learn more here: https://nextjs.org/telemetry
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import DatasetsList from "@/components/DatasetsList";
|
import DatasetsList from "@/components/DatasetsList";
|
||||||
import CreateDatasetModal from "@/components/CreateDatasetModal";
|
import CreateDatasetModal from "@/components/CreateDatasetModal";
|
||||||
import { AdminTokenForm } from "@/components/AdminTokenForm";
|
import { AdminTokenForm } from "@/components/AdminTokenForm";
|
||||||
|
import BuildInfo from "@/components/BuildInfo";
|
||||||
import { requireAdmin } from "@/lib/auth";
|
import { requireAdmin } from "@/lib/auth";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
@@ -30,6 +31,10 @@ export default async function AdminPage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="mb-8">
|
||||||
|
<BuildInfo />
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="mt-8">
|
<div className="mt-8">
|
||||||
<h2 className="text-2xl font-bold mb-4">Datasets</h2>
|
<h2 className="text-2xl font-bold mb-4">Datasets</h2>
|
||||||
<CreateDatasetModal />
|
<CreateDatasetModal />
|
||||||
|
|||||||
32
src/components/BuildInfo.tsx
Normal file
32
src/components/BuildInfo.tsx
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
export default function BuildInfo() {
|
||||||
|
const buildTime = process.env.BUILD_TIME;
|
||||||
|
|
||||||
|
if (!buildTime) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const buildDate = new Date(buildTime);
|
||||||
|
const now = new Date();
|
||||||
|
const diffMs = now.getTime() - buildDate.getTime();
|
||||||
|
|
||||||
|
let timeAgo = '';
|
||||||
|
const diffMins = Math.floor(diffMs / 60000);
|
||||||
|
const diffHours = Math.floor(diffMs / 3600000);
|
||||||
|
const diffDays = Math.floor(diffMs / 86400000);
|
||||||
|
|
||||||
|
if (diffMins < 60) {
|
||||||
|
timeAgo = `${diffMins} minute${diffMins !== 1 ? 's' : ''} ago`;
|
||||||
|
} else if (diffHours < 24) {
|
||||||
|
timeAgo = `${diffHours} hour${diffHours !== 1 ? 's' : ''} ago`;
|
||||||
|
} else {
|
||||||
|
timeAgo = `${diffDays} day${diffDays !== 1 ? 's' : ''} ago`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="bg-gray-50 border border-gray-200 rounded-lg p-4 text-sm">
|
||||||
|
<p className="text-gray-700">
|
||||||
|
<span className="font-semibold">Build Time:</span> {buildDate.toLocaleString()} ({timeAgo})
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user