Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Dockerfile
README.md
.github/
52 changes: 52 additions & 0 deletions .github/workflows/ci-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Docker CI

on:
pull_request:
branches: ['main']
paths: ['Dockerfile','bin','config/**','.github/workflows/ci-docker.yml']

env:
REGISTRY: ghcr.io
IMAGE_NAME: cloudstruct/cardano-db-sync

jobs:
build-amd64:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: qemu
uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: build
uses: docker/build-push-action@v2
with:
context: .
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-arm64:
runs-on: self-hosted
steps:
- uses: actions/checkout@v2
- name: qemu
uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: build
uses: docker/build-push-action@v2
with:
context: .
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
16 changes: 16 additions & 0 deletions .github/workflows/conventional-commits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# The below is pulled from upstream and slightly modified
# https://github.com/webiny/action-conventional-commits/blob/master/README.md#usage

name: Conventional Commits

on:
pull_request:

jobs:
build:
name: Conventional Commits
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: webiny/action-conventional-commits@v1.0.3
111 changes: 111 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: publish

on:
push:
branches: ['main']
release:
types: ['published']

concurrency: ${{ github.ref }}

env:
REGISTRY: ghcr.io
IMAGE_NAME: cloudstruct/cardano-db-sync

jobs:
build-amd64:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
- uses: docker/setup-buildx-action@v1
- name: login
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=false
tags: |
type=schedule,suffix=-amd64
type=ref,event=branch,suffix=-amd64
type=ref,event=tag,suffix=-amd64
type=ref,event=pr,suffix=-amd64
- name: push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-arm64:
runs-on: self-hosted
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
- uses: docker/setup-buildx-action@v1
- name: login
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=false
tags: |
type=schedule,suffix=-arm64v8
type=ref,event=branch,suffix=-arm64v8
type=ref,event=tag,suffix=-arm64v8
type=ref,event=pr,suffix=-arm64v8
- name: push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
multi-arch-manifest:
runs-on: ubuntu-latest
needs: [build-amd64, build-arm64]
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
- uses: docker/setup-buildx-action@v1
- name: login
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=false
tags: |
type=ref,event=branch
type=ref,event=tag
- name: manifest
run: docker manifest create ${{ steps.meta.outputs.tags }} --amend ${{ steps.meta.outputs.tags }}-amd64 --amend ${{ steps.meta.outputs.tags }}-arm64v8
- name: push
run: docker manifest push ${{ steps.meta.outputs.tags }}
117 changes: 117 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
FROM debian:stable-slim as builder
ARG CABAL_VERSION=3.6.2.0
ARG GHC_VERSION=8.10.7

WORKDIR /code

# system dependencies
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y && \
apt-get install -y \
automake \
build-essential \
pkg-config \
libffi-dev \
libgmp-dev \
libnuma-dev \
libpq-dev \
libssl-dev \
libsystemd-dev \
libtinfo-dev \
llvm-dev \
zlib1g-dev \
make \
g++ \
tmux \
git \
jq \
wget \
libncursesw5 \
libtool \
autoconf

# cabal
ENV CABAL_VERSION=${CABAL_VERSION}
ENV PATH="/root/.cabal/bin:/root/.ghcup/bin:/root/.local/bin:$PATH"
RUN wget https://downloads.haskell.org/~cabal/cabal-install-${CABAL_VERSION}/cabal-install-${CABAL_VERSION}-$(uname -m)-linux-deb10.tar.xz \
&& tar -xf cabal-install-${CABAL_VERSION}-$(uname -m)-linux-deb10.tar.xz \
&& rm cabal-install-${CABAL_VERSION}-$(uname -m)-linux-deb10.tar.xz \
&& mkdir -p ~/.local/bin \
&& mv cabal ~/.local/bin/ \
&& cabal update && cabal --version

# GHC
ENV GHC_VERSION=${GHC_VERSION}
RUN wget https://downloads.haskell.org/~ghc/${GHC_VERSION}/ghc-${GHC_VERSION}-$(uname -m)-deb10-linux.tar.xz \
&& tar -xf ghc-${GHC_VERSION}-$(uname -m)-deb10-linux.tar.xz \
&& rm ghc-${GHC_VERSION}-$(uname -m)-deb10-linux.tar.xz \
&& cd ghc-${GHC_VERSION} \
&& ./configure \
&& make install

# Libsodium
RUN git clone https://github.com/input-output-hk/libsodium && \
cd libsodium && \
git checkout 66f017f1 && \
./autogen.sh && \
./configure && \
make && \
make install
ENV LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
ENV PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"

# secp256k1
RUN git clone https://github.com/bitcoin-core/secp256k1 && \
cd secp256k1 && \
git checkout ac83be33 && \
./autogen.sh && \
./configure --enable-module-schnorrsig --enable-experimental && \
make && \
make install

