This commit is contained in:
oiov
2025-05-25 17:01:06 +08:00
parent b9bf2733f9
commit 1eb7c71ff9
4 changed files with 62 additions and 75 deletions

7
.dockerignore Normal file
View File

@@ -0,0 +1,7 @@
# .dockerignore
# node_modules
# npm-debug.log
# README.md
# .env*
# .next
# .git

View File

@@ -1,69 +1,64 @@
name: Build and Push Docker Image
name: Build and Push Docker Image to GHCR
on:
push:
branches:
- '**'
workflow_dispatch:
inputs:
version:
description: '镜像版本号'
required: false
default: 'latest'
environment:
description: '部署环境'
required: false
default: 'production'
type: choice
options:
- production
- staging
- development
- main
tags:
- 'v*.*.*'
pull_request:
branches:
- main
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/wrdo
jobs:
build:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v3
# 设置 QEMU 以支持多平台构建
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
# 设置 Docker Buildx
# 检出代码
- name: Checkout repository
uses: actions/checkout@v4
# 设置 Docker Buildx支持多平台构建
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
# 登录到 GitHub Container Registry
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
driver-opts: |
image=moby/buildkit:master
network=host
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# 提取 Docker 镜像元数据(标签、版本等)
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: oiovwr/wrdo
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ github.event.inputs.version || 'latest' }}
type=raw,value=latest
- name: Build and push
uses: docker/build-push-action@v4
type=sha,format=short
type=ref,event=branch,prefix=
type=ref,event=tag
# 构建并推送 Docker 镜像
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }} # 仅在 push 时推送
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=${{ github.workflow }}-${{ github.ref }}
cache-to: type=gha,mode=max,scope=${{ github.workflow }}-${{ github.ref }}
build-args: |
ENVIRONMENT=${{ github.event.inputs.environment || 'production' }}
cache-from: type=gha
cache-to: type=gha,mode=max

View File

@@ -1,4 +1,4 @@
FROM node:22-alpine AS base
FROM node:20-alpine AS base
FROM base AS deps
RUN apk add --no-cache libc6-compat
@@ -19,21 +19,9 @@ WORKDIR /app
RUN npm install -g pnpm
# ARG NEXT_PUBLIC_APP_URL="http://localhost:3000"
# ARG RESEND_API_KEY="re_"
# ARG DATABASE_URL=""
# ARG NEXT_PUBLIC_OPEN_SIGNUP="1"
# ARG GITHUB_TOKEN=""
# ARG AUTH_SECRET=""
# ARG GOOGLE_CLIENT_ID=""
# ARG GOOGLE_CLIENT_SECRET=""
# ARG GITHUB_ID=""
# ARG GITHUB_SECRET=""
# ARG LinuxDo_CLIENT_ID=""
# ARG LinuxDo_CLIENT_SECRET=""
# ARG NEXT_PUBLIC_EMAIL_R2_DOMAIN=""
# ARG NEXT_PUBLIC_GOOGLE_ID=""
# ARG SCREENSHOTONE_BASE_URL=""
ARG NEXT_PUBLIC_APP_URL="http://localhost:3000"
ARG RESEND_API_KEY=""
ARG DATABASE_URL=""
COPY --from=deps /app/node_modules ./node_modules
COPY . .

View File

@@ -1,13 +1,11 @@
version: "3.8"
services:
app:
build:
context: .
dockerfile: Dockerfile
args:
RESEND_API_KEY: ${RESEND_API_KEY}
# image: ghcr.io/oiov/wr.do/wrdo:${TAG:-latest}
# build:
# context: .
# dockerfile: Dockerfile
# args:
# RESEND_API_KEY: ${RESEND_API_KEY}
image: ghcr.io/oiov/wr.do/wrdo:${TAG:-latest}
container_name: wrdo
ports:
- "3000:3000"
@@ -36,7 +34,6 @@ services:
networks:
- wrdo-network
restart: unless-stopped
# command: ["bash", "-c", "pnpm db:push && node server.js"]
# If you want to use local database, uncomment the following line
# postgres: