Skip to content

Commit

Permalink
add build script
Browse files Browse the repository at this point in the history
  • Loading branch information
shanliu committed Feb 7, 2024
1 parent 3d326ae commit ba88b54
Show file tree
Hide file tree
Showing 131 changed files with 2,278 additions and 1,750 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Build and Release

on:
push:
tags:
- "v*.*.*"

jobs:
# linux_build:
# permissions: write-all
# runs-on: ubuntu-latest

# steps:
# - name: Checkout code
# uses: actions/checkout@v3

# - name: Set up Node.js ${{ matrix.node-version }}
# uses: actions/setup-node@v3
# with:
# node-version: ${{ matrix.node-version }}

# - name: Set up Rust
# uses: actions-rs/toolchain@v1
# with:
# toolchain: stable

# - name: Build
# working-directory: ./
# run: rustc -V && bash ./build.sh && ls -al

# - uses: ncipollo/release-action@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# artifacts: "lsys.tar.gz"
# allowUpdates: true
# token: ${{ secrets.GITHUB_TOKEN }}
# name: ${{ github.event.head_commit.message }}
# prerelease: true
# tag: ${{ github.ref }}
# body: tag version ${{ github.ref }}
# skipIfReleaseExists: true

windows_build:
permissions: write-all
runs-on: windows-latest
steps:
- uses: actions/checkout@v2

- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Build release
run: ./build.cmd

