Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix APPDIR env bug #4

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,4 @@ FodyWeavers.xsd
*.key
*.crt
*.AppImage
server_log
26 changes: 26 additions & 0 deletions Dockerfile.client
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM ubuntu:22.04
# 使用官方的 Ubuntu 基础镜像

# 为了避免在安装过程中出现任何交互式提示
ENV DEBIAN_FRONTEND=noninteractive

WORKDIR /app
# 设置工作目录

# 将编译好的可执行文件复制到容器中
COPY zpods_cli /app
COPY *.key *.crt /app

COPY libzpods_lib.so /usr/lib/libzpods_lib.so
COPY libstdc++.so.6.0.30 /usr/lib/libstdc++.so.6.0.30
RUN rm -rf /usr/lib/libstdc++.so.6 && ln -s /usr/lib/libstdc++.so.6.0.30 /usr/lib/libstdc++.so.6
COPY libm.so.6 /usr/lib/libm.so.6
COPY libgcc_s.so.1 /usr/lib/libgcc_s.so.1
COPY libc.so.6 /usr/lib/libc.so.6
COPY libcrypto.so.3 /usr/lib/libcrypto.so.3

# 给执行文件添加运行权限
RUN chmod u+x /app/zpods_cli

# 设置环境变量以便可以从任何路径运行您的CLI
ENV PATH="/app:${PATH}"
1 change: 1 addition & 0 deletions Dockerfile.server
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ COPY ./server.crt /app
COPY ./client.crt /app

# generated by script
#! you need run scripts/gen_cmd_for_dep.py to generate following commands
COPY libzstd.so.1.4.8 /usr/lib/libzstd.so.1.4.8
RUN rm -rf /usr/lib/libzstd.so.1 && ln -s /usr/lib/libzstd.so.1.4.8 /usr/lib/libzstd.so.1
COPY libstdc++.so.6.0.30 /usr/lib/libstdc++.so.6.0.30
Expand Down
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: clean test configure build install_cli uninstall hdfs local_deploy format local_deploy light_deploy docker_build AppImage gen_key gen_key_local push_docker
.PHONY: clean test configure build install_cli uninstall hdfs local_deploy format local_deploy light_deploy docker_build AppImage gen_key gen_key_local push_docker docker_run_server docker_run_cli

