Skip to content

Commit

Permalink
Adjust Dockerfile to use cabal only, and pre-build Ogmios during the …
Browse files Browse the repository at this point in the history
…setup.
  • Loading branch information
KtorZ committed May 19, 2021
1 parent 606566d commit 5769470
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 87 deletions.
12 changes: 5 additions & 7 deletions server/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
*

!resolver.yaml
!stack.yaml
!.hpack.config.yaml
!.stylish-haskell.yaml
!LICENSE
!cabal.project
!*.cabal

!package.yaml
!app/
!src/
!test/
!static/
!ogmios.wsp.json
!scripts/

!modules/
Expand All @@ -20,4 +18,4 @@ modules/hjsonpointer
modules/hjsonschema
modules/wai-routes

!ogmios.wsp.json
!LICENSE
129 changes: 62 additions & 67 deletions server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

ARG GHC_VERSION=8.10.4
ARG CARDANO_NODE_VERSION=1.27.0
ARG CARDANO_OGMIOS_SNAPSHOT=f5eb524a06bf2439707161f6256af1164e360eb0
ARG CARDANO_CONFIG_URL=https://hydra.iohk.io/build/5821110/download/1
ARG IOHK_LIBSODIUM_GIT_REV=66f017f16633f2060db25e17c170c2afa0f2a8a1

# #
# ------------------------------- SETUP ------------------------------------- #
# #

FROM haskell:${GHC_VERSION} as build-foundation
FROM haskell:8.10.4 as setup
WORKDIR /build
RUN apt-get update && apt-get install --no-install-recommends -y \
automake=1:1.16.* \
Expand All @@ -29,11 +30,8 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
zlib1g-dev=1:1.2.*

RUN cabal update
RUN stack upgrade --binary-version 2.5.1
RUN stack setup
RUN stack update --snapshot-location-base \
https://github.com/KtorZ/cardano-ogmios/blob/ca0671b46bb90be1fed189e8c7d194617c26c280/server/resolver.yaml

# Build IOHK's libsodium fork, needed by cardano-node
WORKDIR /app/src
RUN git clone https://github.com/input-output-hk/libsodium.git &&\
cd libsodium &&\
Expand All @@ -44,45 +42,44 @@ RUN ./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"

# Build cardano-node.
WORKDIR /app/src
RUN git clone https://github.com/input-output-hk/cardano-node.git &&\
cd cardano-node &&\
git fetch --all --tags &&\
git checkout ${CARDANO_NODE_VERSION}
WORKDIR /app/src/cardano-node
RUN cabal install cardano-node \
--overwrite-policy=always \
--install-method=copy \
--installdir=/app/bin

# Pre-build latest release of ogmios, to speed up the actual image build later.
WORKDIR /app/src
RUN git clone https://github.com/KtorZ/cardano-ogmios.git &&\
cd cardano-ogmios &&\
git fetch --all --tags &&\
git checkout ${CARDANO_OGMIOS_SNAPSHOT}
WORKDIR /app/src/cardano-ogmios/server
RUN cabal install exe:ogmios \
--overwrite-policy=always \
--install-method=copy \
--installdir=/app/bin

# #
# ----------------------- BUILD (cardano-ogmios) ----------------------------- #
# #

FROM build-foundation as build-ogmios

WORKDIR /app/src/ogmios

COPY .hpack.config.yaml .hpack.config.yaml
COPY .stylish-haskell.yaml .stylish-haskell.yaml

COPY modules/cardano-client/package.yaml \
modules/cardano-client/package.yaml

COPY modules/fast-bech32/package.yaml \
modules/fast-bech32/package.yaml

COPY modules/git-th/package.yaml \
modules/git-th/package.yaml

COPY modules/hspec-json-schema/package.yaml \
modules/hspec-json-schema/package.yaml

COPY modules/json-wsp/package.yaml \
modules/json-wsp/package.yaml
FROM setup as build

COPY modules/json-via-show/package.yaml \
modules/json-via-show/package.yaml

COPY resolver.yaml resolver.yaml
COPY stack.yaml stack.yaml
COPY package.yaml package.yaml

RUN stack build --only-snapshot
WORKDIR /app/src/cardano-ogmios/server

COPY . .

RUN stack build --only-dependencies
RUN stack install ogmios --flag ogmios:production
RUN cabal install exe:ogmios \
--overwrite-policy=always \
--install-method=copy \
--installdir=/app/bin

# #
# --------------------------- RUN (ogmios-only) ------------------------------ #
Expand All @@ -93,8 +90,8 @@ FROM debian:buster-slim as ogmios
LABEL name=ogmios
LABEL description="A JSON-WSP WebSocket client for cardano-node"

COPY --from=build-ogmios /root/.local/bin/ogmios /bin/ogmios
COPY --from=build-ogmios /usr/local/lib/libsodium.so.23 /usr/lib/x86_64-linux-gnu/libsodium.so.23
COPY --from=build /usr/local/lib/libsodium.so.23 /usr/lib/x86_64-linux-gnu/libsodium.so.23
COPY --from=build /app/bin/ogmios /bin/ogmios

RUN mkdir -p /etc/bash_completion.d
RUN ogmios --bash-completion-script ogmios > /etc/bash_completion.d/ogmios
Expand All @@ -103,23 +100,6 @@ RUN echo "source /etc/bash_completion.d/ogmios" >> ~/.bashrc
EXPOSE 1337/tcp
ENTRYPOINT ["ogmios"]

