-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
160 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
FROM alpine:latest AS build-env | ||
|
||
# 修改Alpine镜像地址 | ||
RUN set -eux && sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories | ||
|
||
# 设置rustup安装代理环境 | ||
ENV RUSTUP_DIST_SERVER="https://rsproxy.cn" | ||
ENV RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup" | ||
|
||
# 安装依赖库 | ||
RUN apk update | ||
RUN apk add -u --no-cache gcc | ||
RUN apk add -u --no-cache musl-dev | ||
RUN apk add -u --no-cache wget | ||
|
||
# 安装rustup | ||
RUN mkdir /tmp/run | ||
RUN wget https://rsproxy.cn/rustup-init.sh | ||
RUN sh rustup-init.sh -y --profile minimal --no-modify-path | ||
|
||
# 链接rustup和cargo到/usr/local/bin | ||
RUN ln -s $HOME/.cargo/bin/rustup /usr/local/bin/rustup | ||
RUN ln -s $HOME/.cargo/bin/cargo /usr/local/bin/cargo | ||
|
||
# 导入cargo配置 | ||
COPY proxy_config / | ||
RUN mv /proxy_config $HOME/.cargo/config | ||
|
||
WORKDIR /satex | ||
|
||
# 复制文件 | ||
COPY src ./src | ||
COPY satex-core ./satex-core | ||
COPY satex-serve ./satex-serve | ||
COPY satex-matcher ./satex-matcher | ||
COPY satex-layer ./satex-layer | ||
COPY satex-service ./satex-service | ||
COPY satex-discovery ./satex-discovery | ||
COPY Cargo.toml . | ||
COPY Cargo.lock . | ||
|
||
# 编译 | ||
RUN cargo build --release | ||
|
||
FROM alpine:latest | ||
|
||
WORKDIR /satex | ||
|
||
# 复制构建文件 | ||
COPY --from=build-env /satex/target/release/satex ./bin/ | ||
|
||
# 复制配置文件 | ||
COPY examples/docker/satex.yaml ./conf/ | ||
COPY examples/docker/static.yaml ./conf/ | ||
COPY examples/resources ./static/ | ||
|
||
# 暴露端口 | ||
EXPOSE 80 | ||
|
||
# 启动 | ||
ENTRYPOINT ["/satex/bin/satex","-c","/satex/conf/satex.yaml"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
satex: | ||
# 日志配置 | ||
tracing: | ||
# 日志级别 | ||
max_level: info | ||
# 是否使用ANSI | ||
ansi: true | ||
# 是否显示级别 | ||
level: true | ||
# 是否显示文件 | ||
file: false | ||
# 是否显示线程名称 | ||
thread_names: true | ||
# 是否显示行号 | ||
line_number: true | ||
|
||
# 服务配置 | ||
serves: | ||
- /satex/conf/static.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# 服务配置 | ||
server: | ||
# 服务端口 | ||
port: 80 | ||
|
||
# 路由配置 | ||
router: | ||
# 路由表 | ||
routes: | ||
# 静态文件 | ||
- id: static | ||
service: Static=/satex/static |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[source.crates-io] | ||
replace-with = 'rsproxy-sparse' | ||
[source.rsproxy] | ||
registry = "https://rsproxy.cn/crates.io-index" | ||
[source.rsproxy-sparse] | ||
registry = "sparse+https://rsproxy.cn/index/" | ||
[registries.rsproxy] | ||
index = "https://rsproxy.cn/crates.io-index" | ||
[net] | ||
git-fetch-with-cli = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::time::Duration; | ||
|
||
use tower_http::timeout::TimeoutLayer; | ||
|
||
use satex_core::config::args::Args; | ||
use satex_core::Error; | ||
|
||
use crate::make::make_layer; | ||
use crate::MakeRouteServiceLayer; | ||
|
||
make_layer! { | ||
Timeout, | ||
|
||
#[serde(deserialize_with="satex_core::serde::tot::as_u64")] | ||
secs: u64 | ||
} | ||
|
||
fn make(args: Args) -> Result<TimeoutLayer, Error> { | ||
let config = Config::try_from(args)?; | ||
Ok(TimeoutLayer::new(Duration::from_secs(config.secs))) | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use std::convert::Infallible; | ||
use std::time::Duration; | ||
|
||
use hyper::{Request, Response}; | ||
use tokio::time::sleep; | ||
use tower::{service_fn, Layer, Service}; | ||
|
||
use satex_core::config::args::{Args, Shortcut}; | ||
use satex_core::http::Body; | ||
|
||
use crate::make::timeout::MakeTimeoutLayer; | ||
use crate::MakeRouteServiceLayer; | ||
|
||
#[tokio::test] | ||
async fn test_layer() { | ||
let args = Args::from(Shortcut::from("3")); | ||
let make = MakeTimeoutLayer::default(); | ||
let layer = make.make(args).unwrap(); | ||
let service = service_fn(|_: Request<Body>| async move { | ||
sleep(Duration::from_secs(5)).await; | ||
Ok::<_, Infallible>(Response::new(Body::empty())) | ||
}); | ||
let mut service = layer.layer(service); | ||
let request = Request::new(Body::empty()); | ||
let response = service.call(request).await.unwrap(); | ||
assert_eq!(response.status().as_u16(), 408); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters