From 7b2f7af77c7b03b80294266877a7a3526d228b7f Mon Sep 17 00:00:00 2001 From: Yuzhong Zhang <141388234+BetterAndBetterII@users.noreply.github.com> Date: Mon, 23 Jun 2025 12:34:34 +0800 Subject: [PATCH] fix --- .github/workflows/docker-build.yml | 31 -------------------- README.md | 46 +++++++++++++++++++----------- excalidraw-complete.Dockerfile | 31 ++++++++++++++++---- ui-build.Dockerfile | 12 -------- 4 files changed, 55 insertions(+), 65 deletions(-) delete mode 100644 ui-build.Dockerfile diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 38d9b88..8973909 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -11,32 +11,7 @@ env: OWNER: betterandbetterii jobs: - build-frontend: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Apply frontend patch - run: | - cd excalidraw - git apply ../frontend.patch - - - name: Build frontend - run: | - docker build -t excalidraw-ui-build excalidraw -f ui-build.Dockerfile - docker run -v ${PWD}/:/pwd/ excalidraw-ui-build cp -r /frontend /pwd - - - name: Upload frontend artifact - uses: actions/upload-artifact@v4 - with: - name: frontend - path: frontend/ - build-and-push: - needs: build-frontend runs-on: ubuntu-latest permissions: contents: read @@ -48,12 +23,6 @@ jobs: with: submodules: recursive - - name: Download frontend artifact - uses: actions/download-artifact@v4 - with: - name: frontend - path: frontend/ - - name: Log in to Container Registry uses: docker/login-action@v3 with: diff --git a/README.md b/README.md index f592a28..5e94ca1 100644 --- a/README.md +++ b/README.md @@ -39,35 +39,47 @@ These flexible configurations ensure Excalidraw Complete fits seamlessly into yo Interested in contributing or customizing? Build Excalidraw Complete from source with these steps: +### Using Docker (Recommended) + +```bash +# Clone the repository with submodules +git clone https://github.com/PatWie/excalidraw-complete.git --recursive +cd excalidraw-complete + +# Build the Docker image (includes frontend and backend) +docker build -t excalidraw-complete -f excalidraw-complete.Dockerfile . + +# Run the container +docker run -p 3002:3002 excalidraw-complete +``` + +### Manual Build + ```bash # Clone and prepare the Excalidraw frontend git clone https://github.com/PatWie/excalidraw-complete.git --recursive cd ./excalidraw-complete/excalidraw -# git checkout tags/v0.17.3 -# Fix docker build (fix already implemented upstream) -# git remote add jcobol https://github.com/jcobol/excalidraw -# git fetch jcobol -# git checkout 7582_fix_docker_build - -# Adjust URLs inside of frontend.patch if you want to use a reverse proxy +# Apply frontend patches git apply ../frontend.patch -cd ../ -git checkout dev -docker build -t exalidraw-ui-build excalidraw -f ui-build.Dockerfile -docker run -v ${PWD}/:/pwd/ -it exalidraw-ui-build cp -r /frontend /pwd + +# Build frontend +npm install +cd excalidraw-app +npm run build:app:docker +cd ../../ + +# Copy frontend build to correct location +cp -r excalidraw/excalidraw-app/build frontend/ + +# Build Go application +go build -o excalidraw-complete main.go ``` (Optional) Replace `localhost:3002` inside of `main.go` with your domain name if you want to use a reverse proxy (Optional) Replace `"ssl=!0", "ssl=0"` with `"ssl=!0", "ssl=1"` if you want to use HTTPS (Optional) Replace `"ssl:!0", "ssl:0"` with `"ssl:!0", "ssl:1"` if you want to use HTTPS -Compile the Go application: - -```bash -go build -o excalidraw-complete main.go -``` - Declare environment variables if you want any (see section above) Example: `STORAGE_TYPE=sqlite DATA_SOURCE_NAME=/tmp/excalidb.sqlite` diff --git a/excalidraw-complete.Dockerfile b/excalidraw-complete.Dockerfile index 6892570..9939d89 100644 --- a/excalidraw-complete.Dockerfile +++ b/excalidraw-complete.Dockerfile @@ -1,14 +1,35 @@ -FROM golang:alpine as builder +# 前端构建阶段 +FROM node:18 AS frontend-builder +WORKDIR /app +# 复制 excalidraw 子模块 +COPY excalidraw/ ./excalidraw/ +# 复制补丁文件 +COPY frontend.patch ./ +# 应用前端补丁 +RUN cd excalidraw && git apply ../frontend.patch +# 构建前端 +RUN cd excalidraw && npm install && cd excalidraw-app && npm run build:app:docker + +# 后端构建阶段 +FROM golang:alpine AS backend-builder RUN apk update && apk add --no-cache git WORKDIR /app -COPY go.mod ./ +# 复制 Go 模块文件 +COPY go.mod go.sum ./ RUN GOPROXY=direct go mod download +# 复制源代码 COPY . . +# 复制前端构建文件到正确位置,以便 Go embed 可以找到 +COPY --from=frontend-builder /app/excalidraw/excalidraw-app/build ./frontend/ +# 构建 Go 应用 RUN GOPROXY=direct CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main . -FROM alpine +# 最终运行镜像 +FROM alpine:latest +RUN apk --no-cache add ca-certificates WORKDIR /root/ -COPY --from=builder /app/main . -# COPY --from=builder /app/.env . +# 复制后端二进制文件(已包含嵌入的前端文件) +COPY --from=backend-builder /app/main . +# 暴露端口 EXPOSE 3002 CMD ["./main"] diff --git a/ui-build.Dockerfile b/ui-build.Dockerfile deleted file mode 100644 index a5b0ad0..0000000 --- a/ui-build.Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -FROM node:18 AS build - -WORKDIR /home/node/app - -COPY . . - -RUN npm install -RUN cd excalidraw-app && npm run build:app:docker - -FROM ubuntu:20.04 -COPY --from=build /home/node/app/excalidraw-app/build /frontend -