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

Add proxy for downloading registry #429

Open
wants to merge 1 commit into
base: main
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
99 changes: 50 additions & 49 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,61 @@ about = "Terraform mirroring proxy"

[[test]]
name = "integration"
path = "integration/main.rs"
path = "integration/main.rs"

[[bin]]
name = "bootstrap"
path = "src/lambda.rs"
[[bin]]
name = "bootstrap"
path = "src/lambda.rs"


# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html


[dependencies]
anyhow = "^1.0.82"
aws-sdk-s3 = { version = "^1.25.0" }
axum = { version = "^0.7.5", features = ["http2", "json", "tracing"] }
clap = { version = "^4.5.4", features = [
"derive",
"env",
"unicode",
"wrap_help",
] }
http = "^1.1.0"
hyper = { version = "^1.3.1", features = ["full"] }
lazy_static = "1.4.0"
reqwest = { version = "0.12.4", default-features = false, features = [
"rustls-tls-manual-roots",
"gzip",
"deflate",
"brotli",
"stream",
] }
serde = { version = "^1.0.200", features = ["serde_derive"] }
serde_json = "^1.0.116"
thiserror = "^1.0.59"
tower = "^0.4.13"
tower-http = { version = "^0.5.2", features = [
"tracing",
"trace",
"metrics",
"util",
] }
tracing = "^0.1.40"
tracing-subscriber = { version = "^0.3.18", features = [
"env-filter",
"json",
"tracing-log",
] }
url = { version = "^2.5.0", features = ["serde"] }
tokio = { version = "^1.37.0", features = ["full"] }
sqlx = { version = "^0.8.0", features = [
"runtime-tokio",
"tls-rustls",
"postgres",
] }
tokio-stream = "^0.1.15"
[dependencies]
anyhow = "^1.0.82"
aws-sdk-s3 = { version = "^1.25.0" }
axum = { version = "^0.7.5", features = ["http2", "json", "tracing"] }
clap = { version = "^4.5.4", features = [
"derive",
"env",
"unicode",
"wrap_help",
] }
http = "^1.1.0"
hyper = { version = "^1.3.1", features = ["full"] }
lazy_static = "1.4.0"
reqwest = { version = "0.12.4", default-features = false, features = [
"rustls-tls-manual-roots",
"gzip",
"deflate",
"brotli",
"stream",
"socks",
] }
serde = { version = "^1.0.200", features = ["serde_derive"] }
serde_json = "^1.0.116"
thiserror = "^1.0.59"
tower = "^0.4.13"
tower-http = { version = "^0.5.2", features = [
"tracing",
"trace",
"metrics",
"util",
] }
tracing = "^0.1.40"
tracing-subscriber = { version = "^0.3.18", features = [
"env-filter",
"json",
"tracing-log",
] }
url = { version = "^2.5.0", features = ["serde"] }
tokio = { version = "^1.37.0", features = ["full"] }
sqlx = { version = "^0.8.0", features = [
"runtime-tokio",
"tls-rustls",
"postgres",
] }
tokio-stream = "^0.1.15"
aws-config = { version = "^1.3.0" }
futures = "0.3.30"
humantime = "2.1.0"
Expand Down
22 changes: 15 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
FROM docker.io/library/rust:1.82@sha256:81584ce20ac0fc77ac45384c28f356cb76489e8c71998962fed0008dbe496987
WORKDIR /usr/src/app
COPY Cargo.toml Cargo.lock .
RUN mkdir src/ && touch src/main.rs
FROM rust:1.82.0

WORKDIR /app

RUN apt-get update && apt-get install -y musl-tools
RUN rustup target add x86_64-unknown-linux-musl

RUN cargo install sqlx-cli

COPY Cargo* .
RUN cargo fetch
COPY src tests resources migrations build.rs .
RUN cargo install --path .
CMD ["terrashine"]
COPY . .
RUN SQLX_OFFLINE=1 cargo build --release
RUN mv ./target/x86_64-unknown-linux-musl/release/terrashine /usr/bin/terrashine
ENV RUST_LOG=info
CMD ["terrashine", "server"]
2 changes: 1 addition & 1 deletion docs/src/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ rustup target add x86_64-unknown-linux-musl
SQLX_OFFLINE=1 cargo build --release
```

Once built, the binary can be found at `./target/release/terrashine`
Once built, the binary can be found at `./target/x86_64-unknown-linux-musl/release/terrashine`

## Install
```sh
Expand Down
1 change: 1 addition & 0 deletions integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fn test_server_startup(_: PoolOptions<Postgres>, db_options: PgConnectOptions) {
http_listen: SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 0),
refresh_interval: Duration::from_secs(10),
upstream_registry_port: 443,
http_proxy: "",
};
let cancellation_token = tokio_util::sync::CancellationToken::new();
let (tx, rx) = tokio::sync::oneshot::channel();
Expand Down
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ pub struct ServerArgs {
hide = true
)]
pub upstream_registry_port: u16,

/// Proxy for downloading registry
///
/// The address to the proxy server. For example "socks5://127.0.0.1:9150"
#[arg(long, default_value = "", env = "TERRASHINE_HTTP_PROXY")]
pub http_proxy: String,
}

#[derive(clap::Args, Debug, Clone)]
Expand Down
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use hyper_util::{
server,
};
use migrate::run_migrate;
use reqwest::{Certificate, Client};
use reqwest::{Certificate, Client, Proxy};
use sqlx::{postgres::PgPoolOptions, PgPool};
use std::{net::SocketAddr, time::Duration};
use tokio::{
Expand Down Expand Up @@ -155,6 +155,16 @@ pub async fn setup_server(
http_builder = http_builder
.add_root_certificate(Certificate::from_der(cert.as_ref()).expect("Not a certificate"));
}
if !&config.http_proxy.is_empty() {
let proxy = match Proxy::all(&config.http_proxy) {
Ok(proxy) => proxy,
Err(error) => {
error!(reason = %error, "Could not initialize proxy, exiting.");
return Err(());
}
};
http_builder = http_builder.proxy(proxy);
};
let http = match http_builder.build() {
Ok(client) => client,
Err(error) => {
Expand Down