diff --git a/nix/docker/README.md b/nix/docker/README.md index 047f813fee9..87977cd74b1 100644 --- a/nix/docker/README.md +++ b/nix/docker/README.md @@ -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 \ diff --git a/nix/docker/context/bin/entrypoint b/nix/docker/context/bin/entrypoint index 0baefe476e3..4d08684a2a5 100755 --- a/nix/docker/context/bin/entrypoint +++ b/nix/docker/context/bin/entrypoint @@ -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 diff --git a/nix/docker/context/bin/run-node b/nix/docker/context/bin/run-node index a0c1c49e61c..85f704a0653 100755 --- a/nix/docker/context/bin/run-node +++ b/nix/docker/context/bin/run-node @@ -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 @@ -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 diff --git a/nix/docker/default.nix b/nix/docker/default.nix index 3bc5f39c331..2f9452eccd8 100644 --- a/nix/docker/default.nix +++ b/nix/docker/default.nix @@ -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 = {