Skip to content

Commit 3927215

Browse files
committed
add git ignore and modify verbose flag
1 parent f825ef0 commit 3927215

File tree

7 files changed

+191
-57
lines changed

7 files changed

+191
-57
lines changed

.env.default

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# LOG_LEVEL
2+
VERBOSE=3
3+
4+
# log output path
5+
# LOG_DIR=./logs
6+
7+
# log rotation values: DAILY, HOURLY, MINUTELY, NEVER
8+
# LOG_ROTATION=DAILY
9+
10+
# beacon chain endpoint url
11+
BEACON_ENDPOINT=http://localhost:3500
12+
13+
# beacon client request timeout
14+
#BEACON_CLIENT_TIMEOUT=10
15+
16+
# beacon client poll interval
17+
#POLL_INTERVAL=6
18+
19+
# blob archiver api server listening address
20+
LISTEN_ADDR=0.0.0.0:8000
21+
22+
# blob archiver origin block number
23+
ORIGIN_BLOCK=0x1
24+
25+
# blob data storage strategy type: s3, fs
26+
STORAGE_TYPE=s3
27+
28+
# s3 storage credentials access key id
29+
AWS_ACCESS_KEY_ID=admin
30+
31+
# s3 storage credentials secret access key
32+
AWS_SECRET_ACCESS_KEY=password
33+
34+
# s3 storage region just use default value: us-east-1
35+
AWS_REGION=us-east-1
36+
37+
# s3 storage endpoint
38+
S3_ENDPOINT=http://localhost:9000
39+
40+
# s3 storage bucket
41+
S3_BUCKET=
42+
43+
# s3 storage path
44+
S3_PATH=
45+
46+
# s3 storage compress
47+
S3_COMPRESS=true
48+
49+
# local file storage directory
50+
FS_DIR=./fs

Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api.Dockerfile

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use the official Rust image as the base
2+
FROM rust:latest as builder
3+
4+
RUN apt-get update && apt-get install -y cmake
5+
6+
# Set the working directory
7+
WORKDIR /usr/src/blob-archiver-rs
8+
9+
# Copy the entire project
10+
COPY . .
11+
12+
# Build the project
13+
RUN cargo build --release -p api
14+
15+
# Create a new stage with a minimal image
16+
FROM ubuntu:latest
17+
18+
# Install OpenSSL
19+
RUN apt-get update && apt-get install -y openssl ca-certificates && rm -rf /var/lib/apt/lists/*
20+
21+
# Copy the built binary from the builder stage
22+
COPY --from=builder /usr/src/blob-archiver-rs/target/release/api /usr/local/bin/api
23+
24+
# Set the entrypoint
25+
ENTRYPOINT ["api"]

archiver.Dockerfile

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
# Use the official Rust image as the base
22
FROM rust:latest as builder
33

4+
RUN apt-get update && apt-get install -y cmake
5+
46
# Set the working directory
57
WORKDIR /usr/src/blob-archiver-rs
68

79
# Copy the entire project
810
COPY . .
911

1012
# Build the project
11-
RUN cargo build --release
13+
RUN cargo build --release -p archiver
1214

1315
# Create a new stage with a minimal image
14-
FROM debian:buster-slim
16+
FROM ubuntu:latest
1517

1618
# Install OpenSSL
1719
RUN apt-get update && apt-get install -y openssl ca-certificates && rm -rf /var/lib/apt/lists/*

bin/api/src/main.rs

+52-41
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ use clap::Parser;
88
use ctrlc::set_handler;
99
use eth2::types::Hash256;
1010
use eth2::{BeaconNodeHttpClient, SensitiveUrl, Timeouts};
11+
use eyre::eyre;
1112
use serde::{Deserialize, Serialize};
1213
use tokio::sync::Mutex;
14+
use tracing::Level;
1315
use tracing_appender::rolling::{RollingFileAppender, Rotation};
16+
use tracing_subscriber::fmt;
17+
use tracing_subscriber::fmt::writer::MakeWriterExt;
1418
use tracing_subscriber::layer::SubscriberExt;
15-
use tracing_subscriber::util::SubscriberInitExt;
16-
use tracing_subscriber::{fmt, EnvFilter};
1719

1820
use blob_archiver_beacon::beacon_client;
1921
use blob_archiver_beacon::beacon_client::BeaconClientEth2;
@@ -72,12 +74,10 @@ async fn main() {
7274
let api = api::Api::new(Arc::new(Mutex::new(beacon_client_eth2)), storage.clone());
7375
let addr: std::net::SocketAddr = config.listen_addr.parse().expect("Invalid listen address");
7476

75-
let (_, server) = warp::serve(api.routes())
76-
.bind_with_graceful_shutdown(addr, async move {
77+
let (_, server) = warp::serve(api.routes()).bind_with_graceful_shutdown(addr, async move {
7778
shutdown_rx.clone().changed().await.ok();
7879
});
7980
server.await;
80-
8181
}
8282

8383
fn init_logging(verbose: u8, log_dir: Option<PathBuf>, rotation: Option<Rotation>) {
@@ -92,18 +92,6 @@ pub fn setup_tracing(
9292
log_dir: Option<PathBuf>,
9393
rotation: Option<Rotation>,
9494
) -> eyre::Result<()> {
95-
let filter = match verbose {
96-
0 => EnvFilter::new("error"),
97-
1 => EnvFilter::new("warn"),
98-
2 => EnvFilter::new("info"),
99-
3 => EnvFilter::new("debug"),
100-
_ => EnvFilter::new("trace"),
101-
};
102-
103-
let subscriber = tracing_subscriber::registry()
104-
.with(EnvFilter::from_default_env())
105-
.with(filter);
106-
10795
if let Some(log_dir) = log_dir {
10896
fs::create_dir_all(&log_dir)
10997
.map_err(|e| eyre::eyre!("Failed to create log directory: {}", e))?;
@@ -114,63 +102,86 @@ pub fn setup_tracing(
114102
"blob-archiver.log",
115103
);
116104
let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);
117-
let file_layer = fmt::layer().with_writer(non_blocking).with_ansi(false);
118-
119-
subscriber
120-
.with(file_layer)
121-
.with(fmt::layer().with_writer(std::io::stdout))
122-
.try_init()?;
105+
let file_layer = fmt::layer()
106+
.with_writer(non_blocking.with_max_level(match verbose {
107+
0 => Level::ERROR,
108+
1 => Level::WARN,
109+
2 => Level::INFO,
110+
3 => Level::DEBUG,
111+
_ => Level::TRACE,
112+
}))
113+
.with_ansi(false);
114+
115+
let subscriber =
116+
tracing_subscriber::registry()
117+
.with(file_layer)
118+
.with(
119+
fmt::layer().with_writer(std::io::stdout.with_max_level(match verbose {
120+
0 => Level::ERROR,
121+
1 => Level::WARN,
122+
2 => Level::INFO,
123+
3 => Level::DEBUG,
124+
_ => Level::TRACE,
125+
})),
126+
);
127+
tracing::subscriber::set_global_default(subscriber).map_err(|e| eyre!(e))?;
123128
} else {
124-
subscriber
125-
.with(fmt::layer().with_writer(std::io::stdout))
126-
.try_init()?;
129+
let subscriber = tracing_subscriber::registry().with(fmt::layer().with_writer(
130+
std::io::stdout.with_max_level(match verbose {
131+
0 => Level::ERROR,
132+
1 => Level::WARN,
133+
2 => Level::INFO,
134+
3 => Level::DEBUG,
135+
_ => Level::TRACE,
136+
}),
137+
));
138+
tracing::subscriber::set_global_default(subscriber).map_err(|e| eyre!(e))?;
127139
}
128-
129140
Ok(())
130141
}
131142

132143
#[derive(Parser, Debug)]
133144
#[clap(author, version, about, long_about = None)]
134145
struct CliArgs {
135-
#[clap(short = 'v', long, action = clap::ArgAction::Count, default_value = "4")]
146+
#[clap(long, env = "VERBOSE", default_value = "2")]
136147
verbose: u8,
137148

138-
#[clap(long)]
149+
#[clap(long, env = "LOG_DIR")]
139150
log_dir: Option<String>,
140151

141-
#[clap(long, help = "Log rotation values: DAILY, HOURLY, MINUTELY, NEVER")]
152+
#[clap(long, env = "LOG_ROTATION", help = "Log rotation values: DAILY, HOURLY, MINUTELY, NEVER")]
142153
log_rotation: Option<String>,
143154

144-
#[clap(long, required = true)]
155+
#[clap(long, env = "BEACON_ENDPOINT", required = true)]
145156
beacon_endpoint: String,
146157

147-
#[clap(long, default_value = "10")]
158+
#[clap(long, env = "BEACON_CLIENT_TIMEOUT", default_value = "10")]
148159
beacon_client_timeout: u64,
149160

150-
#[clap(long, default_value = "6")]
161+
#[clap(long, env = "POLL_INTERVAL", default_value = "6")]
151162
poll_interval: u64,
152163

153-
#[clap(long, default_value = "0.0.0.0:8000")]
164+
#[clap(long, env = "LISTEN_ADDR", default_value = "0.0.0.0:8000")]
154165
listen_addr: String,
155166

156-
#[clap(long, required = true)]
167+
#[clap(long, env = "ORIGIN_BLOCK", required = true)]
157168
origin_block: String,
158169

159-
#[clap(long, default_value = "s3")]
170+
#[clap(long, env = "STORAGE_TYPE", default_value = "s3")]
160171
storage_type: String,
161172

162-
#[clap(long)]
173+
#[clap(long, env = "S3_ENDPOINT")]
163174
s3_endpoint: Option<String>,
164175

165-
#[clap(long)]
176+
#[clap(long, env = "S3_BUCKET")]
166177
s3_bucket: Option<String>,
167178

168-
#[clap(long)]
179+
#[clap(long, env = "S3_PATH")]
169180
s3_path: Option<String>,
170181

171-
#[clap(long, default_value = "false")]
182+
#[clap(long, env = "S3_COMPRESS", default_value = "false")]
172183
s3_compress: Option<bool>,
173-
#[clap(long)]
184+
#[clap(long, env = "FS_DIR")]
174185
fs_dir: Option<String>,
175186
}
176187

bin/archiver/src/main.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -171,45 +171,45 @@ pub fn setup_tracing(
171171

172172
#[derive(Parser, Serialize)]
173173
pub struct CliArgs {
174-
#[clap(short = 'v', long, action = clap::ArgAction::Count, default_value = "2")]
174+
#[clap(long, env = "VERBOSE", default_value = "2")]
175175
verbose: u8,
176176

177-
#[clap(long)]
177+
#[clap(long, env = "LOG_DIR")]
178178
log_dir: Option<String>,
179179

180-
#[clap(long, help = "Log rotation values: DAILY, HOURLY, MINUTELY, NEVER")]
180+
#[clap(long, env = "LOG_ROTATION", help = "Log rotation values: DAILY, HOURLY, MINUTELY, NEVER")]
181181
log_rotation: Option<String>,
182182

183-
#[clap(long, required = true)]
183+
#[clap(long, env = "BEACON_ENDPOINT", required = true)]
184184
beacon_endpoint: String,
185185

186-
#[clap(long, default_value = "10")]
186+
#[clap(long, env = "BEACON_CLIENT_TIMEOUT", default_value = "10")]
187187
beacon_client_timeout: u64,
188188

189-
#[clap(long, default_value = "6")]
189+
#[clap(long, env = "POLL_INTERVAL", default_value = "6")]
190190
poll_interval: u64,
191191

192-
#[clap(long, default_value = "0.0.0.0:8000")]
192+
#[clap(long, env = "LISTEN_ADDR", default_value = "0.0.0.0:8000")]
193193
listen_addr: String,
194194

195-
#[clap(long, required = true)]
195+
#[clap(long, env = "ORIGIN_BLOCK", required = true)]
196196
origin_block: String,
197197

198-
#[clap(long, default_value = "s3")]
198+
#[clap(long, env = "STORAGE_TYPE", default_value = "s3")]
199199
storage_type: String,
200200

201-
#[clap(long)]
201+
#[clap(long, env = "S3_ENDPOINT")]
202202
s3_endpoint: Option<String>,
203203

204-
#[clap(long)]
204+
#[clap(long, env = "S3_BUCKET")]
205205
s3_bucket: Option<String>,
206206

207-
#[clap(long)]
207+
#[clap(long, env = "S3_PATH")]
208208
s3_path: Option<String>,
209209

210-
#[clap(long, default_value = "false")]
210+
#[clap(long, env = "S3_COMPRESS", default_value = "false")]
211211
s3_compress: Option<bool>,
212-
#[clap(long)]
212+
#[clap(long, env = "FS_DIR")]
213213
fs_dir: Option<String>,
214214
}
215215

docker-compose.yaml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
version: "3.7"
2+
3+
services:
4+
api:
5+
build:
6+
context: .
7+
dockerfile: api.Dockerfile
8+
env_file:
9+
- .env
10+
ports:
11+
- "8000:8000"
12+
depends_on:
13+
- minio
14+
- create-buckets
15+
archiver:
16+
build:
17+
context: .
18+
dockerfile: archiver.Dockerfile
19+
env_file:
20+
- .env
21+
depends_on:
22+
- minio
23+
- create-buckets
24+
minio:
25+
restart: unless-stopped
26+
image: minio/minio:latest
27+
ports:
28+
- "9000:9000"
29+
- "9999:9999"
30+
environment:
31+
MINIO_ROOT_USER: admin
32+
MINIO_ROOT_PASSWORD: password
33+
entrypoint: minio server /data --console-address ":9999"
34+
create-buckets:
35+
image: minio/mc
36+
depends_on:
37+
- minio
38+
entrypoint: >
39+
/bin/sh -c "
40+
/usr/bin/mc alias set minio http://minio:9000 admin password;
41+
/usr/bin/mc mb minio/blobs;
42+
/usr/bin/mc anonymous set public minio/blobs;
43+
exit 0;
44+
"

0 commit comments

Comments
 (0)