Skip to content

Commit d08da7f

Browse files
authored
Merge pull request #1 from cloudstruct/feat/initial-image
feat: initial image
2 parents 37cff96 + a4aa197 commit d08da7f

28 files changed

+16955
-1
lines changed

Diff for: .dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Dockerfile
2+
README.md
3+
.github/

Diff for: .github/workflows/ci-docker.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Docker CI
2+
3+
on:
4+
pull_request:
5+
branches: ['main']
6+
paths: ['Dockerfile','bin','config/**','.github/workflows/ci-docker.yml']
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: cloudstruct/cardano-db-sync
11+
12+
jobs:
13+
build-amd64:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: qemu
18+
uses: docker/setup-qemu-action@v1
19+
- uses: docker/setup-buildx-action@v1
20+
- id: meta
21+
uses: docker/metadata-action@v3
22+
with:
23+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
24+
- name: build
25+
uses: docker/build-push-action@v2
26+
with:
27+
context: .
28+
push: false
29+
tags: ${{ steps.meta.outputs.tags }}
30+
labels: ${{ steps.meta.outputs.labels }}
31+
cache-from: type=gha
32+
cache-to: type=gha,mode=max
33+
build-arm64:
34+
runs-on: self-hosted
35+
steps:
36+
- uses: actions/checkout@v2
37+
- name: qemu
38+
uses: docker/setup-qemu-action@v1
39+
- uses: docker/setup-buildx-action@v1
40+
- id: meta
41+
uses: docker/metadata-action@v3
42+
with:
43+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
44+
- name: build
45+
uses: docker/build-push-action@v2
46+
with:
47+
context: .
48+
push: false
49+
tags: ${{ steps.meta.outputs.tags }}
50+
labels: ${{ steps.meta.outputs.labels }}
51+
cache-from: type=gha
52+
cache-to: type=gha,mode=max

Diff for: .github/workflows/conventional-commits.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# The below is pulled from upstream and slightly modified
2+
# https://github.com/webiny/action-conventional-commits/blob/master/README.md#usage
3+
4+
name: Conventional Commits
5+
6+
on:
7+
pull_request:
8+
9+
jobs:
10+
build:
11+
name: Conventional Commits
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- uses: webiny/[email protected]

