docs: build with docker (#78).

This commit is contained in:
Wine93 2025-03-04 14:22:12 +08:00
parent c3a16b5cd8
commit 1a20ed5476
3 changed files with 131 additions and 1 deletions

View File

@ -85,7 +85,7 @@ Install other build prerequisites:
- [`libfuse`](https://github.com/libfuse/libfuse/releases/tag/fuse-3.16.1) 3.16.1 or newer version
- [FoundationDB](https://apple.github.io/foundationdb/getting-started-linux.html) 7.1 or newer version
- [Rust](https://www.rust-lang.org/tools/install) toolchain: minimal 1.75.0, recommanded 1.85.0 or newer version (latest stable version)
- [Rust](https://www.rust-lang.org/tools/install) toolchain: minimal 1.75.0, recommanded 1.85.0 or newer version (latest stable version)
## Build 3FS
@ -94,6 +94,8 @@ Build 3FS in `build` folder:
cmake -S . -B build -DCMAKE_CXX_COMPILER=clang++-14 -DCMAKE_C_COMPILER=clang-14 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
cmake --build build -j 32
You can also build with docker, please see [build_with_docker](docs/build_with_docker.md).
## Run a test cluster
Follow instructions in [setup guide](deploy/README.md) to run a test cluster.

74
docs/build_with_docker.md Normal file
View File

@ -0,0 +1,74 @@
If you want to compile 3FS with docker, here is a guide for you.
# Step 1: create container
> run command in host
```bash
$ mkdir build-3fs; cd build-3fs
$ wget https://raw.githubusercontent.com/deepseek-ai/3FS/refs/heads/main/scripts/playground.sh
$ sudo bash playground.sh
```
# Step2: install dependencies
> run command in container
## 2.1 install dependencies
```bash
$ apt update
$ apt install -y cmake libuv1-dev liblz4-dev liblzma-dev libdouble-conversion-dev libdwarf-dev libunwind-dev \
libaio-dev libgflags-dev libgoogle-glog-dev libgtest-dev libgmock-dev clang-format-14 clang-14 clang-tidy-14 lld-14 \
libgoogle-perftools-dev google-perftools libssl-dev gcc-12 g++-12 libboost-all-dev cargo git g++ wget meson
```
## 2.2 install foundationdb
```bash
$ cd ${BUILD_DIR}
$ wget https://github.com/apple/foundationdb/releases/download/7.1.67/foundationdb-server_7.1.67-1_amd64.deb \
https://github.com/apple/foundationdb/releases/download/7.1.67/foundationdb-clients_7.1.67-1_amd64.deb
$ dpkg -i foundationdb-server_7.1.67-1_amd64.deb foundationdb-clients_7.1.67-1_amd64.deb
```
## 2.3 build and install fuse
```bash
$ cd ${BUILD_DIR}
$ wget https://github.com/libfuse/libfuse/releases/download/fuse-3.16.2/fuse-3.16.2.tar.gz
$ tar -zxvf fuse-3.16.2.tar.gz
$ cd fuse-3.16.2; mkdir build; cd build
$ meson setup ..
$ ninja
$ ninja install # ignore error
```
# Step 3: build 3FS
> run command in container
```bash
$ cd ${BUILD_DIR}
$ git clone https://github.com/deepseek-ai/3fs
$ cd 3fs
$ git submodule update --init --recursive
$ ./patches/apply.sh
$ cmake -S . -B build -DCMAKE_CXX_COMPILER=clang++-14 -DCMAKE_C_COMPILER=clang-14 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
$ cmake --build build -j 45
```
It will generates binrary shown as below once build success:
```bash
$ cd ${BUILD_DIR}; ls -ls 3fs/build/bin
total 2308428
355344 -rwxr-xr-x 1 root root 363871904 Mar 4 11:36 admin_cli
144976 -rwxr-xr-x 1 root root 148454880 Mar 4 11:30 hf3fs-admin
204336 -rwxr-xr-x 1 root root 209239320 Mar 4 11:32 hf3fs_fuse_main
277812 -rwxr-xr-x 1 root root 284476352 Mar 4 11:30 meta_main
174700 -rwxr-xr-x 1 root root 178892200 Mar 4 11:27 mgmtd_main
168300 -rwxr-xr-x 1 root root 172336688 Mar 4 11:26 migration_main
102740 -rwxr-xr-x 1 root root 105205000 Mar 4 11:19 monitor_collector_main
170628 -rwxr-xr-x 1 root root 174721688 Mar 4 11:26 simple_example_main
395964 -rwxr-xr-x 1 root root 405484072 Mar 4 11:34 storage_bench
313628 -rwxr-xr-x 1 root root 321173936 Mar 4 11:28 storage_main
```

54
scripts/playground.sh Normal file
View File

@ -0,0 +1,54 @@
#!/usr/bin/env bash
############################ GLOBAL VARIABLES
g_container_name="build-3fs-playground"
g_container_image="ubuntu:22.04"
############################ BASIC FUNCTIONS
msg() {
printf '%b' "$1" >&2
}
success() {
msg "\33[32m[✔]\33[0m ${1}${2}"
}
############################ FUNCTIONS
create_container() {
id=$(docker ps --all --format "{{.ID}}" --filter name=${g_container_name})
if [ -n "${id}" ]; then
return
fi
docker run -v "$(pwd)":"$(pwd)" \
-dt \
--cap-add=SYS_PTRACE \
--security-opt seccomp=unconfined \
--restart always \
--env "UID=$(id -u)" \
--env "USER=${USER}" \
--env "TZ=Asia/Shanghai" \
--env "BUILD_DIR=$(pwd)" \
--hostname "${g_container_name}" \
--name "${g_container_name}" \
--workdir "$(pwd)" \
"${g_container_image}"
success "create ${g_container_name} (${g_container_image}) success :)\n"
}
enter_container() {
docker exec \
-u "$(id -u):$(id -g)" \
-it \
--env "TERM=xterm-256color" \
"${g_container_name}" /bin/bash
}
main() {
create_container
enter_container
}
############################ MAIN()
main "$@"