diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index ddf1353..2707e80 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,4 +1,4 @@ -name: Publish Docker image +name: Build Docker Images on: workflow_dispatch: @@ -6,19 +6,25 @@ on: types: [published] jobs: - push_to_registry: - name: Push Docker image to Docker Hub + build: runs-on: ubuntu-latest steps: - - name: Check out the repo + - name: Checkout uses: actions/checkout@v4 - - name: Log in to Docker Hub + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: amd64,arm64 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + platforms: linux/amd64,linux/arm64 + - name: Login to Docker Hub uses: docker/login-action@v3 with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Extract metadata (tags, labels) for Docker + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Docker meta id: meta uses: docker/metadata-action@v5 with: @@ -26,20 +32,13 @@ jobs: tags: | type=raw,value=latest type=ref,event=tag - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Build and push Docker image - uses: docker/build-push-action@v5 + - name: Build and push + uses: docker/build-push-action@v6 with: context: . - platforms: linux/amd64,linux/arm64 push: true + platforms: linux/amd64,linux/arm64 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha - cache-to: type=gha,mode=max \ No newline at end of file + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile index db41bd0..1fee85e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,15 @@ -FROM node:18-alpine AS base +FROM node:20-alpine AS base # Install dependencies only when needed FROM base AS deps -# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. -RUN apk add --no-cache libc6-compat && \ - wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.shrc" SHELL="$(which sh)" sh - +RUN apk add --no-cache libc6-compat WORKDIR /app -# Install dependencies based on the preferred package manager -COPY package.json pnpm-lock.yaml ./ -RUN source /root/.shrc; \ - if [ -f pnpm-lock.yaml ]; then pnpm i --frozen-lockfile; \ +COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ +RUN \ + if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ + elif [ -f package-lock.json ]; then npm ci; \ + elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \ else echo "Lockfile not found." && exit 1; \ fi @@ -20,15 +19,15 @@ WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . -# Next.js collects completely anonymous telemetry data about general usage. -# Learn more here: https://nextjs.org/telemetry -# Uncomment the following line in case you want to disable telemetry during the build. ENV NEXT_TELEMETRY_DISABLED 1 +RUN \ + if [ -f yarn.lock ]; then yarn run build; \ + elif [ -f package-lock.json ]; then npm run build; \ + elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \ + else echo "Lockfile not found." && exit 1; \ + fi -RUN wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.shrc" SHELL="$(which sh)" sh -; \ - source /root/.shrc; \ - pnpm build - +# Production image, copy all the files and run next FROM base AS runner WORKDIR /app @@ -38,15 +37,14 @@ ENV NEXT_TELEMETRY_DISABLED 1 RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs +RUN mkdir .next +RUN chown nextjs:nodejs .next + COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static USER nextjs -EXPOSE 3002 - -ENV PORT 3002 -# set hostname to localhost -ENV HOSTNAME "127.0.0.1" - -CMD ["node", "server.js"] \ No newline at end of file +EXPOSE 3000 +ENV PORT 3000 +CMD HOSTNAME="127.0.0.1" node server.js \ No newline at end of file diff --git a/README.md b/README.md index 34643c0..51cfdc0 100644 --- a/README.md +++ b/README.md @@ -13,5 +13,3 @@ - **❗接收到的邮件内容仅能保留10天** - **❗随机生成的邮箱地址任何人都可以使用,请勿用于注册重要账号** - - diff --git a/app/api/config/route.ts b/app/api/config/route.ts index 4e277a5..c4c0ab9 100644 --- a/app/api/config/route.ts +++ b/app/api/config/route.ts @@ -1,7 +1,7 @@ import { NextRequest, NextResponse } from "next/server"; import { ConfigServer } from "@/lib/store/config-server"; -import { getDomainList } from "@/lib/utils"; import { unstable_noStore as noStore } from "next/cache"; +import { getDomainList } from "@/lib/utils"; export async function GET(req: NextRequest) { noStore(); diff --git a/app/api/count/route.ts b/app/api/count/route.ts index f1b3744..611dc76 100644 --- a/app/api/count/route.ts +++ b/app/api/count/route.ts @@ -1,9 +1,9 @@ import { NextRequest, NextResponse } from "next/server"; +import { unstable_noStore as noStore } from "next/cache"; import { fetchLast10Day } from "@/app/api/fetch"; export async function GET(req: NextRequest) { - // No need to execute fetch* when packaging (don't know why, but it works) - req.headers.get("host"); + noStore(); try { const data = await fetchLast10Day(); return NextResponse.json(data); diff --git a/deploy.md b/deploy.md index 6098abd..80bc5e7 100644 --- a/deploy.md +++ b/deploy.md @@ -12,7 +12,7 @@ 2. 然后需要添加一条`Catch-All`的规则到目标邮箱中,如图: -此处需要一个自己的邮箱作为目标邮箱,推荐使用 Outlook *(环境变量配置也是基于此邮箱)* +此处需要一个自己的邮箱作为目标邮箱,推荐使用 Outlook _(环境变量配置也是基于此邮箱)_ ![email-routing.png](doc/email-routing.png) @@ -20,7 +20,7 @@ 默认会从垃圾邮件`Junk`文件夹中获取,可通过`IMAP_PATH`环境变量指定。 -需要添加一个或多个邮件规则,将接收到的目标邮件移动到指定的文件夹下 *(需要将图中的`.eu.org`替换为自己的域名,可配置多个)* +需要添加一个或多个邮件规则,将接收到的目标邮件移动到指定的文件夹下 _(需要将图中的`.eu.org`替换为自己的域名,可配置多个)_ ![rule.png](doc/rule.png) @@ -38,7 +38,7 @@ ## 部署 -*请修改其中的环境变量配置* +_请修改其中的环境变量配置_ ### Docker @@ -48,12 +48,12 @@ docker run --name mail -d --restart unless-stopped -e 'HOSTNAME=0.0.0.0' -e 'IMA ### Docker Compose & Caddy (推荐) -*如果不需要反向代理,需要设置`HOSTNAME=0.0.0.0`环境变量* +_如果不需要反向代理,需要设置`HOSTNAME=0.0.0.0`环境变量_ **docker-compose.yaml** ```yaml -version: '3.0' +version: "3.0" services: mail: @@ -73,4 +73,4 @@ services: mail.example.com { reverse_proxy 127.0.0.1:3002 } -``` \ No newline at end of file +``` diff --git a/lib/constant.ts b/lib/constant.ts index 7ff24fb..10ba24d 100644 --- a/lib/constant.ts +++ b/lib/constant.ts @@ -1,4 +1,4 @@ export const REFRESH_SECONDS = process.env.NODE_ENV === "development" ? 1000 : 10; -export const VERSION = "1.0.3"; +export const VERSION = "1.0.4";