Skip to content

Commit ad8bc88

Browse files
authored
Merge pull request #1 from cloudstruct/feat/build-node
feat: build cardano-node 1.34.1 from source
2 parents 9126ba7 + 20b82a5 commit ad8bc88

20 files changed

+16235
-1
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Dockerfile
2+
README.md
3+
.github/

.github/workflows/ci-docker.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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-node
11+
12+
jobs:
13+
docker:
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+
### TODO: test multiple platforms
30+
# platforms: linux/amd64,linux/arm64
31+
tags: ${{ steps.meta.outputs.tags }}
32+
labels: ${{ steps.meta.outputs.labels }}
33+
### TODO: cache artifacts
34+
#cache-to: type=gha,mode=max
Lines changed: 16 additions & 0 deletions
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]

.github/workflows/publish.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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-node
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+
- name: login
24+
uses: docker/login-action@v1
25+
with:
26+
registry: ${{ env.REGISTRY }}
27+
username: ${{ github.actor }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
- id: meta
30+
uses: docker/metadata-action@v3
31+
with:
32+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
33+
tags: |
34+
type=schedule,suffix=-amd64
35+
type=ref,event=branch,suffix=-amd64
36+
type=ref,event=tag,suffix=-amd64
37+
type=ref,event=pr,suffix=-amd64
38+
- name: push
39+
uses: docker/build-push-action@v2
40+
with:
41+
context: .
42+
push: true
43+
tags: ${{ steps.meta.outputs.tags }}
44+
labels: ${{ steps.meta.outputs.labels }}
45+
cache-from: type=gha
46+
cache-to: type=gha,mode=max
47+
build-arm64:
48+
runs-on: self-hosted
49+
permissions:
50+
contents: read
51+
packages: write
52+
steps:
53+
- uses: actions/checkout@v2
54+
- name: login
55+
uses: docker/login-action@v1
56+
with:
57+
registry: ${{ env.REGISTRY }}
58+
username: ${{ github.actor }}
59+
password: ${{ secrets.GITHUB_TOKEN }}
60+
- id: meta
61+
uses: docker/metadata-action@v3
62+
with:
63+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
64+
tags: |
65+
type=schedule,suffix=-arm64v8
66+
type=ref,event=branch,suffix=-arm64v8
67+
type=ref,event=tag,suffix=-arm64v8
68+
type=ref,event=pr,suffix=-arm64v8
69+
- name: push
70+
uses: docker/build-push-action@v2
71+
with:
72+
context: .
73+
push: true
74+
tags: ${{ steps.meta.outputs.tags }}
75+
labels: ${{ steps.meta.outputs.labels }}
76+
cache-from: type=gha
77+
cache-to: type=gha,mode=max
78+
multi-arch-manifest:
79+
runs-on: ubuntu-latest
80+
needs: [build-amd64, build-arm64]
81+
permissions:
82+
contents: read
83+
packages: write
84+
steps:
85+
- uses: actions/checkout@v2
86+
- name: login
87+
uses: docker/login-action@v1
88+
with:
89+
registry: ${{ env.REGISTRY }}
90+
username: ${{ github.actor }}
91+
password: ${{ secrets.GITHUB_TOKEN }}
92+
- id: meta
93+
uses: docker/metadata-action@v3
94+
with:
95+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
96+
tags: |
97+
type=ref,event=branch
98+
type=ref,event=tag
99+
- name: manifest
100+
run: docker manifest create ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.tags }} --amend ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.tags }}-amd64 --amend ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.tags }}-arm64v8
101+
- name: push
102+
run: docker manifest push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.tags }}

