-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.sink
More file actions
59 lines (45 loc) · 2.29 KB
/
Dockerfile.sink
File metadata and controls
59 lines (45 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Stage 1: Build the Substreams package from source
FROM rust:slim AS builder
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install Substreams CLI
RUN curl -sSL https://github.com/streamingfast/substreams/releases/latest/download/substreams_linux_x86_64.tar.gz | tar xz -C /usr/local/bin
# Add WASM target
RUN rustup target add wasm32-unknown-unknown
# Copy source code
WORKDIR /build/tron
COPY tron/ .
# Build WASM module and package
RUN cargo build --target wasm32-unknown-unknown --release && \
substreams pack ./substreams.yaml
# Stage 2: Runtime image
FROM ubuntu:22.04
# Install dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
curl \
&& rm -rf /var/lib/apt/lists/*
# Download substreams-sink-sql binary (v4.12.0) - detect architecture
ARG TARGETARCH
RUN ARCH=$(echo ${TARGETARCH:-amd64} | sed 's/amd64/x86_64/' | sed 's/arm64/arm64/') && \
curl -sSL "https://github.com/streamingfast/substreams-sink-sql/releases/download/v4.12.0/substreams-sink-sql_linux_${ARCH}.tar.gz" -o /tmp/sink.tar.gz && \
tar xzf /tmp/sink.tar.gz -C /usr/local/bin/ && \
rm /tmp/sink.tar.gz && \
chmod +x /usr/local/bin/substreams-sink-sql
# Copy the built .spkg from builder stage and schema
COPY --from=builder /build/tron/request-network-tron-*.spkg /app/
COPY tron/schema.sql /app/
WORKDIR /app
# Environment variables (override in deployment)
ENV DSN=""
ENV SUBSTREAMS_API_TOKEN=""
# Endpoint configured via SUBSTREAMS_ENDPOINTS_CONFIG_TRON env var
ENV SUBSTREAMS_ENDPOINTS_CONFIG_TRON="mainnet.tron.streamingfast.io:443"
# Create entrypoint script - dynamically find the .spkg file
RUN printf '#!/bin/bash\nset -e\n\nSPKG=$(ls /app/request-network-tron-*.spkg 2>/dev/null | head -1)\nif [ -z "$SPKG" ]; then\n echo "ERROR: No .spkg file found in /app/"\n exit 1\nfi\necho "Using package: $SPKG"\n\n# Setup the database schema first\necho "Setting up database schema..."\nsubstreams-sink-sql setup "$DSN" "$SPKG" || true\n\n# Run the sink\necho "Starting sink..."\nexec substreams-sink-sql run "$DSN" "$SPKG"\n' > /entrypoint.sh && \
chmod +x /entrypoint.sh
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD pgrep substreams-sink-sql || exit 1
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]