Skip to content

Building from Source Code ​

Cloudreve project mainly consists of two parts: the backend main repository cloudreve/Cloudreve, and the frontend repository cloudreve/frontend. Before compiling the Cloudreve backend, you need to build the frontend submodule in the assets directory first, then use embed to embed it into the backend executable.

Installing Dependencies ​

Cloning the Repository ​

bash
# Clone the repository
git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git

# Enter the project directory
cd Cloudreve

# Check out the version you want to compile
git checkout 4.x.x

Building the Frontend ​

bash
# Get current version number and commit
export COMMIT_SHA=$(git rev-parse --short HEAD)
export VERSION=$(git describe --tags)

chmod +x ./.build/build-assets.sh

# Build the frontend
./.build/build-assets.sh $VERSION

The compiled frontend resource package is located at application/statics/assets.zip.

Pro

For Pro edition users, please download the frontend source code from the license management dashboard, then manually build it in the source code directory:

bash
# Install dependencies
yarn install

# Mark version for frontend
yarn version --new-version 4.x.x --no-git-tag-version

# Build the frontend
yarn run build

The build output is in the build directory.

Building the Final Executable ​

bash
# Start compiling
go build -a -o cloudreve \
    -ldflags "-s -w -X 'github.com/cloudreve/Cloudreve/v4/application/constants.BackendVersion=$VERSION' -X 'github.com/cloudreve/Cloudreve/v4/application/constants.LastCommit=$COMMIT_SHA'"

After compilation, the final executable cloudreve will be generated in the project root directory.

Build Helper ​

You can use goreleaser to quickly complete building, packaging, and other operations. Usage is as follows:

bash
# Install goreleaser
go install github.com/goreleaser/goreleaser/v2@latest

# Build the project
goreleaser build --clean --single-target --snapshot

Or cross-compile all available versions:

bash
goreleaser build --clean --snapshot