This commit is contained in:
oiov
2025-05-25 15:15:45 +08:00
parent a5626ebefe
commit fff455312e
2 changed files with 51 additions and 49 deletions
+49 -47
View File
@@ -1,64 +1,66 @@
name: Build and Push Docker Image to GHCR
name: Build and Push Docker Image
on:
push:
branches:
- main
tags:
- 'v*.*.*'
pull_request:
branches:
- main
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/wrdo
workflow_dispatch:
inputs:
version:
description: '镜像版本号'
required: false
default: 'latest'
environment:
description: '部署环境'
required: false
default: 'production'
type: choice
options:
- production
- staging
- development
jobs:
build-and-push:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
# 检出代码
- name: Checkout repository
uses: actions/checkout@v4
# 设置 Docker Buildx(支持多平台构建)
- name: Checkout code
uses: actions/checkout@v3
# 设置 QEMU 以支持多平台构建
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
# 设置 Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# 登录到 GitHub Container Registry
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
uses: docker/setup-buildx-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# 提取 Docker 镜像元数据(标签、版本等)
- name: Extract Docker metadata
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
id: meta
uses: docker/metadata-action@v5
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
images: oiovwr/wrdo
tags: |
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
type=raw,value=${{ github.event.inputs.version || 'latest' }}
type=raw,value=latest
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }} # 仅在 push 时推送
push: true
platforms: linux/amd64,linux/arm64
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
+2 -2
View File
@@ -20,8 +20,8 @@ WORKDIR /app
RUN npm install -g pnpm
# ARG NEXT_PUBLIC_APP_URL="http://localhost:3000"
ARG RESEND_API_KEY="re_"
ARG DATABASE_URL=""
# ARG RESEND_API_KEY="re_"
# ARG DATABASE_URL=""
# ARG NEXT_PUBLIC_OPEN_SIGNUP="1"
# ARG GITHUB_TOKEN=""
# ARG AUTH_SECRET=""