Skip to content

Commit

Permalink
build: add Dockerfile and GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
sunls24 committed Jun 23, 2024
1 parent 9bf8c40 commit 4157130
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 54 deletions.
39 changes: 19 additions & 20 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
name: Publish Docker image
name: Build Docker Images

on:
workflow_dispatch:
release:
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:
images: sunls24/temporary-mail
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
cache-to: type=gha,mode=max
42 changes: 20 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand All @@ -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"]
EXPOSE 3000
ENV PORT 3000
CMD HOSTNAME="127.0.0.1" node server.js
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@

- **❗接收到的邮件内容仅能保留10天**
- **❗随机生成的邮箱地址任何人都可以使用,请勿用于注册重要账号**


2 changes: 1 addition & 1 deletion app/api/config/route.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
4 changes: 2 additions & 2 deletions app/api/count/route.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
12 changes: 6 additions & 6 deletions deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

2. 然后需要添加一条`Catch-All`的规则到目标邮箱中,如图:

此处需要一个自己的邮箱作为目标邮箱,推荐使用 Outlook *(环境变量配置也是基于此邮箱)*
此处需要一个自己的邮箱作为目标邮箱,推荐使用 Outlook _(环境变量配置也是基于此邮箱)_

![email-routing.png](doc/email-routing.png)

## 配置邮件接收规则

默认会从垃圾邮件`Junk`文件夹中获取,可通过`IMAP_PATH`环境变量指定。

需要添加一个或多个邮件规则,将接收到的目标邮件移动到指定的文件夹下 *(需要将图中的`.eu.org`替换为自己的域名,可配置多个)*
需要添加一个或多个邮件规则,将接收到的目标邮件移动到指定的文件夹下 _(需要将图中的`.eu.org`替换为自己的域名,可配置多个)_

![rule.png](doc/rule.png)

Expand All @@ -38,7 +38,7 @@

## 部署

*请修改其中的环境变量配置*
_请修改其中的环境变量配置_

### Docker

Expand All @@ -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:
Expand All @@ -73,4 +73,4 @@ services:
mail.example.com {
reverse_proxy 127.0.0.1:3002
}
```
```
2 changes: 1 addition & 1 deletion lib/constant.ts
Original file line number Diff line number Diff line change
@@ -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";

0 comments on commit 4157130

Please sign in to comment.