build: 分离开发与发布环境的 Docker 构建配置
Docker Build and Push / build (push) Has been cancelled
custom-deploy-your-server / build-deploy (push) Has been cancelled
deploy-demo-site / build-deploy (push) Has been cancelled
Deploy Docs to GitHub Pages / build (push) Has been cancelled
Deploy Docs to GitHub Pages / Deploy (push) Has been cancelled
Docker Build and Push / build (push) Has been cancelled
custom-deploy-your-server / build-deploy (push) Has been cancelled
deploy-demo-site / build-deploy (push) Has been cancelled
Deploy Docs to GitHub Pages / build (push) Has been cancelled
Deploy Docs to GitHub Pages / Deploy (push) Has been cancelled
- 新增 Dockerfile.release 用于生产环境,仅包含运行所需的最小依赖 - 重构原 Dockerfile 为多阶段构建,集成前端构建与后端编译 - 更新 .goreleaser.yaml 以使用新的发布镜像配置 - 新增 GitHub Actions 工作流用于自动构建和推送 Docker 镜像
This commit is contained in:
@@ -0,0 +1,62 @@
|
|||||||
|
name: Docker Build and Push
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "main", "master" ]
|
||||||
|
paths-ignore:
|
||||||
|
- 'docs/**'
|
||||||
|
- '**.md'
|
||||||
|
pull_request:
|
||||||
|
branches: [ "main", "master" ]
|
||||||
|
paths-ignore:
|
||||||
|
- 'docs/**'
|
||||||
|
- '**.md'
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
# Use message-nest to match release workflow naming, or use ${{ github.repository }} for default
|
||||||
|
IMAGE_NAME: message-nest
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Log in to the Container registry
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract metadata (tags, labels) for Docker
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
|
||||||
|
tags: |
|
||||||
|
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' }}
|
||||||
|
type=ref,event=branch
|
||||||
|
type=ref,event=pr
|
||||||
|
type=sha
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Dockerfile
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
+3
-3
@@ -37,7 +37,7 @@ dockers:
|
|||||||
- image_templates:
|
- image_templates:
|
||||||
- "docker.io/engigu/{{ .Env.DOCKER_IMAGE_NAME }}:{{ .Version }}-amd64"
|
- "docker.io/engigu/{{ .Env.DOCKER_IMAGE_NAME }}:{{ .Version }}-amd64"
|
||||||
- "ghcr.io/engigu/{{ .Env.DOCKER_IMAGE_NAME }}:{{ .Version }}-amd64"
|
- "ghcr.io/engigu/{{ .Env.DOCKER_IMAGE_NAME }}:{{ .Version }}-amd64"
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile.release
|
||||||
extra_files:
|
extra_files:
|
||||||
- LICENSE
|
- LICENSE
|
||||||
- README.md
|
- README.md
|
||||||
@@ -56,7 +56,7 @@ dockers:
|
|||||||
- "docker.io/engigu/{{ .Env.DOCKER_IMAGE_NAME }}:{{ .Version }}-arm64v8"
|
- "docker.io/engigu/{{ .Env.DOCKER_IMAGE_NAME }}:{{ .Version }}-arm64v8"
|
||||||
- "ghcr.io/engigu/{{ .Env.DOCKER_IMAGE_NAME }}:{{ .Version }}-arm64v8"
|
- "ghcr.io/engigu/{{ .Env.DOCKER_IMAGE_NAME }}:{{ .Version }}-arm64v8"
|
||||||
goarch: arm64
|
goarch: arm64
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile.release
|
||||||
extra_files:
|
extra_files:
|
||||||
- LICENSE
|
- LICENSE
|
||||||
- README.md
|
- README.md
|
||||||
@@ -76,7 +76,7 @@ dockers:
|
|||||||
- "ghcr.io/engigu/{{ .Env.DOCKER_IMAGE_NAME }}:{{ .Version }}-armv7"
|
- "ghcr.io/engigu/{{ .Env.DOCKER_IMAGE_NAME }}:{{ .Version }}-armv7"
|
||||||
goarch: arm
|
goarch: arm
|
||||||
goarm: 7
|
goarm: 7
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile.release
|
||||||
extra_files:
|
extra_files:
|
||||||
- LICENSE
|
- LICENSE
|
||||||
- README.md
|
- README.md
|
||||||
|
|||||||
+56
-8
@@ -1,16 +1,64 @@
|
|||||||
FROM debian:latest
|
# Stage 1: Build Frontend
|
||||||
|
FROM node:20-alpine AS frontend-builder
|
||||||
|
|
||||||
|
WORKDIR /web
|
||||||
|
|
||||||
|
# Copy package files first for caching
|
||||||
|
COPY web/package*.json ./
|
||||||
|
COPY web/tsconfig*.json ./
|
||||||
|
COPY web/vite.config.ts ./
|
||||||
|
COPY web/index.html ./
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
# Copy source code
|
||||||
|
COPY web/ ./
|
||||||
|
|
||||||
|
# Build frontend
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Stage 2: Build Backend
|
||||||
|
FROM golang:1.24 AS backend-builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy Go module files
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# Copy source code
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Copy frontend build artifacts to the location expected by go:embed
|
||||||
|
# The embed directive in main.go is //go:embed web/dist/*
|
||||||
|
COPY --from=frontend-builder /web/dist ./web/dist
|
||||||
|
|
||||||
|
# Build the binary
|
||||||
|
# CGO_ENABLED=0 for static binary
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux go build -o Message-Nest main.go
|
||||||
|
|
||||||
|
# Stage 3: Runtime
|
||||||
|
FROM debian:stable-slim
|
||||||
|
|
||||||
ENV TZ=Asia/Shanghai
|
ENV TZ=Asia/Shanghai
|
||||||
|
|
||||||
RUN apt update \
|
RUN apt-get update \
|
||||||
&& apt install -y ca-certificates \
|
&& apt-get install -y ca-certificates tzdata \
|
||||||
&& update-ca-certificates \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
COPY ./ /app/
|
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy binary
|
||||||
|
COPY --from=backend-builder /app/Message-Nest .
|
||||||
|
|
||||||
|
# Copy configuration directory (contains app.example.ini)
|
||||||
|
COPY --from=backend-builder /app/conf ./conf
|
||||||
|
|
||||||
|
# Copy other necessary files
|
||||||
|
COPY --from=backend-builder /app/LICENSE .
|
||||||
|
COPY --from=backend-builder /app/README.md .
|
||||||
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
CMD ["/app/Message-Nest"]
|
CMD ["./Message-Nest"]
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
FROM debian:latest
|
||||||
|
|
||||||
|
ENV TZ=Asia/Shanghai
|
||||||
|
|
||||||
|
RUN apt update \
|
||||||
|
&& apt install -y ca-certificates \
|
||||||
|
&& update-ca-certificates \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
COPY ./ /app/
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
|
CMD ["/app/Message-Nest"]
|
||||||
|
|
||||||
Reference in New Issue
Block a user