Dockerfile

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
FROM debian:stable-slim as builder
2+
ARG CABAL_VERSION=3.6.2.0
3+
ARG GHC_VERSION=8.10.7
4+
ARG NODE_VERSION=1.34.1
5+
6+
WORKDIR /code
7+
8+
# system dependencies
9+
ENV DEBIAN_FRONTEND=noninteractive
10+
RUN apt-get update -y && \
11+
apt-get install -y dpkg && \
12+
apt-get install -y \
13+
automake \
14+
build-essential \
15+
pkg-config \
16+
libffi-dev \
17+
libgmp-dev \
18+
libssl-dev \
19+
libtinfo-dev \
20+
libsystemd-dev \
21+
zlib1g-dev \
22+
make \
23+
g++ \
24+
tmux \
25+
git \
26+
jq \
27+
wget \
28+
libncursesw5 \
29+
libtool \
30+
autoconf
31+
32+
# cabal
33+
ENV CABAL_VERSION=${CABAL_VERSION}
34+
ENV PATH="/root/.cabal/bin:/root/.ghcup/bin:/root/.local/bin:$PATH"
35+
RUN wget https://downloads.haskell.org/~cabal/cabal-install-${CABAL_VERSION}/cabal-install-${CABAL_VERSION}-$(uname -m)-linux-deb10.tar.xz \
36+
&& tar -xf cabal-install-${CABAL_VERSION}-$(uname -m)-linux-deb10.tar.xz \
37+
&& rm cabal-install-${CABAL_VERSION}-$(uname -m)-linux-deb10.tar.xz \
38+
&& mkdir -p ~/.local/bin \
39+
&& mv cabal ~/.local/bin/ \
40+
&& cabal update && cabal --version
41+
42+
# GHC
43+
ENV GHC_VERSION=${GHC_VERSION}
44+
RUN wget https://downloads.haskell.org/~ghc/${GHC_VERSION}/ghc-${GHC_VERSION}-$(uname -m)-deb10-linux.tar.xz \
45+
&& tar -xf ghc-${GHC_VERSION}-$(uname -m)-deb10-linux.tar.xz \
46+
&& rm ghc-${GHC_VERSION}-$(uname -m)-deb10-linux.tar.xz \
47+
&& cd ghc-${GHC_VERSION} \
48+
&& ./configure \
49+
&& make install
50+
51+
# Libsodium
52+
RUN git clone https://github.com/input-output-hk/libsodium && \
53+
cd libsodium && \
54+
git checkout 66f017f1 && \
55+
./autogen.sh && \
56+
./configure && \
57+
make && \
58+
make install
59+
ENV LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
60+
ENV PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
61+
62+
# Install cardano-node
63+
ENV NODE_VERSION=${NODE_VERSION}
64+
RUN echo "Building tags/${NODE_VERSION}..." \
65+
&& echo tags/${NODE_VERSION} > /CARDANO_BRANCH \
66+
&& git clone https://github.com/input-output-hk/cardano-node.git \
67+
&& cd cardano-node \
68+
&& git fetch --all --recurse-submodules --tags \
69+
&& git tag \
70+
&& git checkout tags/${NODE_VERSION} \
71+
&& cabal configure --with-compiler=ghc-$GHC_VERSION \
72+
&& echo "package cardano-crypto-praos" >> cabal.project.local \
73+
&& echo " flags: -external-libsodium-vrf" >> cabal.project.local \
74+
&& cabal build all \
75+
&& mkdir -p /root/.local/bin/ \
76+
&& cp -p dist-newstyle/build/x86_64-linux/ghc-$GHC_VERSION/cardano-node-${NODE_VERSION}/x/cardano-node/build/cardano-node/cardano-node /root/.local/bin/ \
77+
&& cp -p dist-newstyle/build/x86_64-linux/ghc-$GHC_VERSION/cardano-cli-${NODE_VERSION}/x/cardano-cli/build/cardano-cli/cardano-cli /root/.local/bin/ \
78+
&& rm -rf /root/.cabal/packages \
79+
&& rm -rf /usr/local/lib/ghc-8.10.7/ /usr/local/share/doc/ghc-8.10.7/ \
80+
&& rm -rf /cardano-node/dist-newstyle/ \
81+
&& rm -rf /root/.cabal/store/ghc-8.10.7
82+
83+
FROM debian:stable-slim as cardano-node
84+
ENV LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
85+
COPY --from=builder /usr/local/lib/ /usr/local/lib/
86+
COPY --from=builder /usr/local/include/ /usr/local/include/
87+
COPY --from=builder /root/.local/bin/cardano-* /usr/local/bin/
88+
COPY bin/ /usr/local/bin/
89+
COPY config/ /opt/cardano/config/
90+
RUN apt-get update -y && \
91+
apt-get install -y \
92+
libgmp10 \
93+
libncursesw5 \
94+
zlib1g && \
95+
chmod +x /usr/local/bin/* && \
96+
rm -rf /var/lib/apt/lists/*
97+
EXPOSE 3001 12798
98+
ENTRYPOINT ["/usr/local/bin/entrypoint"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# docker-cardano-node
2-
Wrapper Dockerfile
2+
Builds a cardano-node on debian

bin/entrypoint

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
if [[ -n ${NETWORK} ]]; then
6+
exec /usr/local/bin/run-network ${@}
7+
fi
8+
case ${1} in
9+
run) exec /usr/local/bin/run-node ${@} ;;
10+
cli) exec /usr/local/bin/run-cli ${@} ;;
11+
*) echo "Nothing to do! Perhaps try [run|cli], or set NETWORK environment variable."; exit 1 ;;
12+
esac
13+
14+
# variables
15+
CARDANO_BLOCK_PRODUCER=${CARDANO_BLOCK_PRODUCER:-false}
16+
CARDANO_CONFIG=
17+
CARDANO_DATABASE_PATH=
18+
CARDANO_NETWORK=
19+
CARDANO_NODE_SOCKET_PATH=${CARDANO_NODE_SOCKET_PATH:-/opt/cardano/ipc/socket}
20+
CARDANO_PORT=${CARDANO_PORT:-3001}
21+
CARDANO_RTS_OPTS=
22+
CARDANO_SHELLEY_KES_KEY=
23+
CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE=
24+
CARDANO_SHELLEY_VRF_KEY=
25+
CARDANO_SOCKET_PATH=
26+
CARDANO_TOPOLOGY=
27+
28+
exec cardano-node \
29+
--config ${CARDANO_CONFIG} \
30+
--topology ${CARDANO_TOPOLOGY} \
31+
--database-path ${CARDANO_DATABASE_PATH} \
32+
--socket-path ${CARDANO_SOCKET_PATH} \
33+
--host-addr 0.0.0.0 \
34+
--port ${CARDANO_PORT}

bin/run-client

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
shift
4+
export CARDANO_NODE_SOCKET_PATH=${CARDANO_NODE_SOCKET_PATH:-/opt/cardano/ipc/socket}
5+
/usr/local/bin/cardano-cli ${@}

bin/run-network

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ -z ${NETWORK} ]]; then
4+
echo "[Error] Cannot obtain NETWORK env variable"
5+
exit 1
6+
fi
7+
8+
export PATH=${PATH}:/usr/local/bin
9+
mkdir -p ipc
10+
case ${NETWORK} in
11+
mainnet|testnet) : ;;
12+
*) echo "[Error] Managed configuration for network ${NETWORK} does not exist"; exit 1 ;;
13+
esac
14+
15+
echo "Starting: /usr/local/bin/cardano-node run"
16+
echo "--config /opt/cardano/config/${NETWORK}-config.json"
17+
echo "--database-path /data/db"
18+
echo "--host-addr 0.0.0.0"
19+
echo "--port 3001"
20+
echo "--socket-path /ipc/node.socket"
21+
echo "--topology /opt/cardano/config/${NETWORK}-topology.json"
22+
echo "+RTS"
23+
echo "-N2"
24+
echo "-I0"
25+
echo "-A16m"
26+
echo "-qg"
27+
echo "-qb"
28+
echo "--disable-delayed-os-memory-return"
29+
echo "-RTS"
30+
echo "..or, once again, in a single line:"
31+
echo "/usr/local/bin/cardano-node run --config /opt/cardano/config/${NETWORK}-config.json --database-path /data/db --host-addr 0.0.0.0 --port 3001 --socket-path /ipc/node.socket --topology /opt/cardano/config/${NETWORK}-topology.json +RTS -N2 -I0 -A16m -qg -qb --disable-delayed-os-memory-return -RTS"
32+
exec /usr/local/bin/cardano-node run --config /opt/cardano/config/${NETWORK}-config.json --database-path /data/db --host-addr 0.0.0.0 --port 3001 --socket-path /ipc/node.socket --topology /opt/cardano/config/${NETWORK}-topology.json +RTS -N2 -I0 -A16m -qg -qb --disable-delayed-os-memory-return -RTS ${@}

0 commit comments

Comments
 (0)