- name: Get current tag
id: get_tag
run: |
$tag = $env:GITHUB_REF -replace 'refs/tags/', ''
Write-Host "##[set-output name=tag;]$tag"
- uses: ncipollo/release-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
artifacts: "lsys.zip"
token: ${{ secrets.GITHUB_TOKEN }}
name: ${{ steps.get_tag.outputs.tag }}
prerelease: true
tag: ${{ github.ref }}
body: |
版本说明: ${{ github.event.head_commit.message }}
文件说明: lsys.zip 为 windows x64 下编译版本,其他版本自行编译。
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/.idea
/.vscode
/.history
dump.rdb
sdk/go/examples/sub_app/__debug_*
sdk/go/.vscode/launch.json
/server/*/.idea/*
/server/.idea/*
/build/*
lsys.tar.gz
lsys.zip
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM rust:latest as rust_rust_builder
WORKDIR /usr/src/lsys-web
COPY ./server .
RUN cargo build -r && sed -i 's|../../../ui/public/|./ui/|g' ./usr/src/lsys-web/examples/lsys-actix-web/config/app.toml

FROM node:18-buster as node_builder
WORKDIR /usr/src/lsys-web
COPY ./ui .
RUN cd ./web && npm run build && cd .. && cd ./web && npm run build

FROM debian:buster-slim
WORKDIR /usr/local/lsys-web
RUN apt-get update && apt-get install -y libssl1.1 && rm -rf /var/lib/apt/lists/*

ENV \
APP_HOST=127.0.0.1 \
APP_PORT=80 \
#APP_SSL_PORT=443
LOG_LEVEL=sqlx_core=info,lsys_sender=debug,axtix_web=debug,actix=info,mio=error,lsys_user=trace,lsys_web=trace,lsys_core=trace,lsys_user=trace,lsys_rbac=trace,lsys_docs=trace,lsys_actix_web=trace,sqlx=trace,redis=debug \
LOG_DIR="logs" \
LOG_NAME="std::out" \
#数据库配置 \
DATABASE_URL="mysql://root:[email protected]:3306/test2" \
#公共表前缀
DATABASE_TABLE_PREFIX="yaf_" \
#redis 配置
REDIS_URL="redis://127.0.0.1/"

COPY --from=rust_builder /usr/src/lsys-web/examples/lsys-actix-web/static /usr/local/lsys-web/
COPY --from=rust_builder /usr/src/lsys-web/examples/lsys-actix-web/config /usr/local/lsys-web/
COPY --from=rust_builder /usr/src/lsys-web/examples/lsys-actix-web/locale /usr/local/lsys-web/
COPY --from=rust_builder /usr/src/lsys-web/examples/lsys-actix-web/data /usr/local/lsys-web/
COPY --from=rust_builder /usr/src/lsys-web/examples/lsys-actix-web/.env /usr/local/lsys-web/.env
COPY --from=rust_builder /usr/src/lsys-web/examples/target/release/lsys-actix-web /usr/local/lsys-web/lsys-actix-web
COPY --from=node_builder /usr/src/lsys-web/public /usr/local/lsys-web/ui
CMD ["/usr/local/lsys-web/lsys-actix-web"]
52 changes: 28 additions & 24 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### rust实现的`面向内部应用的应用管理中心`实现
### rust实现的 `内部应用应用管理中心`

> 适用场景:
> 1. 当你使用rust开发web应用时,使用本项目二次开发可以减少重复工作量。
Expand All @@ -10,49 +10,53 @@
> 在线示例: https://lsys.cc/ [账号:aaaaa 密码:000000]

##### [后端服务](server) 安装
#### 配置跟编译

1. 编译 【中途有失败再次执行】
1. 修改UI访问服务器地址
```
cd server && cargo build -r && cd ..
./ui/web/config.json #修改配置
./ui/wap/config.json #修改配置
```

2. 导入SQL到数据库
```
导入 ./server/assets/tables.sql 到MYSQL
```
2. 执行编译

3. 修改你的监听端口,REDIS,MYSQL等
> [./server/examples/lsys-actix-web/.env 会覆盖./server/examples/lsys-actix-web/config/]
> 编译生成文件在 `./build` 目录中,同时生成 `./build` 目录的压缩包
> windows
```
./server/examples/lsys-actix-web/.env
.\build.cmd #生成 lsys.zip
```

4. 执行 启动服务
> linux or macos
```
cd ./server/examples/lsys-actix-web/ && ../../target/release/lsys-actix-web
bash ./build.sh #生成 lsys.tar.gz
```

> 仅拷贝 `./build` 文件夹到你的服务器 或 把对应生成压缩包拷贝后解压,其他文件可以删除.
##### [管理UI](ui) 安装

1. 修改配置,设置服务地址跟jwt的token等
3. 导入SQL到数据库
```
./ui/web/config.json
./ui/wap/config.json
mysql -u your_username -p your_database < ./build/assets/tables.sql #导入到你的MYSQL
```

2. 编译
4. 根据实际情况,对 `Redis` `Mysql` `jwt token` `日志输出` 等配置进行修改。
```
cd ./ui/web && npm i && npm run build && cd ../..
cd ./ui/wap && npm i && npm run build && cd ../..
cd ..
./build/.env #修改配置
```

3. 访问 http://127.0.0.1/ui/
5. 启动服务

> 下载文件[2023-7-area-code.csv.gz](https://github.com/shanliu/area-db/blob/main/data/2023-7-area-code.csv.gz)`build/data` 目录
> [可选] 下载IP文件 `IP2LOCATION-LITE-DB11.BIN``build/data/` 目录
> 执行 `./actix-web-dome ` 启动服务。注意:初次启动会慢一些。
> 可使用 `nohup ./actix-web-dome &` 后台执行
> 根据`.env`配置访问服务.默认地址:http://127.0.0.1:8080/
#### 二次开发参考时序:
#### 二次开发时序参考

##### 基于rust二次开发

Expand Down
40 changes: 40 additions & 0 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
mkdir build
xcopy "README.MD" build /Y
xcopy LICENSE build /Y

mkdir server\\examples\\lsys-actix-web\data
cd server\\examples\\lsys-actix-web
cargo version
rustc -V
cargo update
cargo build -r -vvv
cd ..\\..\\..

xcopy /E /I /Y server\\assets build\\assets
xcopy server\\target\\release\\lsys-actix-web.exe build /Y
xcopy /E /I /Y server\\examples\\lsys-actix-web\\config build\\config
xcopy /E /I /Y server\\examples\\lsys-actix-web\\data build\\data
xcopy /E /I /Y server\\examples\\lsys-actix-web\\locale build\\locale
xcopy /E /I /Y server\\examples\\lsys-actix-web\\static build\\static
xcopy server\\examples\\lsys-actix-web\\.env build /Y

cd ui\\web
call npm install
call npm run build
cd ..\\..
mkdir ui\\public
cd ui\\wap
call npm install
call npm run build
cd ..\\..
mkdir ui\\public
xcopy /E /I /Y ui\\public build\\ui


powershell.exe -Command "(Get-Content -Path 'build\\config\\app.toml') | ForEach-Object { $_ -replace '../../../ui/public/', './ui/' } | Set-Content -Path 'build\\config\\app.toml'"

cd build
powershell.exe -Command "Compress-Archive -Path './' -DestinationPath '../lsys.zip'"
cd ..

echo The compilation was successful, please enable the service with ( ./lsys-actix-web ) to the service and access it via http://127.0.0.1:8080
31 changes: 31 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

mkdir -p build
cp -fr ./README.MD ./build
cp -fr ./LICENSE ./build
#
mkdir -p ./server/examples/lsys-actix-web/data
cd ./server/examples/lsys-actix-web && cargo build \-r && cd ../../..
cp -fr ./server/assets ./build
cp -fr ./server/target/release/lsys-actix-web ./build
cp -fr ./server/examples/lsys-actix-web/config ./build
cp -fr ./server/examples/lsys-actix-web/data ./build
cp -fr ./server/examples/lsys-actix-web/locale ./build
cp -fr ./server/examples/lsys-actix-web/static ./build
cp -fr ./server/examples/lsys-actix-web/.env ./build
#
cd ui/web && npm i && npm run build && cd ../..
cd ui/wap && npm i && npm run build && cd ../..
cp -fr ./ui/public/ ./build/ui/
#
if [ "$(uname)" = "Darwin" ]; then
sed -i '' "s|../../../ui/public/|./ui/|g" ./build/config/app.toml
else
sed -i "s|../../../ui/public/|./ui/|g" ./build/config/app.toml
fi

cd ./build && tar -cvf ../lsys.tar.gz ./ && cd ..
#
echo -e "The compilation was successful, \
Please start the service with ( ./lsys-actix-web ) \
to start the service and access it via \033[1;32mhttp://127.0.0.1:8080\033[0m"
18 changes: 0 additions & 18 deletions server/Dockerfile

This file was deleted.

7 changes: 4 additions & 3 deletions server/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
> 已实现统一登陆的oauth服务,更多的通用应用实现中。。。

#### 开发配置
### 开发or编译

1. 导入SQL到数据库
```
导入 ./assets/tables.sql 到MYSQL
```

2. 修改你的REDIS,MYSQL等的配置
2. 修改你的REDIS,MYSQL,jwt token等配置
> [./examples/lsys-actix-web/.env 的配置会覆盖./examples/lsys-actix-web/config/下配置]
```
Expand All @@ -24,4 +24,5 @@
3. 启动开发环境
```
cd ./examples/lsys-actix-web/ && cargo run
```
#cargo build -r && cd .. #or build
```
3 changes: 3 additions & 0 deletions server/examples/lsys-actix-web/.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ LOG_DIR="logs"
LOG_NAME="std::out"
#LOG_GELF="127.0.0.1:12201"

#jwt 密钥 ,修改将导致登陆失效
APP_JWT_KEY = "bbb"

#数据库配置
DATABASE_URL="mysql://root:[email protected]:3306/test2"
#公共表前缀
Expand Down
7 changes: 4 additions & 3 deletions server/examples/lsys-actix-web/config/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ rbac_cache = true
ui_dir = "../../../ui/public/"
#静态文件访问路径,默认:/ui/
#ui_path="/ui/"
ui_path="/"
#超级管理员id
root_user_id = [1]

#语言文件目录
fluent_dir = "locale/"

#页面模板目录
tpl_dir = "static"
tpl_dir = "./static"

#地址库数据文件压缩包
area_code_db = "data/2023-7-area-code.csv.gz"
Expand All @@ -46,8 +47,8 @@ ip_city_db = "data/IP2LOCATION-LITE-DB11.BIN"
#snowflake_node_id=1 #最大31

# jwt token
app_jwt_key = "bbb" #jwt 密钥
#app_jwt_key = "bbb" #jwt 密钥


#git doc save dir
doc_git_dir = "/tmp/"
#doc_git_dir = "/tmp/"
12 changes: 11 additions & 1 deletion server/examples/lsys-actix-web/locale/en_US/app.ftl
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
jwt-encode-error = JWT generation error:{$msg}
wechat-parse-state-error= state error:{$msg}
wechat-parse-state-error= state error:{$msg}
time-format-error=Date parsing exception: {$msg}
time-zone-error=Date time zone exception.
area-db-error=Database exception:{$msg}
area-error=System exception:{$msg}
area-not-found=Address information not found.
areaa-store-error=Store exception:{$msg}
area-tantivy-error=Search exception:{$msg}
5 changes: 3 additions & 2 deletions server/examples/lsys-actix-web/locale/en_US/lsys-core.ftl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
app-error = Send error, details:{$msg}
utf-error = String is not a valid UTF character, error details:{$msg}
utf-parse-error = String is not a valid UTF character, error details:{$msg}
valid-code-tag-len = Checksum KEY[{$tag}] max length:{$max}
valid-code-submit-empty = The code is not empty.
valid-code-not-match = The submitted code [{$code}] does not match.
valid-code-not-match = The submitted code [{$code}] does not match.
wait-notify-timeout=Wait to send timeout
Loading

0 comments on commit ba88b54

Please sign in to comment.