Diff for: .github/workflows/publish.yml

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: publish
2+
3+
on:
4+
push:
5+
branches: ['main']
6+
release:
7+
types: ['published']
8+
9+
concurrency: ${{ github.ref }}
10+
11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: cloudstruct/cardano-db-sync
14+
15+
jobs:
16+
build-amd64:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
packages: write
21+
steps:
22+
- uses: actions/checkout@v2
23+
- uses: docker/setup-buildx-action@v1
24+
- name: login
25+
uses: docker/login-action@v1
26+
with:
27+
registry: ${{ env.REGISTRY }}
28+
username: ${{ github.actor }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
30+
- id: meta
31+
uses: docker/metadata-action@v3
32+
with:
33+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
34+
flavor: |
35+
latest=false
36+
tags: |
37+
type=schedule,suffix=-amd64
38+
type=ref,event=branch,suffix=-amd64
39+
type=ref,event=tag,suffix=-amd64
40+
type=ref,event=pr,suffix=-amd64
41+
- name: push
42+
uses: docker/build-push-action@v2
43+
with:
44+
context: .
45+
push: true
46+
tags: ${{ steps.meta.outputs.tags }}
47+
labels: ${{ steps.meta.outputs.labels }}
48+
cache-from: type=gha
49+
cache-to: type=gha,mode=max
50+
build-arm64:
51+
runs-on: self-hosted
52+
permissions:
53+
contents: read
54+
packages: write
55+
steps:
56+
- uses: actions/checkout@v2
57+
- uses: docker/setup-buildx-action@v1
58+
- name: login
59+
uses: docker/login-action@v1
60+
with:
61+
registry: ${{ env.REGISTRY }}
62+
username: ${{ github.actor }}
63+
password: ${{ secrets.GITHUB_TOKEN }}
64+
- id: meta
65+
uses: docker/metadata-action@v3
66+
with:
67+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
68+
flavor: |
69+
latest=false
70+
tags: |
71+
type=schedule,suffix=-arm64v8
72+
type=ref,event=branch,suffix=-arm64v8
73+
type=ref,event=tag,suffix=-arm64v8
74+
type=ref,event=pr,suffix=-arm64v8
75+
- name: push
76+
uses: docker/build-push-action@v2
77+
with:
78+
context: .
79+
push: true
80+
tags: ${{ steps.meta.outputs.tags }}
81+
labels: ${{ steps.meta.outputs.labels }}
82+
cache-from: type=gha
83+
cache-to: type=gha,mode=max
84+
multi-arch-manifest:
85+
runs-on: ubuntu-latest
86+
needs: [build-amd64, build-arm64]
87+
permissions:
88+
contents: read
89+
packages: write
90+
steps:
91+
- uses: actions/checkout@v2
92+
- uses: docker/setup-buildx-action@v1
93+
- name: login
94+
uses: docker/login-action@v1
95+
with:
96+
registry: ${{ env.REGISTRY }}
97+
username: ${{ github.actor }}
98+
password: ${{ secrets.GITHUB_TOKEN }}
99+
- id: meta
100+
uses: docker/metadata-action@v3
101+
with:
102+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
103+
flavor: |
104+
latest=false
105+
tags: |
106+
type=ref,event=branch
107+
type=ref,event=tag
108+
- name: manifest
109+
run: docker manifest create ${{ steps.meta.outputs.tags }} --amend ${{ steps.meta.outputs.tags }}-amd64 --amend ${{ steps.meta.outputs.tags }}-arm64v8
110+
- name: push
111+
run: docker manifest push ${{ steps.meta.outputs.tags }}

Diff for: Dockerfile

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
FROM debian:stable-slim as builder
2+
ARG CABAL_VERSION=3.6.2.0
3+
ARG GHC_VERSION=8.10.7
4+
5+
WORKDIR /code
6+
7+
# system dependencies
8+
ENV DEBIAN_FRONTEND=noninteractive
9+
RUN apt-get update -y && \
10+
apt-get install -y \
11+
automake \
12+
build-essential \
13+
pkg-config \
14+
libffi-dev \
15+
libgmp-dev \
16+
libnuma-dev \
17+
libpq-dev \
18+
libssl-dev \
19+
libsystemd-dev \
20+
libtinfo-dev \
21+
llvm-dev \
22+
zlib1g-dev \
23+
make \
24+
g++ \
25+
tmux \
26+
git \
27+
jq \
28+
wget \
29+
libncursesw5 \
30+
libtool \
31+
autoconf
32+
33+
# cabal
34+
ENV CABAL_VERSION=${CABAL_VERSION}
35+
ENV PATH="/root/.cabal/bin:/root/.ghcup/bin:/root/.local/bin:$PATH"
36+
RUN wget https://downloads.haskell.org/~cabal/cabal-install-${CABAL_VERSION}/cabal-install-${CABAL_VERSION}-$(uname -m)-linux-deb10.tar.xz \
37+
&& tar -xf cabal-install-${CABAL_VERSION}-$(uname -m)-linux-deb10.tar.xz \
38+
&& rm cabal-install-${CABAL_VERSION}-$(uname -m)-linux-deb10.tar.xz \
39+
&& mkdir -p ~/.local/bin \
40+
&& mv cabal ~/.local/bin/ \
41+
&& cabal update && cabal --version
42+
43+
# GHC
44+
ENV GHC_VERSION=${GHC_VERSION}
45+
RUN wget https://downloads.haskell.org/~ghc/${GHC_VERSION}/ghc-${GHC_VERSION}-$(uname -m)-deb10-linux.tar.xz \
46+
&& tar -xf ghc-${GHC_VERSION}-$(uname -m)-deb10-linux.tar.xz \
47+
&& rm ghc-${GHC_VERSION}-$(uname -m)-deb10-linux.tar.xz \
48+
&& cd ghc-${GHC_VERSION} \
49+
&& ./configure \
50+
&& make install
51+
52+
# Libsodium
53+
RUN git clone https://github.com/input-output-hk/libsodium && \
54+
cd libsodium && \
55+
git checkout 66f017f1 && \
56+
./autogen.sh && \
57+
./configure && \
58+
make && \
59+
make install
60+
ENV LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
61+
ENV PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
62+
63+
# secp256k1
64+
RUN git clone https://github.com/bitcoin-core/secp256k1 && \
65+
cd secp256k1 && \
66+
git checkout ac83be33 && \
67+
./autogen.sh && \
68+
./configure --enable-module-schnorrsig --enable-experimental && \
69+
make && \
70+
make install
71+
72+
FROM builder as cardano-db-sync-build
73+
# Install cardano-db-sync
74+
ARG DBSYNC_VERSION=13.0.4
75+
ENV DBSYNC_VERSION=${DBSYNC_VERSION}
76+
RUN echo "Building tags/${DBSYNC_VERSION}..." \
77+
&& echo tags/${DBSYNC_VERSION} > /CARDANO_BRANCH \
78+
&& git clone https://github.com/input-output-hk/cardano-db-sync.git \
79+
&& cd cardano-db-sync\
80+
&& git fetch --all --recurse-submodules --tags \
81+
&& git tag \
82+
&& git checkout tags/${DBSYNC_VERSION} \
83+
&& cabal configure --with-compiler=ghc-$GHC_VERSION \
84+
&& cabal build cardano-db-sync \
85+
&& mkdir -p /root/.local/bin/ \
86+
&& 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/ \
87+
&& rm -rf /root/.cabal/packages \
88+
&& rm -rf /usr/local/lib/ghc-8.10.7/ /usr/local/share/doc/ghc-8.10.7/ \
89+
&& rm -rf /code/cardano-db-sync/dist-newstyle/ \
90+
&& rm -rf /root/.cabal/store/ghc-8.10.7
91+
92+
FROM debian:stable-slim as cardano-db-sync
93+
ENV LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
94+
ENV PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
95+
COPY --from=cardano-db-sync-build /usr/local/lib/ /usr/local/lib/
96+
COPY --from=cardano-db-sync-build /usr/local/include/ /usr/local/include/
97+
COPY --from=cardano-db-sync-build /root/.local/bin/cardano-* /code/cardano-db-sync/scripts/postgresql-setup.sh /usr/local/bin/
98+
COPY --from=cardano-db-sync-build /code/cardano-db-sync/schema/ /opt/cardano/schema/
99+
COPY bin/ /bin/
100+
COPY config/ /opt/cardano/config/
101+
RUN apt-get update -y && \
102+
apt-get install -y \
103+
libffi7 \
104+
libgmp10 \
105+
libncursesw5 \
106+
libnuma1 \
107+
libsystemd0 \
108+
libssl1.1 \
109+
libtinfo6 \
110+
llvm-11-runtime \
111+
pkg-config \
112+
postgresql-client \
113+
zlib1g && \
114+
chmod +x /usr/local/bin/* && \
115+
rm -rf /var/lib/apt/lists/*
116+
EXPOSE 8080
117+
ENTRYPOINT ["/bin/entry-point"]

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
# docker-cardano-db-sync
1+
# docker-cardano-db-sync
2+
Builds a cardano-db-sync on debian

Diff for: bin/entry-point

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
mkdir -p /configuration
5+
if [[ ! -f /configuration/pgpass ]]; then
6+
gen-pgpass /run/secrets
7+
fi
8+
export PGPASSFILE=/configuration/pgpass
9+
mkdir -p -m 1777 /tmp
10+
set -euo pipefail
11+
if [[ ! -z ${RESTORE_SNAPSHOT:-} ]]; then
12+
__base=$(basename ${RESTORE_SNAPSHOT})
13+
__mark=${__base}.restored
14+
if [[ ! -f ${RESTORED_MARKER} ]]; then
15+
if [[ ${RESTORE_SNAPSHOT} =~ ^https://.* ]]; then
16+
echo "Downloading snapshot ${RESTORE_SNAPSHOT} ..."
17+
curl -LOC - "${RESTORE_SNAPSHOT}"
18+
curl -LO "${RESTORE_SNAPSHOT}.sha256sum"
19+
sha256sum -c "${__base}.sha256sum"
20+
__snap=${__base}
21+
else
22+
__snap=${RESTORE_SNAPSHOT}
23+
fi
24+
rm -f /var/lib/cexplorer/*.lstate
25+
postgresql-setup.sh --restore-snapshot ${__snap} /var/lib/cexplorer
26+
touch ${RESTORED_MARKER}
27+
rm -f ${__snap}{,.sha256sum,.asc}
28+
fi
29+
fi
30+
31+
if [[ -z ${NETWORK} ]]; then
32+
echo "Connecting to network specified in configuration.yaml"
33+
exec cardano-db-sync \
34+
--schema-dir /opt/cardano/schema \
35+
--state-dir /var/lib/cexplorer ${@}
36+
else
37+
echo "Connecting to network: ${NETWORK}"
38+
export CARDANO_NODE_SOCKET_PATH=${CARDANO_NODE_SOCKET_PATH:-/node-ipc/node.socket}
39+
mkdir -p log-dir # do we need this?
40+
exec cardano-db-sync \
41+
--config /opt/cardano/config/${NETWORK}-db-sync-config.json \
42+
--schema-dir /opt/cardano/schema \
43+
--socket-path ${CARDANO_NODE_SOCKET_PATH} \
44+
--state-dir /var/lib/cexplorer
45+
46+
fi

Diff for: bin/gen-pgpass

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
__dir=${1}
4+
echo ${__dir}
5+
echo "Generating PGPASS file"
6+
POSTGRES_DB=${POSTGRES_DB:-$(< ${__dir}/postgres_db)}
7+
POSTGRES_USER=${POSTGRES_USER:-$(< ${__dir}/postgres_user)}
8+
POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-$(< ${__dir}/postgres_password)}
9+
echo "${POSTGRES_HOST}:${POSTGRES_PORT}:${POSTGRES_DB}:${POSTGRES_USER}:${POSTGRES_PASSWORD}" > /configuration/pgpass
10+
chmod 0600 /configuration/pgpass

0 commit comments

Comments
 (0)