Skip to content

Commit ff5090e

Browse files
committed
move frontend stuff to frontend; add docker-compose
1 parent 3138961 commit ff5090e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+129
-7
lines changed

README.md

+5-4

backend.Dockerfile

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Stage 1: Build
2+
FROM rust as builder
3+
4+
# Set the working directory inside the container
5+
WORKDIR /usr/src/app/backend
6+
7+
# Copy only Cargo files first (to leverage Docker caching)
8+
COPY backend/Cargo.toml backend/Cargo.lock ./
9+
10+
RUN cargo fetch
11+
12+
# Copy the rest of the source code
13+
COPY backend .
14+
15+
# Compile the Rust application
16+
RUN cargo build
17+
18+
# Stage 2: Runtime
19+
FROM rust
20+
21+
# Set working directory in the final container
22+
WORKDIR /usr/src/app/backend
23+
24+
# Copy the compiled binary from the builder stage
25+
COPY --from=builder /usr/src/app/backend/target/debug/backend .
26+
COPY backend/usage_keys.json .
27+
28+
# Expose the backend service port (should match docker-compose.yml)
29+
EXPOSE 3000
30+
31+
# Run the compiled Rust backend
32+
CMD ["./backend"]

backend/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ log = "0.4.25"
2121
[dev-dependencies]
2222
mockito = "1.6.1"
2323
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
24+
25+
[[bin]]
26+
name = "backend"
27+
path = "src/main.rs"

backend/src/usage.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl UsageMonitoringConfig {
111111
/// Read keys used in reporting usages from a json file.
112112
fn load_usage_keys() -> UsageStatsKeys {
113113
// Path relative to backend
114-
let data = fs::read_to_string("../usage_keys.json").expect("Unable to read file");
114+
let data = fs::read_to_string("usage_keys.json").expect("Unable to read file");
115115
serde_json::from_str(&data).expect("JSON parsing failed")
116116
}
117117
}
@@ -199,7 +199,6 @@ pub async fn usage_monitoring_task(shared_stats: SharedUsageStats, config: &Usag
199199
start_time = time_30d_earlier;
200200
}
201201

202-
info!("start_time {}", start_time);
203202
let mut locked_stats = shared_stats.lock().await;
204203
let result = fetch_user_ops(&http_client, &config.user_ops_query_url, start_time, now).await;
205204

File renamed without changes.

docker-compose.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
services:
2+
backend:
3+
build:
4+
context: .
5+
dockerfile: backend.Dockerfile
6+
container_name: strata_dashboards_backend
7+
environment:
8+
RPC_URL: https://strataclient1ff4bc1df.devnet-annapurna.stratabtc.org
9+
BUNDLER_URL: https://bundler.devnet-annapurna.stratabtc.org/health
10+
# TODO: Update the following two urls after strata blockscout service includes
11+
# updated user-ops-indexer supporting timestamp-based filtering
12+
USER_OPS_QUERY_URL: http://localhost/api/v2/proxy/account-abstraction/operations
13+
ACCOUNTS_QUERY_URL: http://localhost/api/v2/proxy/account-abstraction/accounts
14+
USAGE_STATS_REFETCH_INTERVAL_S: 120
15+
ports:
16+
- "3000:3000"
17+
18+
frontend:
19+
build:
20+
context: .
21+
dockerfile: frontend.Dockerfile
22+
container_name: strata_dashboards_frontend
23+
depends_on:
24+
- backend
25+
ports:
26+
- "5173:5173"
27+
environment:
28+
VITE_USAGE_STATS_REFETCH_INTERVAL_S: 60

frontend.Dockerfile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Use Node.js for development
2+
FROM node:20
3+
4+
WORKDIR /app/frontend
5+
6+
# Copy package.json and lock file first to optimize caching
7+
COPY frontend/package.json frontend/package-lock.json ./
8+
9+
# Install dependencies
10+
RUN npm install
11+
12+
# Copy the rest of the project files
13+
COPY frontend .
14+
15+
COPY backend/usage_keys.json public/usage_keys.json
16+
17+
# Expose the Vite development server port (default is 5173)
18+
EXPOSE 5173
19+
20+
# Start the Vite development server
21+
CMD ["npm", "run", "dev", "--", "--host"]
File renamed without changes.

frontend/Dockerfile

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Use Node.js for development
2+
FROM node:20
3+
4+
WORKDIR /app
5+
6+
# Copy package.json and lock file first to optimize caching
7+
COPY strata-dashboards/package.json package-lock.json ./
8+
9+
# Install dependencies
10+
RUN npm install
11+
12+
# Copy the rest of the project files
13+
COPY . .
14+
15+
# Copy usage_keys.json if available (from build context)
16+
ARG USAGE_KEYS_PATH
17+
COPY usage_keys.json ${USAGE_KEYS_PATH}
18+
19+
# Ensure the file exists (fallback to empty JSON)
20+
RUN test -f ${USAGE_KEYS_PATH} || echo '{}' > ${USAGE_KEYS_PATH}
21+
22+
# Expose the Vite development server port (default is 5173)
23+
EXPOSE 5173
24+
25+
# Start the Vite development server
26+
CMD ["npm", "run", "start"]

frontend/entrypoint.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
# Copy usage_keys.json if it exists at runtime
4+
if [ -f "/mnt/usage_keys.json" ]; then
5+
cp /mnt/usage_keys.json /app/public/usage_keys.json
6+
else
7+
echo '{}' > /app/public/usage_keys.json # Ensure it exists with default data
8+
fi
9+
10+
# Start the frontend
11+
exec npm run start
File renamed without changes.
File renamed without changes.
File renamed without changes.

strata-dashboards/package.json renamed to frontend/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"dev": "vite",
88
"start": "npm run build && vite",
9-
"build": "cp ../usage_keys.json ./public/usage_keys.json && tsc -b && vite build",
9+
"build": "cp ../backend/usage_keys.json ./public/usage_keys.json && tsc -b && vite build",
1010
"lint": "eslint .",
1111
"preview": "vite preview"
1212
},
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)