FROM builder as cardano-db-sync-build
# Install cardano-db-sync
ARG DBSYNC_VERSION=13.0.4
ENV DBSYNC_VERSION=${DBSYNC_VERSION}
RUN echo "Building tags/${DBSYNC_VERSION}..." \
&& echo tags/${DBSYNC_VERSION} > /CARDANO_BRANCH \
&& git clone https://github.com/input-output-hk/cardano-db-sync.git \
&& cd cardano-db-sync\
&& git fetch --all --recurse-submodules --tags \
&& git tag \
&& git checkout tags/${DBSYNC_VERSION} \
&& cabal configure --with-compiler=ghc-$GHC_VERSION \
&& cabal build cardano-db-sync \
&& mkdir -p /root/.local/bin/ \
&& cp -p dist-newstyle/build/$(uname -m)-linux/ghc-$GHC_VERSION/cardano-db-sync-${DBSYNC_VERSION}/build/cardano-db-sync/cardano-db-sync /root/.local/bin/ \
&& rm -rf /root/.cabal/packages \
&& rm -rf /usr/local/lib/ghc-8.10.7/ /usr/local/share/doc/ghc-8.10.7/ \
&& rm -rf /code/cardano-db-sync/dist-newstyle/ \
&& rm -rf /root/.cabal/store/ghc-8.10.7

FROM debian:stable-slim as cardano-db-sync
ENV LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
ENV PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
COPY --from=cardano-db-sync-build /usr/local/lib/ /usr/local/lib/
COPY --from=cardano-db-sync-build /usr/local/include/ /usr/local/include/
COPY --from=cardano-db-sync-build /root/.local/bin/cardano-* /code/cardano-db-sync/scripts/postgresql-setup.sh /usr/local/bin/
COPY --from=cardano-db-sync-build /code/cardano-db-sync/schema/ /opt/cardano/schema/
COPY bin/ /bin/
COPY config/ /opt/cardano/config/
RUN apt-get update -y && \
apt-get install -y \
libffi7 \
libgmp10 \
libncursesw5 \
libnuma1 \
libsystemd0 \
libssl1.1 \
libtinfo6 \
llvm-11-runtime \
pkg-config \
postgresql-client \
zlib1g && \
chmod +x /usr/local/bin/* && \
rm -rf /var/lib/apt/lists/*
EXPOSE 8080
ENTRYPOINT ["/bin/entry-point"]
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# docker-cardano-db-sync
# docker-cardano-db-sync
Builds a cardano-db-sync on debian
46 changes: 46 additions & 0 deletions bin/entry-point
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

set -e
mkdir -p /configuration
if [[ ! -f /configuration/pgpass ]]; then
gen-pgpass /run/secrets
fi
export PGPASSFILE=/configuration/pgpass
mkdir -p -m 1777 /tmp
set -euo pipefail
if [[ ! -z ${RESTORE_SNAPSHOT:-} ]]; then
__base=$(basename ${RESTORE_SNAPSHOT})
__mark=${__base}.restored
if [[ ! -f ${RESTORED_MARKER} ]]; then
if [[ ${RESTORE_SNAPSHOT} =~ ^https://.* ]]; then
echo "Downloading snapshot ${RESTORE_SNAPSHOT} ..."
curl -LOC - "${RESTORE_SNAPSHOT}"
curl -LO "${RESTORE_SNAPSHOT}.sha256sum"
sha256sum -c "${__base}.sha256sum"
__snap=${__base}
else
__snap=${RESTORE_SNAPSHOT}
fi
rm -f /var/lib/cexplorer/*.lstate
postgresql-setup.sh --restore-snapshot ${__snap} /var/lib/cexplorer
touch ${RESTORED_MARKER}
rm -f ${__snap}{,.sha256sum,.asc}
fi
fi

if [[ -z ${NETWORK} ]]; then
echo "Connecting to network specified in configuration.yaml"
exec cardano-db-sync \
--schema-dir /opt/cardano/schema \
--state-dir /var/lib/cexplorer ${@}
else
echo "Connecting to network: ${NETWORK}"
export CARDANO_NODE_SOCKET_PATH=${CARDANO_NODE_SOCKET_PATH:-/node-ipc/node.socket}
mkdir -p log-dir # do we need this?
exec cardano-db-sync \
--config /opt/cardano/config/${NETWORK}-db-sync-config.json \
--schema-dir /opt/cardano/schema \
--socket-path ${CARDANO_NODE_SOCKET_PATH} \
--state-dir /var/lib/cexplorer

fi
10 changes: 10 additions & 0 deletions bin/gen-pgpass
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

__dir=${1}
echo ${__dir}
echo "Generating PGPASS file"
POSTGRES_DB=${POSTGRES_DB:-$(< ${__dir}/postgres_db)}
POSTGRES_USER=${POSTGRES_USER:-$(< ${__dir}/postgres_user)}
POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-$(< ${__dir}/postgres_password)}
echo "${POSTGRES_HOST}:${POSTGRES_PORT}:${POSTGRES_DB}:${POSTGRES_USER}:${POSTGRES_PASSWORD}" > /configuration/pgpass
chmod 0600 /configuration/pgpass
Loading