diff --git a/.env.example b/.env.example index b452c5f..7d597d9 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ -NezhaBaseUrl=http://0.0.0.0:8008 -NezhaAuth=5hAY3QX6Nl9B3UOQgB26KdsdS1dsdUdM -NEXT_PUBLIC_NezhaFetchInterval=5000 +NezhaBaseUrl=http://1.1.1.1:8008 +NezhaAuth=nezha-token +NEXT_PUBLIC_NezhaFetchInterval=2000 NEXT_PUBLIC_ShowFlag=true -NEXT_PUBLIC_DisableCartoon=true \ No newline at end of file +NEXT_PUBLIC_DisableCartoon=false \ No newline at end of file diff --git a/.github/workflows/Deploy.yml b/.github/workflows/Deploy.yml new file mode 100644 index 0000000..b4ca664 --- /dev/null +++ b/.github/workflows/Deploy.yml @@ -0,0 +1,46 @@ +name: Build and push Docker image + +on: + push: + tags: + - "v*" + +jobs: + build-and-push: + runs-on: ubuntu-latest + environment: Production + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Login to AliYun Container Registry + uses: docker/login-action@v3 + with: + registry: registry.cn-guangzhou.aliyuncs.com + username: ${{ secrets.ALI_USERNAME }} + password: ${{ secrets.ALI_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: | + hamster1963/nezha-dash + registry.cn-guangzhou.aliyuncs.com/hamster-home/nezha-dash + tags: | + type=raw,value=latest + type=ref,event=tag + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index a5cfcf0..336b824 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,9 +24,6 @@ WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . -ARG PROD_ENV="" -# Appends to .env.production -RUN printf "$PROD_ENV" >> .env.production RUN yarn build @@ -41,12 +38,10 @@ RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs COPY --from=builder /app/public ./public -COPY --from=builder /app/.env.production ./.env.production COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static - - +COPY --from=builder --chown=nextjs:nodejs /app/.env.example ./.env USER nextjs diff --git a/app/(main)/ClientComponents/ServerListClient.tsx b/app/(main)/ClientComponents/ServerListClient.tsx index a441bda..cc82121 100644 --- a/app/(main)/ClientComponents/ServerListClient.tsx +++ b/app/(main)/ClientComponents/ServerListClient.tsx @@ -4,10 +4,11 @@ import { ServerApi } from "@/app/types/nezha-api"; import ServerCard from "@/components/ServerCard"; import { nezhaFetcher } from "@/lib/utils"; import useSWR from "swr"; +import getEnv from "@/lib/env-entry"; export default function ServerListClient() { const { data } = useSWR("/api/server", nezhaFetcher, { - refreshInterval: Number(process.env.NEXT_PUBLIC_NezhaFetchInterval) || 2000, + refreshInterval: Number(getEnv("NEXT_PUBLIC_NezhaFetchInterval")) || 2000, }); if (!data) return null; diff --git a/app/(main)/ClientComponents/ServerOverviewClient.tsx b/app/(main)/ClientComponents/ServerOverviewClient.tsx index 5297d71..ec50d46 100644 --- a/app/(main)/ClientComponents/ServerOverviewClient.tsx +++ b/app/(main)/ClientComponents/ServerOverviewClient.tsx @@ -7,11 +7,12 @@ import useSWR from "swr"; import { formatBytes, nezhaFetcher } from "@/lib/utils"; import { Loader } from "@/components/loading/Loader"; import { ServerApi } from "@/app/types/nezha-api"; +import getEnv from "@/lib/env-entry"; export default function ServerOverviewClient() { const { data } = useSWR("/api/server", nezhaFetcher); - const disableCartoon = process.env.NEXT_PUBLIC_DisableCartoon === "true"; + const disableCartoon = getEnv("NEXT_PUBLIC_DisableCartoon") === "true"; return (
diff --git a/app/api/server/route.ts b/app/api/server/route.ts index f99bc10..f47afb7 100644 --- a/app/api/server/route.ts +++ b/app/api/server/route.ts @@ -1,11 +1,17 @@ import { GetNezhaData } from "@/lib/serverFetch"; import { NextResponse } from "next/server"; +export const dynamic = "force-dynamic"; + export async function GET(_: Request) { try { const response = await GetNezhaData(); return NextResponse.json(response, { status: 200 }); } catch (error) { - return NextResponse.json({ error: error }, { status: 200 }); + console.error(error); + return NextResponse.json( + { error: "fetch nezha data failed" }, + { status: 400 }, + ); } } diff --git a/app/layout.tsx b/app/layout.tsx index 7783995..f9e8355 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -6,6 +6,7 @@ import { ThemeProvider } from "next-themes"; import React from "react"; import { Viewport } from "next"; import { cn } from "@/lib/utils"; +import { PublicEnvScript } from "next-runtime-env"; const fontSans = FontSans({ subsets: ["latin"], @@ -37,6 +38,9 @@ interface RootLayoutProps { export default function RootLayout({ children }: RootLayoutProps) { return ( + + +