Skip to content

Your favorite shift management application!

feat: Adds Docker build versioning and enhanced footer (#15)

panteLabc6e841d938
diff --git a/.github/workflows/docker-dev.yml b/.github/workflows/docker-dev.yml
index 326c651..396250b 100644
--- a/.github/workflows/docker-dev.yml
+++ b/.github/workflows/docker-dev.yml
@@ -48,3 +48,5 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
+ build-args: |
+ VERSION=dev
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 0b75a5f..cb410aa 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -116,6 +116,8 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
+ build-args: |
+ VERSION=v${{ steps.version.outputs.VERSION }}
- name: Create Release
uses: softprops/action-gh-release@v2
diff --git a/.gitignore b/.gitignore
index 328b211..3f6f1e6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -49,6 +49,9 @@ sqlite.db-shm
sqlite.db-wal
data/
+# Docker build version file
+.version
+
# docker (local override configuration)
docker-compose.override.yml
diff --git a/Dockerfile b/Dockerfile
index 5ee4ba0..36eb9e6 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -5,6 +5,9 @@ FROM node:20-alpine AS builder
RUN apk add --no-cache libc6-compat python3 make g++
WORKDIR /app
+# Build argument for version (set during docker build)
+ARG VERSION=dev
+
# Copy package files and install ALL dependencies
# These layers are cached unless package files change
COPY package.json package-lock.json ./
@@ -26,6 +29,9 @@ FROM node:20-alpine AS runner
RUN apk add --no-cache libc6-compat
WORKDIR /app
+# Get VERSION from builder stage
+ARG VERSION=dev
+
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
@@ -42,6 +48,9 @@ COPY --from=builder /app/package-lock.json ./package-lock.json
RUN --mount=type=cache,target=/root/.npm \
npm ci --only=production
+# Write VERSION to file for runtime access
+RUN echo "$VERSION" > /app/.version
+
# Create data directory for SQLite database
RUN mkdir -p /app/data
diff --git a/app/api/version/route.ts b/app/api/version/route.ts
index 0560dea..92e4527 100644
--- a/app/api/version/route.ts
+++ b/app/api/version/route.ts
@@ -1,34 +1,44 @@
import { NextResponse } from "next/server";
-import { readFileSync } from "fs";
+import { readFileSync, existsSync } from "fs";
import { join } from "path";
-// Cache version info for 1 hour
+// Cache version info
let cachedVersion: {
version: string;
- branch: string;
commitHash: string;
- buildDate: string;
timestamp: number;
} | null = null;
-// Cache package version at module level (initialized on first call)
+let cachedDockerVersion: string | null = null;
let cachedPackageVersion = "";
-const CACHE_SECONDS = parseInt(
- process.env.VERSION_CACHE_DURATION || "3600",
- 10
-); // Default: 1 hour in seconds
-const CACHE_DURATION = CACHE_SECONDS * 1000; // Convert to milliseconds for in-memory TTL
-const GITHUB_API_REVALIDATE = parseInt(
- process.env.GITHUB_API_REVALIDATE || "3600",
- 10
-); // Default: 1 hour in seconds
+const CACHE_DURATION = 3600 * 1000; // 1 hour
+const CACHE_SECONDS = 3600;
const GITHUB_REPO_OWNER = process.env.GITHUB_REPO_OWNER || "panteLx";
const GITHUB_REPO_NAME = process.env.GITHUB_REPO_NAME || "BetterShift";
const GITHUB_BRANCH = process.env.GITHUB_BRANCH || "main";
const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
+function getDockerVersion(): string | null {
+ if (cachedDockerVersion !== null) {
+ return cachedDockerVersion;
+ }
+
+ try {
+ const versionFilePath = join(process.cwd(), ".version");
+ if (existsSync(versionFilePath)) {
+ cachedDockerVersion = readFileSync(versionFilePath, "utf-8").trim();
+ return cachedDockerVersion;
+ }
+ } catch (error) {
+ console.log("No .version file found, not running in Docker");
+ }
+
+ cachedDockerVersion = null;
+ return null;
+}
+
function getPackageVersion(): string {
if (cachedPackageVersion) {
return cachedPackageVersion;
@@ -46,11 +56,8 @@ function getPackageVersion(): string {
}
}
-async function fetchGitHubVersion() {
+async function fetchCommitHash(): Promise<string> {
try {
- const packageVersion = getPackageVersion();
-
- // Get latest commit from configured branch
const response = await fetch(
`https://api.github.com/repos/${GITHUB_REPO_OWNER}/${GITHUB_REPO_NAME}/commits/${GITHUB_BRANCH}`,
{
@@ -58,7 +65,7 @@ async function fetchGitHubVersion() {
Accept: "application/vnd.github.v3+json",
...(GITHUB_TOKEN && { Authorization: `Bearer ${GITHUB_TOKEN}` }),
},
- next: { revalidate: GITHUB_API_REVALIDATE },
+ next: { revalidate: CACHE_SECONDS },
}
);
@@ -67,31 +74,43 @@ async function fetchGitHubVersion() {
}
const data = await response.json();
- const commitHash = data.sha.substring(0, 7);
- const branch = GITHUB_BRANCH;
-
- return {
- version: packageVersion,
- branch,
- commitHash,
- buildDate: data.commit.committer.date,
- timestamp: Date.now(),
- };
+ return data.sha.substring(0, 7);
} catch (error) {
- console.error("Failed to fetch GitHub version:", error);
- return null;
+ console.error("Failed to fetch commit hash:", error);
+ return "unknown";
}
}
+function buildGitHubUrl(version: string, commitHash: string): string {
+ const baseUrl = `https://github.com/${GITHUB_REPO_OWNER}/${GITHUB_REPO_NAME}`;
+
+ // Check if version matches semver pattern (e.g., 1.1.1 or v1.1.1)
+ const semverPattern = /^v?\d+\.\d+\.\d+$/;
+ if (semverPattern.test(version)) {
+ const tag = version.startsWith("v") ? version : `v${version}`;
+ return `${baseUrl}/releases/tag/${tag}`;
+ }
+
+ // Otherwise link to commit
+ if (commitHash && commitHash !== "unknown") {
+ return `${baseUrl}/commit/${commitHash}`;
+ }
+
+ return baseUrl;
+}
+
export async function GET() {
- // Check if we have a valid cached version
+ // Check cache
if (cachedVersion && Date.now() - cachedVersion.timestamp < CACHE_DURATION) {
+ const githubUrl = buildGitHubUrl(
+ cachedVersion.version,
+ cachedVersion.commitHash
+ );
return NextResponse.json(
{
version: cachedVersion.version,
- branch: cachedVersion.branch,
commitHash: cachedVersion.commitHash,
- buildDate: cachedVersion.buildDate,
+ githubUrl,
},
{
headers: {
@@ -101,38 +120,28 @@ export async function GET() {
);
}
- // Fetch new version from GitHub
- const versionInfo = await fetchGitHubVersion();
+ // Try to get version from Docker build arg first
+ const dockerVersion = getDockerVersion();
+ const version = dockerVersion || getPackageVersion();
+ const commitHash = await fetchCommitHash();
- if (versionInfo) {
- cachedVersion = versionInfo;
- return NextResponse.json(
- {
- version: versionInfo.version,
- branch: versionInfo.branch,
- commitHash: versionInfo.commitHash,
- buildDate: versionInfo.buildDate,
- },
- {
- headers: {
- "Cache-Control": `public, max-age=${CACHE_SECONDS}`,
- },
- }
- );
- }
+ cachedVersion = {
+ version,
+ commitHash,
+ timestamp: Date.now(),
+ };
+
+ const githubUrl = buildGitHubUrl(version, commitHash);
- // Fallback to dev-local if GitHub API fails
- const packageVersion = getPackageVersion();
return NextResponse.json(
{
- version: packageVersion,
- branch: "unknown",
- commitHash: "unknown",
- buildDate: new Date().toISOString(),
+ version,
+ commitHash,
+ githubUrl,
},
{
headers: {
- "Cache-Control": "public, max-age=60", // Shorter cache on error
+ "Cache-Control": `public, max-age=${CACHE_SECONDS}`,
},
}
);
diff --git a/app/page.tsx b/app/page.tsx
index 4cd768e..9e43d34 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -12,6 +12,7 @@ import { ICloudSyncManageDialog } from "@/components/icloud-sync-manage-dialog";
import { DayShiftsDialog } from "@/components/day-shifts-dialog";
import { SyncedShiftsDialog } from "@/components/synced-shifts-dialog";
import { LanguageSwitcher } from "@/components/language-switcher";
+import { AppFooter } from "@/components/app-footer";
import { ShiftStats } from "@/components/shift-stats";
import { NoteDialog } from "@/components/note-dialog";
import { AppHeader } from "@/components/app-header";
@@ -152,7 +153,11 @@ function HomeContent() {
const [statsRefreshTrigger, setStatsRefreshTrigger] = useState(0);
const [togglingDates, setTogglingDates] = useState<Set<string>>(new Set());
const [isConnected, setIsConnected] = useState(true);
- const [version, setVersion] = useState<string | null>(null);
+ const [versionInfo, setVersionInfo] = useState<{
+ version: string;
+ githubUrl: string;
+ commitHash?: string;
+ } | null>(null);
// SSE Connection for real-time updates
useSSEConnection({
@@ -170,7 +175,11 @@ function HomeContent() {
try {
const response = await fetch("/api/version");
const data = await response.json();
- setVersion(data.version);
+ setVersionInfo({
+ version: data.version,
+ githubUrl: data.githubUrl,
+ commitHash: data.commitHash,
+ });
} catch (error) {
console.error("Failed to fetch version:", error);
}
@@ -927,16 +936,7 @@ function HomeContent() {
/>
{/* Footer */}
- <div className="border-t bg-background mt-auto">
- <div className="container max-w-4xl mx-auto p-3 sm:p-4 flex justify-between items-center">
- <LanguageSwitcher />
- {version && (
- <div className="text-xs text-muted-foreground font-mono">
- {t("version.label")}: {version}
- </div>
- )}
- </div>
- </div>
+ <AppFooter versionInfo={versionInfo} />
</div>
);
}
diff --git a/components/app-footer.tsx b/components/app-footer.tsx
new file mode 100644
index 0000000..01ce8c1
--- /dev/null
+++ b/components/app-footer.tsx
@@ -0,0 +1,85 @@
+"use client";
+
+import { useTranslations } from "next-intl";
+import { Coffee, Github } from "lucide-react";
+import { LanguageSwitcher } from "./language-switcher";
+
+interface VersionInfo {
+ version: string;
+ githubUrl: string;
+ commitHash?: string;
+}
+
+interface AppFooterProps {
+ versionInfo: VersionInfo | null;
+}
+
+export function AppFooter({ versionInfo }: AppFooterProps) {
+ const t = useTranslations();
+
+ // Format version display based on version type
+ const displayVersion =
+ versionInfo?.version === "dev" && versionInfo?.commitHash
+ ? `dev (${versionInfo.commitHash})`
+ : versionInfo?.version;
+
+ return (
+ <footer className="border-t bg-background mt-auto">
+ <div className="container max-w-4xl mx-auto p-3 sm:p-4">
+ {/* Mobile: Two rows (language + links), Desktop: One row */}
+ <div className="flex flex-col gap-2 sm:flex-row sm:justify-between sm:items-center sm:gap-4">
+ {/* Language switcher */}
+ <div className="flex justify-center sm:justify-start">
+ <LanguageSwitcher />
+ </div>
+
+ {/* Links row - horizontal on all screen sizes */}
+ <div className="flex flex-row items-center justify-center sm:justify-end gap-3 sm:gap-4 text-xs">
+ {/* Version info */}
+ {versionInfo && (
+ <a
+ href={versionInfo.githubUrl}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-muted-foreground hover:text-foreground transition-colors font-mono whitespace-nowrap"
+ title={
+ versionInfo.commitHash
+ ? `${t("footer.version")}: ${versionInfo.version} (${
+ versionInfo.commitHash
+ })`
+ : `${t("footer.version")}: ${versionInfo.version}`
+ }
+ >
+ {t("footer.version")}: {displayVersion}
+ </a>
+ )}
+
+ {/* GitHub repo link */}
+ <a
+ href="https://github.com/panteLx/BetterShift"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="flex items-center gap-1.5 text-muted-foreground hover:text-foreground transition-colors"
+ title={t("footer.github")}
+ >
+ <Github className="w-4 h-4" />
+ <span className="hidden sm:inline">{t("footer.github")}</span>
+ </a>
+
+ {/* Buy Me a Coffee link */}
+ <a
+ href="https://buymeacoffee.com/pantelx"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="flex items-center gap-1.5 text-muted-foreground hover:text-amber-500 transition-colors"
+ title={t("footer.support")}
+ >
+ <Coffee className="w-4 h-4" />
+ <span className="hidden sm:inline">{t("footer.support")}</span>
+ </a>
+ </div>
+ </div>
+ </div>
+ </footer>
+ );
+}
diff --git a/messages/de.json b/messages/de.json
index 8563d72..c568b35 100644
--- a/messages/de.json
+++ b/messages/de.json
@@ -158,6 +158,11 @@
"version": {
"label": "Version"
},
+ "footer": {
+ "version": "Version",
+ "github": "GitHub",
+ "support": "Unterstützen"
+ },
"icloud": {
"manageTitle": "iCloud-Synchronisierungen verwalten",
"manageDescription": "Füge mehrere iCloud-Kalendersynchronisierungen für diesen Kalender hinzu und verwalte sie",
diff --git a/messages/en.json b/messages/en.json
index 0d669ef..1702aa7 100644
--- a/messages/en.json
+++ b/messages/en.json
@@ -158,6 +158,11 @@
"version": {
"label": "Version"
},
+ "footer": {
+ "version": "Version",
+ "github": "GitHub",
+ "support": "Support"
+ },
"icloud": {
"manageTitle": "Manage iCloud Syncs",
"manageDescription": "Add and manage multiple iCloud calendar syncs for this calendar",