Skip to content

Commit 4815388

Browse files
committed
chore: build the Haskell parts with haskell.nix
1 parent d12e00e commit 4815388

File tree

1 file changed

+64
-112
lines changed

1 file changed

+64
-112
lines changed

Dockerfile

Lines changed: 64 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,76 @@
11
ARG UBUNTU_VERSION=22.04
2-
FROM ubuntu:${UBUNTU_VERSION} as haskell-builder
3-
ENV DEBIAN_FRONTEND=nonintercative
4-
RUN mkdir -p /app/src
5-
WORKDIR /app
6-
RUN apt-get update -y && apt-get install -y \
7-
autoconf=2.71* \
8-
automake=1:1.16.* \
9-
build-essential=12.* \
10-
g++=4:11.2.* \
11-
git=1:2.34.* \
12-
jq=1.6* \
13-
libffi-dev=3.* \
14-
libghc-postgresql-libpq-dev=0.9.4.* \
15-
libgmp-dev=2:6.2.* \
16-
libncursesw5=6.* \
17-
libpq-dev=14.* \
18-
libssl-dev=3.0.* \
19-
libsystemd-dev=249.* \
20-
libtinfo-dev=6.* \
21-
libtool=2.4.* \
22-
make=4.3* \
23-
pkg-config=0.29.* \
24-
tmux=3.* \
25-
wget=1.21.* \
26-
zlib1g-dev=1:1.2.*
2+
ARG TARGETARCH=amd64
3+
ARG CARDANO_NODE_VERSION=1.35.5
4+
ARG CARDANO_DB_SYNC_VERSION=13.1.0.0
5+
ARG NODEJS_MAJOR_VERSION=14
6+
7+
FROM ${TARGETARCH}/ubuntu:${UBUNTU_VERSION} as haskell-builder
278
ARG TARGETARCH
9+
ARG CARDANO_NODE_VERSION
10+
ARG CARDANO_DB_SYNC_VERSION
11+
ENV DEBIAN_FRONTEND=noninteractive
12+
RUN apt update -y
13+
RUN apt install curl git -y
14+
# Note: `sandbox = false` is for compatibility with Podman, Docker doesn’t require it.
15+
# Note: you can comment out `substituters` to build the world from source (including multiple GHC stages).
16+
RUN curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix/tag/v0.11.0 | sh -s -- install linux \
17+
--extra-conf "sandbox = false" \
18+
--extra-conf "substituters = https://cache.nixos.org https://cache.iog.io" \
19+
--extra-conf "trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" \
20+
--init none --no-confirm
21+
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:
2826
RUN \
2927
if [ "$TARGETARCH" = "arm64" ]; then \
30-
apt-get install -y libnuma-dev=2.0.* llvm-14; \
31-
fi
32-
ARG CABAL_VERSION=3.6.2.0
33-
RUN \
34-
if [ "$TARGETARCH" = "arm64" ]; then \
35-
TARGETARCH1=aarch64; \
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 ;\
3636
else \
37-
TARGETARCH1=x86_64; \
38-
fi; \
39-
wget --secure-protocol=TLSv1_2 \
40-
https://downloads.haskell.org/~cabal/cabal-install-${CABAL_VERSION}/cabal-install-${CABAL_VERSION}-${TARGETARCH1}-linux-deb10.tar.xz &&\
41-
tar -xf cabal-install-${CABAL_VERSION}-${TARGETARCH1}-linux-deb10.tar.xz &&\
42-
rm cabal-install-${CABAL_VERSION}-${TARGETARCH1}-linux-deb10.tar.xz &&\
43-
mv cabal /usr/local/bin/
44-
RUN cabal update
45-
WORKDIR /app/ghc
46-
ARG GHC_VERSION=8.10.7
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
4739
RUN \
4840
if [ "$TARGETARCH" = "arm64" ]; then \
49-
TARGETARCH1=aarch64; \
41+
nix build -L -o cardano-cli ./src/cardano-node#legacyPackages.aarch64-linux.hydraJobs.musl.cardano-cli ;\
5042
else \
51-
TARGETARCH1=x86_64; \
52-
fi; \
53-
wget --secure-protocol=TLSv1_2 \
54-
https://downloads.haskell.org/~ghc/${GHC_VERSION}/ghc-${GHC_VERSION}-${TARGETARCH1}-deb10-linux.tar.xz &&\
55-
tar -xf ghc-${GHC_VERSION}-${TARGETARCH1}-deb10-linux.tar.xz &&\
56-
rm ghc-${GHC_VERSION}-${TARGETARCH1}-deb10-linux.tar.xz
57-
WORKDIR /app/ghc/ghc-${GHC_VERSION}
58-
RUN ./configure && make install
59-
WORKDIR /app/src
60-
ARG IOHK_LIBSODIUM_GIT_REV=11bb20dba02b013bf1d83e3c16c51eab2ff07efc
61-
RUN git clone https://github.com/input-output-hk/libsodium.git &&\
62-
cd libsodium &&\
63-
git fetch --all --tags &&\
64-
git checkout ${IOHK_LIBSODIUM_GIT_REV}
65-
WORKDIR /app/src/libsodium
66-
RUN ./autogen.sh && ./configure && make && make install
67-
ENV LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
68-
ENV PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
69-
WORKDIR /app/src
70-
RUN git clone https://github.com/bitcoin-core/secp256k1 &&\
71-
cd secp256k1 &&\
72-
git checkout ac83be33
73-
WORKDIR /app/src/secp256k1
74-
RUN ./autogen.sh && ./configure --enable-module-schnorrsig --enable-experimental &&\
75-
make && make install
76-
WORKDIR /app/src
77-
ARG CARDANO_NODE_VERSION=1.35.5
78-
RUN git clone https://github.com/input-output-hk/cardano-node.git &&\
79-
cd cardano-node &&\
80-
git fetch --all --tags &&\
81-
git checkout ${CARDANO_NODE_VERSION}
82-
WORKDIR /app/src/cardano-node
83-
RUN cabal update
84-
RUN \
85-
cabal build exe:cardano-node \
86-
-f -systemd &&\
87-
if [ "$TARGETARCH" = "arm64" ]; then \
88-
TARGETARCH1=aarch64; \
89-
else \
90-
TARGETARCH1=x86_64; \
91-
fi; \
92-
mv ./dist-newstyle/build/${TARGETARCH1}-linux/ghc-${GHC_VERSION}/cardano-node-${CARDANO_NODE_VERSION}/x/cardano-node/build/cardano-node/cardano-node /usr/local/bin/
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
9345
RUN \
94-
cabal build exe:cardano-cli \
95-
-f -systemd &&\
96-
if [ "$TARGETARCH" = "arm64" ]; then \
97-
TARGETARCH1=aarch64; \
98-
else \
99-
TARGETARCH1=x86_64; \
100-
fi; \
101-
mv ./dist-newstyle/build/${TARGETARCH1}-linux/ghc-${GHC_VERSION}/cardano-cli-${CARDANO_NODE_VERSION}/x/cardano-cli/build/cardano-cli/cardano-cli /usr/local/bin/
102-
WORKDIR /app/src
103-
ARG CARDANO_DB_SYNC_VERSION=13.1.0.0
104-
RUN git clone https://github.com/input-output-hk/cardano-db-sync.git &&\
46+
mkdir -p src && cd src &&\
47+
git clone https://github.com/input-output-hk/cardano-db-sync.git &&\
10548
cd cardano-db-sync &&\
10649
git fetch --all --tags &&\
107-
git checkout ${CARDANO_DB_SYNC_VERSION}
108-
WORKDIR /app/src/cardano-db-sync
109-
RUN cabal install cardano-db-sync \
110-
--install-method=copy \
111-
--installdir=/usr/local/bin
112-
# Cleanup for runtiume-base copy of /usr/local/lib
113-
RUN rm -rf /usr/local/lib/ghc-${GHC_VERSION} /usr/local/lib/pkgconfig
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 ..
11460

