Skip to content

Commit 2ce9fe5

Browse files
committed
fix: make older cardano-node versions work
1 parent 4815388 commit 2ce9fe5

File tree

3 files changed

+57
-53
lines changed

3 files changed

+57
-53
lines changed

Dockerfile

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ARG UBUNTU_VERSION=22.04
22
ARG TARGETARCH=amd64
3-
ARG CARDANO_NODE_VERSION=1.35.5
3+
ARG CARDANO_NODE_VERSION=1.35.7
44
ARG CARDANO_DB_SYNC_VERSION=13.1.0.0
55
ARG NODEJS_MAJOR_VERSION=14
66

@@ -19,53 +19,53 @@ RUN curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/
1919
--extra-conf "trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" \
2020
--init none --no-confirm
2121
ENV PATH="${PATH}:/nix/var/nix/profiles/default/bin"
22-
RUN mkdir -p /app
23-
WORKDIR /app
24-
# Note: since we don’t officially support `aarch64-linux`, we have to tweak the source a bit
25-
# in this case; but otherwise, build straight from GitHub:
26-
RUN \
27-
if [ "$TARGETARCH" = "arm64" ]; then \
28-
mkdir -p src && cd src &&\
29-
git clone https://github.com/input-output-hk/cardano-node.git &&\
30-
cd cardano-node &&\
31-
git fetch --all --tags &&\
32-
git checkout ${CARDANO_NODE_VERSION} &&\
33-
echo '["aarch64-linux"]' >nix/supported-systems.nix &&\
34-
cd ../.. &&\
35-
nix build -L -o cardano-node ./src/cardano-node#legacyPackages.aarch64-linux.hydraJobs.musl.cardano-node ;\
36-
else \
37-
nix build -L -o cardano-node github:input-output-hk/cardano-node/${CARDANO_NODE_VERSION}#legacyPackages.x86_64-linux.hydraJobs.musl.cardano-node ;\
38-
fi
39-
RUN \
40-
if [ "$TARGETARCH" = "arm64" ]; then \
41-
nix build -L -o cardano-cli ./src/cardano-node#legacyPackages.aarch64-linux.hydraJobs.musl.cardano-cli ;\
42-
else \
43-
nix build -L -o cardano-cli github:input-output-hk/cardano-node/${CARDANO_NODE_VERSION}#legacyPackages.x86_64-linux.hydraJobs.musl.cardano-cli ;\
44-
fi
45-
RUN \
46-
mkdir -p src && cd src &&\
47-
git clone https://github.com/input-output-hk/cardano-db-sync.git &&\
48-
cd cardano-db-sync &&\
49-
git fetch --all --tags &&\
50-
git checkout ${CARDANO_DB_SYNC_VERSION} &&\
51-
cd ../.. &&\
52-
if [ "$TARGETARCH" = "arm64" ]; then \
53-
echo '["aarch64-linux"]' >src/cardano-db-sync/supported-systems.nix &&\
54-
nix build -L -o cardano-db-sync--tar ./src/cardano-db-sync#hydraJobs.cardano-db-sync-linux.aarch64-linux ;\
55-
else \
56-
nix build -L -o cardano-db-sync--tar ./src/cardano-db-sync#hydraJobs.cardano-db-sync-linux.x86_64-linux ;\
57-
fi &&\
58-
mkdir cardano-db-sync && cd cardano-db-sync &&\
59-
tar -xf ../cardano-db-sync--tar/cardano-db-sync*.tar.gz && chown -R 0:0 . && chmod -R -w . && cd ..
22+
# We don’t officially support AArch64, so we have to go through some hops:
23+
SHELL ["/bin/bash", "-c"]
24+
RUN mkdir -p /app && cat >/app/default.nix <<<$'\n\
25+
let\n\
26+
system = "'"$([ "$TARGETPLATFORM" = "linux/arm64" ] && echo "aarch64-linux" || echo "x86_64-linux")"$'";\n\
27+
_nodeFlake = __getFlake "github:input-output-hk/cardano-node/'"${CARDANO_NODE_VERSION}"$'";\n\
28+
_dbSyncFlake = __getFlake "github:input-output-hk/cardano-db-sync/'"${CARDANO_DB_SYNC_VERSION}"$'";\n\
29+
pkgs = _nodeFlake.inputs.nixpkgs.legacyPackages.${system};\n\
30+
nix-bundle-exe = import (fetchTarball "https://github.com/3noch/nix-bundle-exe/archive/3522ae68aa4188f4366ed96b41a5881d6a88af97.zip") { inherit pkgs; };\n\
31+
enableAArch64 = original: supportedSystemsPath:\n\
32+
if system == "x86_64-linux" then original\n\
33+
else if system == "aarch64-linux" then let\n\
34+
patched = pkgs.runCommandNoCC "patched" {} "cp -r ${original} $out && chmod -R +w $out && echo ${with pkgs; with lib; escapeShellArg (__toJSON [system])} >$out/${supportedSystemsPath}";\n\
35+
in (import _nodeFlake.inputs.flake-compat {\n\
36+
src = {\n\
37+
inherit (patched) outPath;\n\
38+
inherit (original) rev shortRev lastModified lastModifiedDate;\n\
39+
};\n\
40+
}).defaultNix else throw "unsupported system: ${system}";\n\
41+
nodeFlake = enableAArch64 _nodeFlake "nix/supported-systems.nix";\n\
42+
dbSyncFlake = enableAArch64 _dbSyncFlake "supported-systems.nix";\n\
43+
in\n\
44+
# cardano-node doesn’t build for ARM before 1.35.7:\n\
45+
assert system != "aarch64-linux" || _nodeFlake.sourceInfo.lastModifiedDate >= "20230328184650";\n\
46+
{\n\
47+
inherit _nodeFlake;\n\
48+
cardano-node = nix-bundle-exe nodeFlake.packages.${system}.cardano-node;\n\
49+
cardano-cli = nix-bundle-exe nodeFlake.packages.${system}.cardano-cli;\n\
50+
cardano-db-sync = nix-bundle-exe dbSyncFlake.packages.${system}.cardano-db-sync;\n\
51+
schema = pkgs.runCommandNoCC "schema" {} "cp -r ${_dbSyncFlake}/schema $out";\n\
52+
}\n\
53+
' && cat /app/default.nix
54+
SHELL ["/bin/sh", "-c"]
55+
# Note: ‘GC_DONT_GC=1’ prevents rare segfaults in Nix’s Boehm GC:
56+
RUN GC_DONT_GC=1 nix-build /app/default.nix -A cardano-node -o /app/cardano-node
57+
RUN GC_DONT_GC=1 nix-build /app/default.nix -A cardano-cli -o /app/cardano-cli
58+
RUN GC_DONT_GC=1 nix-build /app/default.nix -A cardano-db-sync -o /app/cardano-db-sync
59+
RUN GC_DONT_GC=1 nix-build /app/default.nix -A schema -o /app/schema
60+
RUN mkdir -p /opt && cp -rL /app/cardano-node /app/cardano-cli /app/cardano-db-sync /app/schema /opt/
6061