configure:
chmod u+x scripts/*.sh
Expand All @@ -16,15 +16,22 @@ build:
./scripts/build.sh

docker_build: build
./scripts/docker_build.sh
./scripts/docker_build_server.sh

push_docker: docker_build
docker tag zpods_server:latest code4love/zpods_server:v1.0
docker push code4love/zpods_server:v1.0

docker_run_server: docker_build
./scripts/run_server.sh

AppImage: build
./scripts/build_appimage.sh

docker_run_cli: build
./scripts/docker_build_cli.sh
docker run --network host -it zpods_cli:latest /bin/bash

local_deploy: build
bash ./scripts/deploy_local.sh

Expand All @@ -37,9 +44,10 @@ uninstall:
format:
@clang-format -i -style=file $(shell find ZpodsLib network \( -name "*.h" -o -name "*.cpp" \) -size -100k)

install_cli: build uninstall
install_cli: build uninstall AppImage
@# if there is no /usr/local/bin/zpods.cli, then create a symbol link
@[ -f /usr/local/bin/zpods.cli ] || ln -s $(shell pwd)/build/client/cli/src/zpods_cli /usr/local/bin/zpods.cli
@chmod u+x zpods_cli-x86_64.AppImage
@[ -f /usr/local/bin/zpods.cli ] || ln -s $(shell pwd)/zpods_cli-x86_64.AppImage /usr/local/bin/zpods.cli
@echo "installed successfully in /usr/local/bin/zpods.cli!"
@echo "you can use 'zpods.cli --help' to learn how to use zpods cli"

Expand Down
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,31 @@ make configure
make test
```

## how to deploy?

### gen keys

You need to generate keys and credentials first.

For local use, just run `make gen_key_local`, and you will see `client.key`, `client.crt`, `server.key`, `server.crt` in the root directory of the project.

For remote use, you must modify the IP in `san.cnf`, and then run `make gen_key`.

NOTE: the client and the server share the same version of keys and credentials. So please only do this step once, and reuse generated files for the following steps.

### make appimage

1. You need to run `python3 scripts/gen_cmd_for_dep.py deploy/zpods_cli AppDir/usr/lib` to get the commands and replace them in `scripts/build_appimage.sh`
2. You need to get appimagetool from `https://appimage.github.io/appimagetool/` and install it.
3. Make sure you have run `make gen_key` or `make gen_key_local` first.
4. `make AppImage`

### deploy with docker

1. You need to run `python3 scripts/gen_cmd_for_dep.py deploy/zpods_server server_image` to get the commands and replace them in `scripts/docker_build.sh` and `Docker.server`.
2. Run `make run_server` to build docker image and run it locally.
3. For remote deployment, `make push_docker`. Then copy the `./scripts/run_server.sh` to your server and run it.

## install cli

```sh
Expand Down Expand Up @@ -82,3 +107,17 @@ zpods.cli restore --src ./tmp/single.map --target ./tmp
# you must use '-p' to specify the password used in encryption
zpods.cli restore --src ./tmp/single.map --target ./tmp -p 1234
```

### remote backup

```shell
# set you remote server address
zpods.cli set_server_addr IP:PORT
zpods.cli register
zpods.cli login
# use -r in backup to backup to remote server
# the mapping will be recorded
zpods.cli backup ... -r
# run daemon for synchronization continuously
zpods.cli daemon
```
4 changes: 2 additions & 2 deletions ZpodsLib/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ FILE(GLOB_RECURSE SRC *.cpp *.c)

find_package(OpenSSL REQUIRED)

include_directories(./base ./core ./network ./)
include_directories(./base ./core ./transform ./)
add_library(${PROJECT_NAME} SHARED zpods_lib.h ${SRC})

collect_and_set_global_include_dirs(${CMAKE_CURRENT_SOURCE_DIR} ZPODS_LIB_INCLUDE_DIRS)

target_link_libraries(${PROJECT_NAME} PRIVATE OpenSSL::SSL OpenSSL::Crypto)

target_precompile_headers(${PROJECT_NAME} PRIVATE ${PCH_PATH})
target_precompile_headers(${PROJECT_NAME} PRIVATE ${PCH_PATH})
2 changes: 1 addition & 1 deletion ZpodsLib/src/base/compress.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ struct fmt::formatter<Code>
template <typename FormatContext>
auto format(const Code& p, FormatContext& ctx) const
{
return format_to(ctx.out(), "0b{:0{}b}", p.bits, p.len);
return fmt::format_to(ctx.out(), "0b{:0{}b}", p.bits, p.len);
}
};

Expand Down
55 changes: 14 additions & 41 deletions ZpodsLib/src/base/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,34 +78,20 @@ auto zpods::fs::open_file_as_ifs(const char* path, zpods::fs::openmode mode)
return ifs;
}

auto zpods::fs::open_or_create_file_as_ofs(const char* path,
zpods::fs::openmode mode)
-> std::ofstream
{
let base = get_base_name(path);
if (!exists(base.c_str()))
{
create_directory_if_not_exist(base.c_str());
}
std::ofstream ofs(path, mode);
ZPODS_ASSERT(ofs.is_open());
return ofs;
}

auto zpods::fs::get_base_name(const char* path) -> std::string
{
size_t len = 0;
let_mut p = path;
while (*p)
{
if (*p == '/')
{
len = p - path;
}
p++;
}
return {path, len};
}
/* auto zpods::fs::get_base_name(const char* path) -> std::string */
/* { */
/* size_t len = 0; */
/* let_mut p = path; */
/* while (*p) */
/* { */
/* if (*p == '/') */
/* { */
/* len = p - path; */
/* } */
/* p++; */
/* } */
/* return {path, len}; */
/* } */

auto zpods::fs::read_from_file(const char* path) -> std::string
{
Expand All @@ -116,16 +102,3 @@ auto zpods::fs::read_from_file(const char* path) -> std::string
ifs.read(buf.data(), (long)size);
return {buf.begin(), buf.end()};
}

auto zpods::fs::get_file_name(const char* path) -> const char*
{
let_mut len = strlen(path);
let_mut ret = path;
while (*path)
{
if (*path == '/')
ret = path + 1;
path++;
}
return ret;
}
Loading