Skip to content

Commit

Permalink
fix: unable to load env var through docker compose
Browse files Browse the repository at this point in the history
- Use arguments from command line instead of environment variables.
- Environment in docker compose seems different from docker run -e, which can't be loaded in images from scratch.
  • Loading branch information
hlf20010508 committed Nov 23, 2023
1 parent 352d6df commit 4ef23c5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
9 changes: 8 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gpts-code-analyst"
version = "1.1.1"
version = "1.1.2"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -18,5 +18,6 @@ async-std = "1.12.0"
awc = { version = "3.2.0", features = ["rustls-0_21"] }
env_logger = "0.10.1"
log = "0.4.20"
pico-args = { version = "0.5.0", features = ["short-space-opt"] }
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ RUN apk add --update --no-cache musl-dev &&\
FROM scratch
COPY --from=builder /workdir/target/release/gpts-code-analyst /
COPY --from=builder /workdir/static /static
CMD ["/gpts-code-analyst"]
ENTRYPOINT ["/gpts-code-analyst"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Github Code Analyst over GPTs
```sh
PORT=8080 # 改成你的端口号
GITHUB_TOKEN=xxxxxxxxxxxxxx # 改成你的Github Token
docker run -d --name code-analyst -p $PORT:8080 -e GITHUB_TOKEN=$GITHUB_TOKEN hlf01/gpts-code-analyst
docker run -d --name code-analyst -p $PORT:8080 hlf01/gpts-code-analyst --token $GITHUB_TOKEN
```

## Docker构建
Expand Down
5 changes: 3 additions & 2 deletions src/requests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use async_std::io::{Error, ErrorKind, Result};
use std::env::var;
use pico_args::Arguments;

pub async fn get(url: &str) -> Result<String> {
let client = awc::Client::builder()
Expand All @@ -8,7 +8,8 @@ pub async fn get(url: &str) -> Result<String> {

let mut request = client.get(url).insert_header(("User-Agent", "Actix-web"));

if let Ok(github_token) = var("GITHUB_TOKEN") {
let mut args = Arguments::from_env();
if let Ok(github_token) = args.value_from_str::<&str, String>("--token") {
request = request.insert_header(("Authorization", format!("Bearer {}", github_token)));
} else {
return Err(Error::new(
Expand Down

0 comments on commit 4ef23c5

Please sign in to comment.