diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 537c08f..ddc7f09 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,11 +24,32 @@ jobs: - name: Get dependencies and build run: | sudo apt-get update - sh -c "$(curl -sSL https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin - task release + sudo apt-get -y install gcc-mingw-w64-x86-64 + sudo apt-get -y install gcc-arm-linux-gnueabihf libc6-dev-armhf-cross + sudo apt-get -y install gcc-aarch64-linux-gnu libc6-dev-arm64-cross + chmod +x ./build.sh + ./build.sh -r b - - name: Upload binary files - uses: actions/upload-artifact@v3 + - name: Upload binary files (windows_amd64) + uses: actions/upload-artifact@v2 with: - name: release_artifacts - path: release/* \ No newline at end of file + name: cloudreve_windows_amd64 + path: release/cloudreve*windows_amd64.* + + - name: Upload binary files (linux_amd64) + uses: actions/upload-artifact@v2 + with: + name: cloudreve_linux_amd64 + path: release/cloudreve*linux_amd64.* + + - name: Upload binary files (linux_arm) + uses: actions/upload-artifact@v2 + with: + name: cloudreve_linux_arm + path: release/cloudreve*linux_arm.* + + - name: Upload binary files (linux_arm64) + uses: actions/upload-artifact@v2 + with: + name: cloudreve_linux_arm64 + path: release/cloudreve*linux_arm64.* diff --git a/Dockerfile b/Dockerfile index a66d1ad..d3d5caa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,59 +1,49 @@ # the frontend builder # cloudreve need node.js 16* to build frontend, -# !!! Doesn't require any cleanup, as multi-stage builds are removed after completion -FROM node:16-alpine as frontend_builder +# separate build step and custom image tag will resolve this +FROM node:16-alpine as cloudreve_frontend_builder -RUN set -e \ - && apk update \ - && apk add bash wget curl git zip \ - && sh -c "$(curl -sSL https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin -# Maybe copying the current directory is more accurate? -# && git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git /cloudreve +RUN apk update \ + && apk add --no-cache wget curl git yarn zip bash \ + && git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git /cloudreve_frontend -COPY . /cloudreve - -WORKDIR /cloudreve - -RUN task clean-frontend build-frontend +# build frontend assets using build script, make sure all the steps just follow the regular release +WORKDIR /cloudreve_frontend +ENV GENERATE_SOURCEMAP false +RUN chmod +x ./build.sh && ./build.sh -a # the backend builder # cloudreve backend needs golang 1.18* to build -# !!! Doesn't require any cleanup, as multi-stage builds are removed after completion -FROM golang:1.18-alpine as backend_builder +FROM golang:1.18-alpine as cloudreve_backend_builder # install dependencies and build tools -RUN set -e \ - && apk update \ - && apk add bash wget curl git build-base \ - && sh -c "$(curl -sSL https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin -# Maybe copying the current directory is more accurate? -# && git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git /cloudreve +RUN apk update \ + # install dependencies and build tools + && apk add --no-cache wget curl git build-base gcc abuild binutils binutils-doc gcc-doc zip bash \ + && git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git /cloudreve_backend -COPY . /cloudreve - -WORKDIR /cloudreve +WORKDIR /cloudreve_backend +COPY --from=cloudreve_frontend_builder /cloudreve_frontend/assets.zip ./ +RUN chmod +x ./build.sh && ./build.sh -c -COPY --from=frontend_builder /cloudreve/assets.zip ./ -RUN task clean-backend build-backend "PLATFORM=docker" - - -# the final builder +# TODO: merge the frontend build and backend build into a single one image +# the final published image FROM alpine:latest WORKDIR /cloudreve +COPY --from=cloudreve_backend_builder /cloudreve_backend/cloudreve ./cloudreve -COPY --from=backend_builder /cloudreve/release/cloudreve-docker ./cloudreve - -# !!! For i18n users, do not set timezone -RUN set -e \ - && apk update \ - && apk add bash ca-certificates tzdata \ - && rm -f /var/cache/apk/* +RUN apk update \ + && apk add --no-cache tzdata \ + && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ + && echo "Asia/Shanghai" > /etc/timezone \ + && chmod +x ./cloudreve \ + && mkdir -p /data/aria2 \ + && chmod -R 766 /data/aria2 EXPOSE 5212 - VOLUME ["/cloudreve/uploads", "/cloudreve/avatar", "/data"] ENTRYPOINT ["./cloudreve"] diff --git a/README.md b/README.md index 03d3553..58e6b60 100644 --- a/README.md +++ b/README.md @@ -74,75 +74,50 @@ The above is a minimum deploy example, you can refer to [Getting started](https: ## :gear: Build -You need to have `Go >= 1.18`, `node.js`, `yarn`, `curl`, `zip`, `go-task` and other necessary dependencies before you can build it yourself. +You need to have `Go >= 1.18`, `node.js`, `yarn`, `zip` and other necessary dependencies before you can build it yourself. -#### Install go-task +#### Clone the code ```shell -sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin +git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git ``` -For more installation methods, please refer to the official documentation: [https://taskfile.dev/installation/](https://taskfile.dev/installation/) - -#### Clone the code +#### Build static resources ```shell -git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git +# Enter frontend sub-module +cd assets +# Install dependencies +yarn install +# Start building +yarn run build +# Delete unused map files +cd build +find . -name "*.map" -type f -delete +# Return to main folder to pack static files +cd ../../ +zip -r - assets/build >assets.zip ``` #### Compile ```shell -# Enter the project directory -cd Cloudreve - -# Execute the task command -# Note: The `task` command executes the task named `default` by default. -task +# Obtain version number, commit SHA +export COMMIT_SHA=$(git rev-parse --short HEAD) +export VERSION=$(git describe --tags) -# View compiled files -ls release +# Compile +go build -a -o cloudreve -ldflags "-s -w -X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.BackendVersion=$VERSION' -X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.LastCommit=$COMMIT_SHA'" ``` -If you want to compile only the frontend code, please execute `task build-frontend`; similarly you can also execute `task build-backend` to only compile the backend code. - -You can view all supported tasks through the `task --list` command: +You can also start a quick build using `build.sh` in the project root directory: ```shell -~/Cloudreve ❯❯❯ task --list ✘ 146 master -task: Available tasks for this project: -* all: Build All Platform -* build: Build Cloudreve -* build-backend: Build Backend -* build-frontend: Build Frontend -* clean: Clean All Build Cache -* clean-backend: Clean Backend Build Cache -* clean-frontend: Clean Frontend Build Cache -* darwin-amd64: Build Backend(darwin-amd64) -* darwin-amd64-v2: Build Backend(darwin-amd64-v2) -* darwin-amd64-v3: Build Backend(darwin-amd64-v3) -* darwin-amd64-v4: Build Backend(darwin-amd64-v4) -* darwin-arm64: Build Backend(darwin-arm64) -* freebsd-386: Build Backend(freebsd-386) -* freebsd-amd64: Build Backend(freebsd-amd64) -* freebsd-amd64-v2: Build Backend(freebsd-amd64-v2) -* freebsd-amd64-v3: Build Backend(freebsd-amd64-v3) -* freebsd-amd64-v4: Build Backend(freebsd-amd64-v4) -* freebsd-arm: Build Backend(freebsd-arm) -* freebsd-arm64: Build Backend(freebsd-arm64) -* linux-amd64: Build Backend(linux-amd64) -* linux-amd64-v2: Build Backend(linux-amd64-v2) -* linux-amd64-v3: Build Backend(linux-amd64-v3) -* linux-amd64-v4: Build Backend(linux-amd64-v4) -* linux-armv5: Build Backend(linux-armv5) -* linux-armv6: Build Backend(linux-armv6) -* linux-armv7: Build Backend(linux-armv7) -* linux-armv8: Build Backend(linux-armv8) -* windows-amd64: Build Backend(windows-amd64) -* windows-amd64-v2: Build Backend(windows-amd64-v2) -* windows-amd64-v3: Build Backend(windows-amd64-v3) -* windows-amd64-v4: Build Backend(windows-amd64-v4) -* windows-arm64: Build Backend(windows-arm64) +./build.sh [-a] [-c] [-b] [-r] + a - Build assets + c - Build binary backend + b - Build both assets and backend + r - Cross-compilation for final release ``` ## :alembic: Stacks diff --git a/README_zh-CN.md b/README_zh-CN.md index a383479..a2056ab 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -74,75 +74,50 @@ chmod +x ./cloudreve ## :gear: 构建 -自行构建前需要拥有 `Go >= 1.18`、`node.js`、`yarn`、`curl`、`zip`、`go-task` 等必要依赖。 +自行构建前需要拥有 `Go >= 1.18`、`node.js`、`yarn`、`zip` 等必要依赖。 -#### 安装 go-task +#### 克隆代码 ```shell -sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin +git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git ``` -对于其他平台或者其他安装方式, 请参考官方安装文档: [https://taskfile.dev/installation/](https://taskfile.dev/installation/) - -#### 克隆代码 +#### 构建静态资源 ```shell -git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git +# 进入前端子模块 +cd assets +# 安装依赖 +yarn install +# 开始构建 +yarn run build +# 构建完成后删除映射文件 +cd build +find . -name "*.map" -type f -delete +# 返回项目主目录打包静态资源 +cd ../../ +zip -r - assets/build >assets.zip ``` #### 编译项目 ```shell -# 进入项目目录 -cd Cloudreve - -# 执行 task 命令 -# 提示: 单独执行 `task` 命令实际上默认执行叫做 `default` 的 task -task +# 获得当前版本号、Commit +export COMMIT_SHA=$(git rev-parse --short HEAD) +export VERSION=$(git describe --tags) -# 查看已编译好的文件 -ls release +# 开始编译 +go build -a -o cloudreve -ldflags "-s -w -X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.BackendVersion=$VERSION' -X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.LastCommit=$COMMIT_SHA'" ``` -如果你期望单独编译前端代码, 请执行 `task build-frontend` 命令; 同样你可以通过执行 `task build-backend` 命令单独编译后端代码. - -你可以通过执行 `task --list` 命令查看所以已支持的 task. +你也可以使用项目根目录下的 `build.sh` 快速开始构建: ```shell -~/Cloudreve ❯❯❯ task --list ✘ 146 master ✱ -task: Available tasks for this project: -* all: Build All Platform -* build: Build Cloudreve -* build-backend: Build Backend -* build-frontend: Build Frontend -* clean: Clean All Build Cache -* clean-backend: Clean Backend Build Cache -* clean-frontend: Clean Frontend Build Cache -* darwin-amd64: Build Backend(darwin-amd64) -* darwin-amd64-v2: Build Backend(darwin-amd64-v2) -* darwin-amd64-v3: Build Backend(darwin-amd64-v3) -* darwin-amd64-v4: Build Backend(darwin-amd64-v4) -* darwin-arm64: Build Backend(darwin-arm64) -* freebsd-386: Build Backend(freebsd-386) -* freebsd-amd64: Build Backend(freebsd-amd64) -* freebsd-amd64-v2: Build Backend(freebsd-amd64-v2) -* freebsd-amd64-v3: Build Backend(freebsd-amd64-v3) -* freebsd-amd64-v4: Build Backend(freebsd-amd64-v4) -* freebsd-arm: Build Backend(freebsd-arm) -* freebsd-arm64: Build Backend(freebsd-arm64) -* linux-amd64: Build Backend(linux-amd64) -* linux-amd64-v2: Build Backend(linux-amd64-v2) -* linux-amd64-v3: Build Backend(linux-amd64-v3) -* linux-amd64-v4: Build Backend(linux-amd64-v4) -* linux-armv5: Build Backend(linux-armv5) -* linux-armv6: Build Backend(linux-armv6) -* linux-armv7: Build Backend(linux-armv7) -* linux-armv8: Build Backend(linux-armv8) -* windows-amd64: Build Backend(windows-amd64) -* windows-amd64-v2: Build Backend(windows-amd64-v2) -* windows-amd64-v3: Build Backend(windows-amd64-v3) -* windows-amd64-v4: Build Backend(windows-amd64-v4) -* windows-arm64: Build Backend(windows-arm64) +./build.sh [-a] [-c] [-b] [-r] + a - 构建静态资源 + c - 编译二进制文件 + b - 构建前端 + 编译二进制文件 + r - 交叉编译,构建用于release的版本 ``` ## :alembic: 技术栈 diff --git a/Taskfile.yaml b/Taskfile.yaml deleted file mode 100644 index 7586ab0..0000000 --- a/Taskfile.yaml +++ /dev/null @@ -1,428 +0,0 @@ -version: '3' - -vars: - VERSION: - sh: git describe --tags --always - COMMIT_SHA: - sh: git rev-parse --short HEAD - CGO_ENABLED: 0 - DEFAULT_PLATFORM: "{{OS}}-{{ARCH}}" - -tasks: - clean-frontend: - desc: Clean Frontend Build Cache - cmds: - - rm -rf assets/build assets.zip - status: - - test ! -d assets/build - - test ! -f assets.zip - - clean-backend: - desc: Clean Backend Build Cache - cmds: - - rm -rf release - status: - - test ! -d release - - clean: - desc: Clean All Build Cache - cmds: - - task: clean-frontend - - task: clean-backend - - mkdir: - cmds: - - mkdir -p release - status: - - test -d release - - build-frontend: - desc: Build Frontend - env: - GENERATE_SOURCEMAP: false - dir: assets - cmds: - - env CI=false - - yarn install --network-timeout 1000000 - - yarn build - - cd .. && zip -r - assets/build > assets.zip - status: - - test -d build - - build-backend: - desc: Build Backend - label: build-{{.PLATFORM | default "backend"}} - cmds: - - task: mkdir - - | - GOOS={{.GOOS}} GOARCH={{.GOARCH}} GOARM={{.GOARM}} GOMIPS={{.GOMIPS}} CGO_ENABLED={{.CGO_ENABLED}} CC={{.CC}} \ - go build -trimpath -o release/cloudreve-{{.PLATFORM}}{{.BINEXT}} -ldflags \ - "-w -s -X github.com/cloudreve/Cloudreve/v3/pkg/conf.BackendVersion={{.VERSION}} \ - -X github.com/cloudreve/Cloudreve/v3/pkg/conf.LastCommit={{.COMMIT_SHA}}" - - - linux-amd64: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: linux, - GOARCH: amd64 - } - linux-amd64-v2: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: linux, - GOARCH: amd64, - GOAMD64: v2 - } - linux-amd64-v3: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: linux, - GOARCH: amd64, - GOAMD64: v3 - } - linux-amd64-v4: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: linux, - GOARCH: amd64, - GOAMD64: v4 - } - linux-armv5: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: linux, - GOARCH: arm, - GOARM: 5 - } - linux-armv6: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: linux, - GOARCH: arm, - GOARM: 6 - } - linux-armv7: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: linux, - GOARCH: arm, - GOARM: 7 - } - linux-armv8: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: linux, - GOARCH: arm64 - } -# -# !!! modernc.org/libc doesn't support mips architecture yet -# -# linux-mips-hardfloat: -# desc: Build Backend({{.TASK}}) -# cmds: -# - task: build-backend -# vars: { -# PLATFORM: "{{.TASK}}", -# GOOS: linux, -# GOARCH: mips, -# GOMIPS: hardfloat -# } -# linux-mipsle-softfloat: -# desc: Build Backend({{.TASK}}) -# cmds: -# - task: build-backend -# vars: { -# PLATFORM: "{{.TASK}}", -# GOOS: linux, -# GOARCH: mipsle, -# GOMIPS: softfloat -# } -# linux-mipsle-hardfloat: -# desc: Build Backend({{.TASK}}) -# cmds: -# - task: build-backend -# vars: { -# PLATFORM: "{{.TASK}}", -# GOOS: linux, -# GOARCH: mipsle, -# GOMIPS: hardfloat -# } -# linux-mips64: -# desc: Build Backend({{.TASK}}) -# cmds: -# - task: build-backend -# vars: { -# PLATFORM: "{{.TASK}}", -# GOOS: linux, -# GOARCH: mips64 -# } -# linux-mips64le: -# desc: Build Backend({{.TASK}}) -# cmds: -# - task: build-backend -# vars: { -# PLATFORM: "{{.TASK}}", -# GOOS: linux, -# GOARCH: mips64le -# } - darwin-amd64: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: darwin, - GOARCH: amd64 - } - darwin-amd64-v2: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: darwin, - GOARCH: amd64, - GOAMD64: v2 - } - darwin-amd64-v3: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: darwin, - GOARCH: amd64, - GOAMD64: v3 - } - darwin-amd64-v4: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: darwin, - GOARCH: amd64, - GOAMD64: v4 - } - darwin-arm64: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: darwin, - GOARCH: arm64 - } - freebsd-386: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: freebsd, - GOARCH: 386 - } - freebsd-amd64: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: freebsd, - GOARCH: amd64 - } - freebsd-amd64-v2: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: freebsd, - GOARCH: amd64, - GOAMD64: v2 - } - freebsd-amd64-v3: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: freebsd, - GOARCH: amd64, - GOAMD64: v3 - } - freebsd-amd64-v4: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: freebsd, - GOARCH: amd64, - GOAMD64: v4 - } - freebsd-arm: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: freebsd, - GOARCH: arm - } - freebsd-arm64: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - GOOS: freebsd, - GOARCH: arm64 - } -# -# The sqlite library does not support the windows 386 architecture -# https://gitlab.com/cznic/sqlite/-/issues/86 -# -# windows-386: -# cmds: -# - task: build-backend -# vars: { -# PLATFORM: "{{.TASK}}", -# BINEXT: ".exe", -# GOOS: windows, -# GOARCH: 386 -# } - windows-amd64: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - BINEXT: ".exe", - GOOS: windows, - GOARCH: amd64 - } - windows-amd64-v2: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - BINEXT: ".exe", - GOOS: windows, - GOARCH: amd64, - GOAMD64: v2 - } - windows-amd64-v3: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - BINEXT: ".exe", - GOOS: windows, - GOARCH: amd64, - GOAMD64: v3 - } - windows-amd64-v4: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - BINEXT: ".exe", - GOOS: windows, - GOARCH: amd64, - GOAMD64: v4 - } - windows-arm64: - desc: Build Backend({{.TASK}}) - cmds: - - task: build-backend - vars: { - PLATFORM: "{{.TASK}}", - BINEXT: ".exe", - GOOS: windows, - GOARCH: arm64 - } - - build: - desc: Build Cloudreve - cmds: - - task: clean - - task: build-frontend - - task: build-backend - vars: { - PLATFORM: "{{.DEFAULT_PLATFORM}}", - BINEXT: "{{exeExt}}" - } - - default: - cmds: - - task: build - - all: - desc: Build All Platform - cmds: - - task: clean - - task: build-frontend - - task: linux-amd64 - - task: linux-amd64-v2 - - task: linux-amd64-v3 - - task: linux-amd64-v4 - - task: linux-armv5 - - task: linux-armv6 - - task: linux-armv7 - - task: linux-armv8 - - task: darwin-amd64 - - task: darwin-amd64-v2 - - task: darwin-amd64-v3 - - task: darwin-amd64-v4 - - task: darwin-arm64 - - task: windows-amd64 - - task: windows-amd64-v2 - - task: windows-amd64-v3 - - task: windows-amd64-v4 - - task: windows-arm64 - - release: - desc: Build common platforms for release - env: - RELEASE_PACKING: true - cmds: - - task: clean - - task: build-frontend - - task: linux-amd64 - - task: linux-armv5 - - task: linux-armv6 - - task: linux-armv7 - - task: linux-armv8 - - task: darwin-amd64 - - task: darwin-arm64 - - task: windows-amd64 - - task: windows-arm64 \ No newline at end of file diff --git a/assets b/assets index d4dc124..09a5168 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit d4dc124e9986d18096d54ec6f2b4b283de1536cc +Subproject commit 09a5168b23349cb1d0201b544ba48ccb583886be