115-
FROM ubuntu:${UBUNTU_VERSION} as ubuntu-nodejs
116-
ARG NODEJS_MAJOR_VERSION=14
117-
ENV DEBIAN_FRONTEND=nonintercative
118-
RUN apt-get update && apt-get install curl -y &&\
61+
# Note: one more stage to detect Haskell errors earlier:
62+
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
69+
70+
FROM ${TARGETARCH}/ubuntu:${UBUNTU_VERSION} as ubuntu-nodejs
71+
ARG NODEJS_MAJOR_VERSION
72+
ENV DEBIAN_FRONTEND=noninteractive
73+
RUN apt-get update && apt-get install curl gnupg2 lsb-core -y &&\
11974
curl --proto '=https' --tlsv1.2 -sSf -L https://deb.nodesource.com/setup_${NODEJS_MAJOR_VERSION}.x | bash - &&\
12075
apt-get install nodejs -y
12176

@@ -138,11 +93,8 @@ RUN curl --proto '=https' --tlsv1.2 -sSf -L https://www.postgresql.org/media/key
13893
postgresql-12 \
13994
postgresql-client-12 &&\
14095
npm install pm2 -g
141-
COPY --from=haskell-builder /usr/local/lib /usr/local/lib
142-
COPY --from=haskell-builder /usr/local/bin/cardano-node /usr/local/bin/
143-
COPY --from=haskell-builder /usr/local/bin/cardano-cli /usr/local/bin/
144-
COPY --from=haskell-builder /usr/local/bin/cardano-db-sync /usr/local/bin/
145-
COPY --from=haskell-builder /app/src/cardano-db-sync/schema /cardano-db-sync/schema
96+
COPY --from=haskell-runtime /usr/local/bin/* /usr/local/bin/
97+
COPY --from=haskell-runtime /cardano-db-sync/schema /cardano-db-sync/schema
14698
# Configure dynamic linker
14799
RUN ldconfig
148100
# easy step-down from root
@@ -192,7 +144,7 @@ RUN yarn --offline --frozen-lockfile --non-interactive --production
192144

193145
FROM ubuntu-nodejs as cardano-rosetta-server
194146
ARG NETWORK=mainnet
195-
COPY --from=haskell-builder /usr/local/bin/cardano-cli \
147+
COPY --from=haskell-runtime /usr/local/bin/cardano-cli \
196148
/usr/local/bin/cardano-node \
197149
/usr/local/bin/
198150
COPY --from=rosetta-server-builder /app/dist /cardano-rosetta-server/dist

0 commit comments

Comments
 (0)