Skip to content
Draft
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
23 changes: 23 additions & 0 deletions docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Ignore common build artifacts and large nix store paths
result
result.tar.gz
result-*.tar.gz
dist
dist-newstyle
dist/*
*.o
*.hi
.stack-work
.ghc.environment.*
.cabal-sandbox
.cabal-sandbox/*
node_modules
.git
*.lock
**/.DS_Store

# Ignore Nix store references and temporary files
/nix
*.drv
*.nar

29 changes: 29 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Lightweight Dockerfile for a static cardano-db-sync binary
#
# Usage (example):
# 1. Build a static executable with Nix:
# nix build .#cardano-db-sync-linux
# 2. Build the image from the project root:
# docker build -f docker/Dockerfile -t cardano-db-sync:lightweight .
#
# Note: Since result/ is a Nix symlink, Docker may have issues following it.
# If this fails, you can dereference the symlink first:
# mkdir -p docker/build && cp -L result/*.tar.gz docker/build/
# docker build -f docker/Dockerfile -t cardano-db-sync:lightweight .
#
# Important: this Dockerfile assumes the binary is a fully static executable
# (statically linked). If it's not static, use a small base image (see docs).

# Stage 1: Extract the binary from the tarball
FROM busybox:latest AS extractor
ARG TARBALL
# ADD automatically extracts tarballs
ADD ${TARBALL} /tmp/extract/
RUN find /tmp/extract -name cardano-db-sync -type f -exec mv {} /cardano-db-sync \; && \
chmod +x /cardano-db-sync

# Stage 2: Minimal runtime image
FROM scratch
COPY --from=extractor /cardano-db-sync /usr/local/bin/cardano-db-sync
ENTRYPOINT ["/usr/local/bin/cardano-db-sync"]
CMD ["--help"]
65 changes: 65 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
Lightweight Docker image for cardano-db-sync
==========================================

This folder contains a minimal Docker context and `Dockerfile` intended for use with
a statically-built `cardano-db-sync` executable produced by Nix.

Why this exists
---------------

Building the full NixOS-based Docker image is a reproducible approach, but can lead
to large images and bundled configuration that make customization more difficult.
This lightweight approach lets users build a small, standard Docker image and supply
configuration at runtime via volumes or create their own derived images.

Quickstart
----------

1. Build the cardano-db-sync package with Nix:

```bash
nix build .#cardano-db-sync-linux
```

2. a) Extract the binary from the tarball and copy it to this directory:

```bash
tar xf result/cardano-db-sync-*-linux.tar.gz -C docker/ --strip-components=1 ./bin/cardano-db-sync
```

2. b) move the binary:

```bash
mv docker/bin/cardano-db-sync ./docker && rm -r docker/bin/
```

3. Build the image:

```bash
docker build -t cardano-db-sync:lightweight docker/
```

4. get the configs:
- https://book.world.dev.cardano.org/environments/preprod/db-sync-config.json

4. Run the container and mount your configuration (recommended):

```bash
docker run -v $PWD/environments/preprod:/config \
--env POSTGRES_HOST=postgres --env POSTGRES_PORT=5432 \
cardano-db-sync:lightweight --config $PWD/config/db-sync-config.json \
--socket-path "$HOME/workshop/cardano-node/configuration/preprod/db/node.socket" \
--schema-dir /schema
```

Notes
-----

- The `Dockerfile` uses `FROM scratch` and therefore requires the binary to be
statically linked. If you need dynamic linking, change the base image to a small
distro such as `ubuntu:24.04` or `debian:bookworm-slim`.
- The image intentionally omits network configuration files. Use volumes or a
derived image if you want to embed configs.

See also: the project's `doc/docker.md` for more details and guidance.

12 changes: 12 additions & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail

# Dereference the Nix result symlink
TARBALL=$(basename "$(readlink -f result/*.tar.gz)")
cp -L result/*.tar.gz docker/

# Build with the exact tarball name as build arg
docker build --build-arg TARBALL="$TARBALL" -t cardano-db-sync:lightweight docker/

# Cleanup
rm -f docker/*.tar.gz
Loading