61-
# Note: one more stage to detect Haskell errors earlier:
62+
# One more stage to detect Haskell errors early:
6263
FROM ${TARGETARCH}/ubuntu:${UBUNTU_VERSION} as haskell-runtime
63-
COPY --from=haskell-builder /app/cardano-node/bin/cardano-node /usr/local/bin/
64-
COPY --from=haskell-builder /app/cardano-cli/bin/cardano-cli /usr/local/bin/
65-
COPY --from=haskell-builder /app/cardano-db-sync/cardano-db-sync /usr/local/bin/
66-
COPY --from=haskell-builder /app/src/cardano-db-sync/schema /cardano-db-sync/schema
67-
RUN cardano-node --version && cardano-cli --version && cardano-db-sync --version
68-
RUN ls -alh /cardano-db-sync/schema
64+
COPY --from=haskell-builder /opt/ /opt/
65+
RUN stat /opt/schema &&\
66+
/opt/cardano-node/bin/cardano-node --version &&\
67+
/opt/cardano-cli/bin/cardano-cli --version &&\
68+
/opt/cardano-db-sync/bin/cardano-db-sync --version
6969

7070
FROM ${TARGETARCH}/ubuntu:${UBUNTU_VERSION} as ubuntu-nodejs
7171
ARG NODEJS_MAJOR_VERSION
@@ -93,8 +93,10 @@ RUN curl --proto '=https' --tlsv1.2 -sSf -L https://www.postgresql.org/media/key
9393
postgresql-12 \
9494
postgresql-client-12 &&\
9595
npm install pm2 -g
96-
COPY --from=haskell-runtime /usr/local/bin/* /usr/local/bin/
97-
COPY --from=haskell-runtime /cardano-db-sync/schema /cardano-db-sync/schema
96+
COPY --from=haskell-builder /opt/ /opt/
97+
RUN ln -s /opt/cardano-node/bin/* /opt/cardano-cli/bin/* /opt/cardano-db-sync/bin/* /usr/local/bin/ &&\
98+
mkdir -p /cardano-db-sync &&\
99+
ln -s /opt/schema /cardano-db-sync/schema
98100
# Configure dynamic linker
99101
RUN ldconfig
100102
# easy step-down from root
@@ -144,9 +146,8 @@ RUN yarn --offline --frozen-lockfile --non-interactive --production
144146

145147
FROM ubuntu-nodejs as cardano-rosetta-server
146148
ARG NETWORK=mainnet
147-
COPY --from=haskell-runtime /usr/local/bin/cardano-cli \
148-
/usr/local/bin/cardano-node \
149-
/usr/local/bin/
149+
COPY --from=haskell-builder /opt/ /opt/
150+
RUN ln -s /opt/cardano-node/bin/* /opt/cardano-cli/bin/* /usr/local/bin/
150151
COPY --from=rosetta-server-builder /app/dist /cardano-rosetta-server/dist
151152
COPY --from=rosetta-server-production-deps /app/node_modules /cardano-rosetta-server/node_modules
152153
COPY config/network/${NETWORK} /config/

ecosystem.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ module.exports = {
1717
},
1818
{
1919
name: 'cardano-node',
20-
script: '/usr/local/bin/cardano-node',
20+
script: '/bin/sh',
2121
args: [
22+
'/usr/local/bin/cardano-node',
2223
'run',
2324
'--config', '/config/cardano-node/config.json',
2425
'--database-path', '/data/node-db',
@@ -71,4 +72,4 @@ module.exports = {
7172
out_file: 'NULL'
7273
}
7374
]
74-
}
75+
}

scripts/entrypoint.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ elif [ "$MODE" == "online" ]; then
3131

3232
chown postgres:postgres -R \
3333
/config \
34+
/etc/postgresql \
3435
$DATA_DIR_DB_SYNC \
3536
$DATA_DIR_POSTGRES \
3637
$DATA_DIR_NODE \
@@ -74,6 +75,7 @@ elif [ "$MODE" == "online" ]; then
7475

7576
/etc/init.d/postgresql stop 1> /dev/null
7677
echo 'Starting';
78+
chmod 644 /ecosystem.config.js
7779
exec gosu postgres pm2-runtime start ecosystem.config.js --env production
7880

7981
else

0 commit comments

Comments
 (0)