Skip to content
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
22 changes: 17 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,53 @@

# Stage 1: Build the binary

FROM rust:slim-bullseye as builder
FROM rust:slim-bookworm AS builder

WORKDIR /app

COPY --link . /app

RUN for i in 1 2 3; do apt-get update && apt-get install --fix-missing -y cmake curl clang git pkg-config libssl-dev libdw-dev libpq-dev lld && break || sleep 10; done
RUN apt-get update \
&& apt-get install --no-install-recommends --fix-missing -y \
cmake \
curl \
clang \
make \
git \
pkg-config \
libssl-dev \
libdw-dev \
libpq-dev \
lld \
&& rm -rf /var/lib/apt/lists/*
ENV CARGO_NET_GIT_FETCH_WITH_CLI true

Check warning on line 24 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
# TODO: Fix this with real processors.
RUN cargo build --locked --release -p processor && ls -lah target/release/
RUN cp target/release/processor /usr/local/bin

# add build info
ARG GIT_TAG
ENV GIT_TAG ${GIT_TAG}

Check warning on line 31 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
ARG GIT_BRANCH
ENV GIT_BRANCH ${GIT_BRANCH}

Check warning on line 33 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
ARG GIT_SHA
ENV GIT_SHA ${GIT_SHA}

Check warning on line 35 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

# Stage 2: Create the final image

FROM debian:bullseye-slim
FROM debian:bookworm-slim

COPY --from=builder /usr/local/bin/processor /usr/local/bin

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && apt-get install --no-install-recommends --fix-missing -y \
libssl1.1 \
libssl3 \
ca-certificates \
net-tools \
tcpdump \
iproute2 \
netcat \
netcat-openbsd \
libdw-dev \
libpq-dev \
curl
Expand All @@ -45,11 +57,11 @@

# add build info
ARG GIT_TAG
ENV GIT_TAG ${GIT_TAG}

Check warning on line 60 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
ARG GIT_BRANCH
ENV GIT_BRANCH ${GIT_BRANCH}

Check warning on line 62 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
ARG GIT_SHA
ENV GIT_SHA ${GIT_SHA}

Check warning on line 64 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

# The health check port
EXPOSE 8084
Expand Down
22 changes: 17 additions & 5 deletions Dockerfile.address-reputation-api
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,52 @@

# Stage 1: Build the binary

FROM rust:slim-bullseye as builder
FROM rust:slim-bookworm AS builder

WORKDIR /app

COPY --link . /app

RUN for i in 1 2 3; do apt-get update && apt-get install --fix-missing -y cmake curl clang git pkg-config libssl-dev libdw-dev libpq-dev lld && break || sleep 10; done
RUN apt-get update \
&& apt-get install --no-install-recommends --fix-missing -y \
cmake \
curl \
clang \
make \
git \
pkg-config \
libssl-dev \
libdw-dev \
libpq-dev \
lld \
&& rm -rf /var/lib/apt/lists/*
ENV CARGO_NET_GIT_FETCH_WITH_CLI true

Check warning on line 24 in Dockerfile.address-reputation-api

View workflow job for this annotation

GitHub Actions / BuildAddressReputationApi

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
RUN cargo build --locked --release -p address-reputation-api && ls -lah target/release/
RUN cp target/release/address-reputation-api /usr/local/bin

# add build info
ARG GIT_TAG
ENV GIT_TAG ${GIT_TAG}

Check warning on line 30 in Dockerfile.address-reputation-api

View workflow job for this annotation

GitHub Actions / BuildAddressReputationApi

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
ARG GIT_BRANCH
ENV GIT_BRANCH ${GIT_BRANCH}

Check warning on line 32 in Dockerfile.address-reputation-api

View workflow job for this annotation

GitHub Actions / BuildAddressReputationApi

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
ARG GIT_SHA
ENV GIT_SHA ${GIT_SHA}

Check warning on line 34 in Dockerfile.address-reputation-api

View workflow job for this annotation

GitHub Actions / BuildAddressReputationApi

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

# Stage 2: Create the final image

FROM debian:bullseye-slim
FROM debian:bookworm-slim

COPY --from=builder /usr/local/bin/address-reputation-api /usr/local/bin

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && apt-get install --no-install-recommends --fix-missing -y \
libssl1.1 \
libssl3 \
ca-certificates \
net-tools \
tcpdump \
iproute2 \
netcat \
netcat-openbsd \
libdw-dev \
libpq-dev \
curl
Expand All @@ -44,11 +56,11 @@

# add build info
ARG GIT_TAG
ENV GIT_TAG ${GIT_TAG}

Check warning on line 59 in Dockerfile.address-reputation-api

View workflow job for this annotation

GitHub Actions / BuildAddressReputationApi

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
ARG GIT_BRANCH
ENV GIT_BRANCH ${GIT_BRANCH}

Check warning on line 61 in Dockerfile.address-reputation-api

View workflow job for this annotation

GitHub Actions / BuildAddressReputationApi

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
ARG GIT_SHA
ENV GIT_SHA ${GIT_SHA}

Check warning on line 63 in Dockerfile.address-reputation-api

View workflow job for this annotation

GitHub Actions / BuildAddressReputationApi

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

# API server port (matches ServerConfig default; override via config file)
EXPOSE 8080
Expand Down
49 changes: 48 additions & 1 deletion processor/src/processors/default/models/table_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ pub struct TableMetadata {
impl TableMetadata {
pub fn from_write_table_item(table_item: &WriteTableItem) -> Self {
Self {
handle: table_item.handle.to_string(),
// Proto table handles are not always 64-char padded. table_items /
// current_table_items already standardize; keep this PK in the same
// form so joins on handle succeed.
handle: standardize_address(&table_item.handle.to_string()),
key_type: table_item.data.as_ref().unwrap().key_type.clone(),
value_type: table_item.data.as_ref().unwrap().value_type.clone(),
}
Expand Down Expand Up @@ -315,3 +318,47 @@ impl From<TableMetadata> for PostgresTableMetadata {
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use aptos_indexer_processor_sdk::aptos_protos::transaction::v1::{
WriteTableData, WriteTableItem,
};

fn write_table_item(handle: &str) -> WriteTableItem {
WriteTableItem {
handle: handle.to_string(),
key: "0x1".to_string(),
data: Some(WriteTableData {
key: "\"1\"".to_string(),
key_type: "u64".to_string(),
value: "\"2\"".to_string(),
value_type: "u64".to_string(),
}),
..Default::default()
}
}

#[test]
fn table_metadata_handle_matches_standardized_table_item_handle() {
let raw_handle = "0xabc";
assert_ne!(
standardize_address(raw_handle),
raw_handle,
"precondition: proto table handles can be shorter than 64 hex chars"
);

let item = write_table_item(raw_handle);
let (table_item, current) =
TableItem::from_write_table_item(&item, 0, 1, 1, chrono::NaiveDateTime::default());
let metadata = TableMetadata::from_write_table_item(&item);

let expected = standardize_address(raw_handle);
assert_eq!(table_item.table_handle, expected);
assert_eq!(current.table_handle, expected);
assert_eq!(metadata.handle, expected);
assert_eq!(metadata.key_type, "u64");
assert_eq!(metadata.value_type, "u64");
}
}
5 changes: 4 additions & 1 deletion scripts/rust_lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ fi
set -e
set -x

cargo +nightly xclippy
# Run clippy on the pinned STABLE toolchain (from rust-toolchain.toml), NOT
# nightly. Latest nightly makes Infallible an alias of !, which breaks
# allocative (impl Allocative for both). Stable clippy matches the build toolchain.
cargo xclippy

# We require the nightly build of cargo fmt
# to provide stricter rust formatting.
Expand Down
Loading