# #
# ------------------------ BUILD (cardano-node) ------------------------------ #
# #

FROM build-foundation as build-cardano-node

WORKDIR /app/src
RUN git clone https://github.com/input-output-hk/cardano-node.git &&\
cd cardano-node &&\
git fetch --all --tags &&\
git checkout ${CARDANO_NODE_VERSION}
WORKDIR /app/src/cardano-node
RUN cabal install cardano-node \
--install-method=copy \
--installdir=/root/.local/bin \
-f -systemd

# #
# --------------------- RUN (cardano-node & ogmios) -------------------------- #
# #
Expand All @@ -129,21 +109,36 @@ FROM debian:buster-slim as cardano-node-ogmios
LABEL name=cardano-node-ogmios
LABEL description="A JSON-WSP WebSocket client for cardano-node w/ a cardano-node"

COPY --from=build-foundation /usr/local/lib/libsodium.so.23 /usr/lib/x86_64-linux-gnu/libsodium.so.23
COPY --from=build-ogmios /root/.local/bin/ogmios /bin/ogmios
COPY --from=build-cardano-node /root/.local/bin/cardano-node /bin/cardano-node
# Ogmios, cardano-node, ekg, prometheus
EXPOSE 1337/tcp 3000/tcp 12788/tcp 12798/tcp

RUN apt-get update && apt-get install -y \
wget=1.20.1-* \
netbase=5.6
RUN apt-get -y purge && apt-get -y clean && apt-get -y autoremove && rm -rf /var/lib/apt/lists/*

COPY --from=setup /usr/local/lib/libsodium.so.23 /usr/lib/x86_64-linux-gnu/libsodium.so.23
COPY --from=setup /app/bin/cardano-node /bin/cardano-node
COPY --from=build /app/bin/ogmios /bin/ogmios

WORKDIR /config

RUN wget https://hydra.iohk.io/build/6198010/download/1/mainnet-config.json
RUN wget https://hydra.iohk.io/build/6198010/download/1/mainnet-byron-genesis.json
RUN wget https://hydra.iohk.io/build/6198010/download/1/mainnet-shelley-genesis.json
RUN wget https://hydra.iohk.io/build/6198010/download/1/mainnet-topology.json
RUN wget ${CARDANO_CONFIG_URL}/mainnet-config.json
RUN wget ${CARDANO_CONFIG_URL}/mainnet-byron-genesis.json
RUN wget ${CARDANO_CONFIG_URL}/mainnet-shelley-genesis.json
RUN wget ${CARDANO_CONFIG_URL}/mainnet-topology.json

RUN wget ${CARDANO_CONFIG_URL}/testnet-config.json
RUN wget ${CARDANO_CONFIG_URL}/testnet-byron-genesis.json
RUN wget ${CARDANO_CONFIG_URL}/testnet-shelley-genesis.json
RUN wget ${CARDANO_CONFIG_URL}/testnet-topology.json

RUN wget ${CARDANO_CONFIG_URL}/staging-config.json
RUN wget ${CARDANO_CONFIG_URL}/staging-byron-genesis.json
RUN wget ${CARDANO_CONFIG_URL}/staging-shelley-genesis.json
RUN wget ${CARDANO_CONFIG_URL}/staging-topology.json

RUN wget https://hydra.iohk.io/build/6198010/download/1/testnet-config.json
RUN wget https://hydra.iohk.io/build/6198010/download/1/testnet-byron-genesis.json
RUN wget https://hydra.iohk.io/build/6198010/download/1/testnet-shelley-genesis.json
RUN wget https://hydra.iohk.io/build/6198010/download/1/testnet-topology.json
RUN find . -name "*config*.json" -print0 | xargs -0 sed -i 's/127.0.0.1/0.0.0.0/g' > /dev/null 2>&1

WORKDIR /root
COPY scripts/entrypoint.sh entrypoint.sh
Expand Down
9 changes: 0 additions & 9 deletions server/cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ package ogmios
package cryptonite
flags: -support_rdrand

-- Bundle VRF crypto in libsodium and do not rely on an external fork to have it. This
-- is okay because ogmios doesn't really do anything with VRF crypto, it's merely needed
-- for compiler unused part of the node's api.
--
-- This still requires the host system to have the 'standard' libsodium installed.
package cardano-crypto-praos
flags: +external-libsodium-vrf


-- The "cabal" wrapper script provided by nix-shell will cut off / restore the remainder of this file
-- in order to force usage of nix provided dependencies for `source-repository-package`.
-- --------------------------- 8< --------------------------
Expand Down
13 changes: 9 additions & 4 deletions server/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
#!/bin/bash

set -m

if [ -z "$NETWORK" ]; then
echo "'NETWORK' environment variable must be set."
exit 1
fi

cardano-node run\
--topology config/$NETWORK-topology.json\
--topology /config/$NETWORK-topology.json\
--database-path db/$NETWORK\
--port 3000\
--config config/$NETWORK-config.json\
--socket-path ./node.socket &
--host-addr 0.0.0.0\
--config /config/$NETWORK-config.json\
--socket-path ./node.socket&
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start cardano-node: $status"
exit $status
fi

OGMIOS_NETWORK=$NETWORK ogmios --node-socket ./node.socket &
OGMIOS_NETWORK=$NETWORK ogmios \
--host 0.0.0.0\
--node-socket ./node.socket &
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start ogmios: $status"
Expand Down

0 comments on commit 5769470

Please sign in to comment.