Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
imp: add by-network /opt/cardano/config subdir in oci
  • Loading branch information
johnalotoski committed Feb 10, 2025
commit f3d65d7373a54318d6c05aa3fdde55a2d8439bbc
4 changes: 2 additions & 2 deletions nix/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ docker run --rm -it --entrypoint=bash \
ghcr.io/intersectmbo/cardano-node:dev

cardano-node run \
--config /opt/cardano/config/mainnet-config.json \
--topology /opt/cardano/config/mainnet-topology.json \
--config /opt/cardano/config/mainnet/config.json \
--topology /opt/cardano/config/mainnet/topology.json \
--socket-path /opt/cardano/ipc/socket \
--database-path /opt/cardano/data \
--host-addr 0.0.0.0 \
Expand Down
6 changes: 3 additions & 3 deletions nix/docker/context/bin/entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

if [[ -n $NETWORK ]]; then

exec /usr/local/bin/run-network $@
exec /usr/local/bin/run-network "$@"

elif [[ $1 == "run" ]]; then

exec /usr/local/bin/run-node $@
exec /usr/local/bin/run-node "$@"

elif [[ $1 == "cli" ]]; then

exec /usr/local/bin/run-client $@
exec /usr/local/bin/run-client "$@"

else

Expand Down
6 changes: 3 additions & 3 deletions nix/docker/context/bin/run-node
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ echo "Running the cardano node ..."
CARDANO_CONFIG_BASE="/opt/cardano/config"

if [[ -z $CARDANO_CONFIG ]]; then
CARDANO_CONFIG="$CARDANO_CONFIG_BASE/mainnet-config.json"
CARDANO_CONFIG="$CARDANO_CONFIG_BASE/mainnet/config.json"
fi

if [[ -z $CARDANO_TOPOLOGY ]]; then
CARDANO_TOPOLOGY="$CARDANO_CONFIG_BASE/mainnet-topology.json"
CARDANO_TOPOLOGY="$CARDANO_CONFIG_BASE/mainnet/topology.json"
fi

if [[ -z $CARDANO_DATABASE_PATH ]]; then
Expand Down Expand Up @@ -102,7 +102,7 @@ CARDANO_BLOCK_PRODUCER=$CARDANO_BLOCK_PRODUCER
CNODE_HOSTNAME="$CARDANO_PUBLIC_IP"
CNODE_PORT=$CARDANO_PORT
CUSTOM_PEERS="$CARDANO_CUSTOM_PEERS"
GENESIS_JSON="$CARDANO_CONFIG_BASE/mainnet-shelley-genesis.json"
GENESIS_JSON="$CARDANO_CONFIG_BASE/mainnet/shelley-genesis.json"
TOPOLOGY="$CARDANO_TOPOLOGY"
LOG_DIR="$CARDANO_LOG_DIR"
EOF
Expand Down
71 changes: 56 additions & 15 deletions nix/docker/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -105,34 +105,75 @@ let
# The Docker context with static content
context = ./context;

# Mainnet configuration used by the 'run' option
mainnetConfigFile = builtins.toFile "mainnet-config.json"
(builtins.toJSON commonLib.environments.mainnet.nodeConfig);
mainnetTopologyFile = commonLib.mkTopology commonLib.environments.mainnet;
genCfgs = let
environments = lib.getAttrs [ "mainnet" "preprod" "preview" "sanchonet" ] commonLib.environments;
cardano-deployment = commonLib.mkConfigHtml environments;
in
pkgs.runCommand "cardano-html" {} ''
mkdir "$out"
cp "${cardano-deployment}/index.html" "$out/"
cp "${cardano-deployment}/rest-config.json" "$out/"

ENVS=(${lib.escapeShellArgs (builtins.attrNames environments)})
for ENV in "''${ENVS[@]}"; do
# Migrate each env from a flat dir to an ENV subdir
mkdir -p "$out/config/$ENV"
for i in $(find ${cardano-deployment} -type f -name "$ENV-*" -printf "%f\n"); do
cp -v "${cardano-deployment}/$i" "$out/config/$ENV/''${i#"$ENV-"}"
done

# Adjust genesis file, config and config-bp refs
for i in config config-bp db-sync-config; do
if [ -f "$out/config/$ENV/$i.json" ]; then
sed -i "s|\"$ENV-|\"|g" "$out/config/$ENV/$i.json"
fi
done

# Adjust index.html file refs
sed -i "s|$ENV-|config/$ENV/|g" "$out/index.html"
done
'';

in
dockerTools.buildImage {
name = "${repoName}";
tag = "${gitrev}";
fromImage = baseImage;
created = "now"; # Set creation date to build time. Breaks reproducibility

# May require system-features = kvm in /etc/nix/nix.conf
# https://discourse.nixos.org/t/cannot-build-docker-image/7445
# runAsRoot = '' ln -s ${cardano-node} bin/cardano-node '';
# Set creation date to build time. Breaks reproducibility
created = "now";

extraCommands = ''
mkdir -p opt/cardano/config
# These directories serve as defaults when the node docker container uses the `run` arg.
# Alternatively, when the NETWORK environment variable is set the defaults are different.
# TODO: Reduce the confusion on this.
mkdir -p opt/cardano/data
mkdir -p opt/cardano/ipc
mkdir -p opt/cardano/logs
mkdir -p usr/local/bin
ln -s ${mainnetConfigFile} opt/cardano/config/mainnet-config.json
ln -s ${mainnetTopologyFile} opt/cardano/config/mainnet-topology.json
cp ${runNetwork}/bin/* usr/local/bin
cp ${context}/bin/* usr/local/bin
ln -s ${cardano-node}/bin/cardano-node usr/local/bin/cardano-node
ln -s ${cardano-cli}/bin/cardano-cli usr/local/bin/cardano-cli

cp -v ${runNetwork}/bin/* usr/local/bin
cp -v ${context}/bin/* usr/local/bin

ln -sv ${cardano-node}/bin/cardano-node usr/local/bin/cardano-node
ln -sv ${cardano-cli}/bin/cardano-cli usr/local/bin/cardano-cli

# Create iohk-nix network configs, organized by network directory.
SRC="${genCfgs}"
DST="opt/cardano"

# Make the directory structure with the iohk-nix configs mutable.
# This leaves the option to create merged entrypoint configs in the network directory.
find "$SRC" -mindepth 1 -type d -exec bash -c "DIR=\"{}\"; mkdir -v -p \"$DST/\''${DIR#${genCfgs}/}\"" \;

# Keep all base iohk-nix config files immutable via symlinks to nix store.
find "$SRC" -mindepth 1 -type f -exec bash -c "FILE=\"{}\"; TGT=\"$DST/\''${FILE#${genCfgs}/}\"; ln -sv \"\$FILE\" \"\$TGT\"" \;

# Preserve legacy oci config and topo path for backwards compatibility.
pushd opt/cardano/config
ln -sv mainnet/config.json mainnet-config.json
ln -sv mainnet/topology.json mainnet-topology.json
popd
'';

config = {
Expand Down