diff --git a/.env.sample b/.env.sample index 5b8cf377..0723d7d4 100644 --- a/.env.sample +++ b/.env.sample @@ -1,5 +1,5 @@ -DATABASE_URL=postgres://postgres:password@postgres:5433/namada-indexer +POSTGRES_PASSWORD= TENDERMINT_URL=http://host.docker.internal:26657 -CACHE_URL=redis://dragonfly:6379 WEBSERVER_PORT=5001 -DATABASE_URL_TEST=postgres://postgres:password@0.0.0.0:5433 +# Binds the webserver's port to the localhost by default. if you need to make it public bind it to 0.0.0.0 or your server IP +WEBSERVER_HOST_IP=127.0.0.1 diff --git a/.gitignore b/.gitignore index fa4b55c2..56f2134d 100644 --- a/.gitignore +++ b/.gitignore @@ -82,8 +82,10 @@ rust-project.json # End of https://www.toptal.com/developers/gitignore/api/osx,git,macos,rust-analyzer,rust .vscode +.idea swagger-codegen.json # Ignore docker compose override files docker-compose.override* +overrides diff --git a/docker-compose-db.yml b/docker-compose-db.yml deleted file mode 100644 index 8f00eba5..00000000 --- a/docker-compose-db.yml +++ /dev/null @@ -1,33 +0,0 @@ -services: - postgres: - image: postgres:16-alpine - command: ["postgres", "-c", "listen_addresses=0.0.0.0", "-c", "max_connections=200", "-p", "5433"] - expose: - - "5433" - ports: - - "5433:5433" - environment: - POSTGRES_PASSWORD: password - POSTGRES_USER: postgres - PGUSER: postgres - POSTGRES_DB: namada-indexer - healthcheck: - test: ["CMD-SHELL", "pg_isready -U postgres -d namada-indexer -h localhost -p 5433"] - interval: 5s - timeout: 5s - retries: 5 - restart: unless-stopped - - dragonfly: - image: docker.dragonflydb.io/dragonflydb/dragonfly - command: --logtostderr --cache_mode=true --port 6379 -dbnum 1 - ulimits: - memlock: -1 - ports: - - "6379:6379" - healthcheck: - test: ["CMD-SHELL", "redis-cli ping | grep PONG"] - interval: 5s - timeout: 5s - retries: 5 - restart: unless-stopped diff --git a/docker-compose.yml b/docker-compose.yml index 2663f43e..7b12277c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,41 +1,66 @@ +name: ${NAMADA_INDEXER_PROJECT_NAME:-namada-indexer} x-defaults: &defaults restart: unless-stopped depends_on: - postgres: - condition: service_healthy - dragonfly: - condition: service_healthy + postgres: + condition: service_healthy + dragonfly: + condition: service_healthy build: &build context: . dockerfile: Dockerfile - args: &build-args - DATABASE_URL: ${DATABASE_URL} - TENDERMINT_URL: ${TENDERMINT_URL} - CACHE_URL: ${CACHE_URL} - WEBSERVER_PORT: ${WEBSERVER_PORT} environment: &env-vars - <<: *build-args - command: "./service \ - --tendermint-url ${TENDERMINT_URL} \ - --database-url ${DATABASE_URL}" + DATABASE_URL: ${DATABASE_URL:-postgres://postgres:${POSTGRES_PASSWORD:?}@postgres:5432/namada-indexer} + TENDERMINT_URL: ${TENDERMINT_URL} + CACHE_URL: ${CACHE_URL:-redis://dragonfly:6379} + command: | + ./service extra_hosts: - - "host.docker.internal:host-gateway" - -include: - - docker-compose-db.yml + - "host.docker.internal:host-gateway" services: + postgres: + image: postgres:16-alpine + command: [ "postgres", "-c", "max_connections=200" ] + expose: + - "5432" + environment: + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?} + POSTGRES_DB: namada-indexer + healthcheck: + test: [ "CMD-SHELL", "pg_isready -U postgres -d namada-indexer" ] + interval: 5s + timeout: 5s + retries: 5 + restart: unless-stopped + volumes: + - type: volume + source: postgres-data + target: /var/lib/postgresql/data + + dragonfly: + image: docker.dragonflydb.io/dragonflydb/dragonfly + command: --logtostderr --cache_mode=true --port 6379 -dbnum 1 + ulimits: + memlock: -1 + expose: + - "6379" + healthcheck: + test: [ "CMD-SHELL", "redis-cli ping | grep PONG" ] + interval: 5s + timeout: 5s + retries: 5 + restart: unless-stopped + chain: <<: *defaults image: namada/chain-indexer - command: "./service \ - --tendermint-url ${TENDERMINT_URL} \ - --database-url ${DATABASE_URL} \ - --initial-query-retry-time=15" + environment: + <<: *env-vars + INITIAL_QUERY_RETRY_TIME: ${INITIAL_QUERY_RETRY_TIME:-15} build: <<: *build args: - <<: *build-args PACKAGE: chain governance: @@ -44,7 +69,6 @@ services: build: <<: *build args: - <<: *build-args PACKAGE: governance pos: @@ -53,7 +77,6 @@ services: build: <<: *build args: - <<: *build-args PACKAGE: pos rewards: @@ -62,7 +85,6 @@ services: build: <<: *build args: - <<: *build-args PACKAGE: rewards parameters: @@ -71,7 +93,6 @@ services: build: <<: *build args: - <<: *build-args PACKAGE: parameters transactions: @@ -80,20 +101,19 @@ services: build: <<: *build args: - <<: *build-args PACKAGE: transactions webserver: <<: *defaults image: namada/webserver-indexer build: - context: . - dockerfile: Dockerfile + <<: *build args: PACKAGE: webserver - command: "./service" + expose: + - 5001 ports: - - ${WEBSERVER_PORT}:5001 + - ${WEBSERVER_HOST_IP:-127.0.0.1}:${WEBSERVER_PORT:-5001}:5001 environment: <<: *env-vars healthcheck: @@ -103,3 +123,5 @@ services: retries: 5 restart: unless-stopped +volumes: + postgres-data: \ No newline at end of file diff --git a/webserver/Dockerfile b/webserver/Dockerfile deleted file mode 100644 index 39a59f76..00000000 --- a/webserver/Dockerfile +++ /dev/null @@ -1,26 +0,0 @@ -FROM lukemathwalker/cargo-chef:latest-rust-1.79-bookworm AS chef -WORKDIR /app - -FROM chef AS planner -COPY . . -RUN cargo chef prepare --recipe-path recipe.json - -FROM chef AS builder -COPY --from=planner /app/recipe.json recipe.json - -RUN apt-get update && apt-get install -y protobuf-compiler build-essential clang-tools-14 - -RUN cargo chef cook --release --recipe-path recipe.json - -COPY . . -RUN cargo build --release --package webserver - -FROM debian:bookworm-slim AS runtime -WORKDIR /app -COPY --from=builder /app/target/release/webserver /app/webserver - -RUN apt-get update && apt-get install -y libpq5 curl - -WORKDIR /app - -CMD ["./webserver"]