Skip to content

Commit

Permalink
update scripts, add init-env service, wip node-start service
Browse files Browse the repository at this point in the history
  • Loading branch information
eureka-cpu committed Jun 27, 2024
1 parent 9b30183 commit 973fb66
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 40 deletions.
88 changes: 54 additions & 34 deletions deployments/lasr_node/common.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, ... }:
{ pkgs, lasr_pkgs, ... }:
let
system = pkgs.stdenv.hostPlatform.system;
# Pull the PD server image from dockerhub
Expand All @@ -16,6 +16,8 @@ let
finalImageName = "pingcap/pd";
};
# Starts the placement driver server for TiKV.
# NOTE: This is a global script, which is run by default and is only
# necessary in scenarios where the server does not start automatically.
start-pd-server = pkgs.writeShellScriptBin "start-pd-server.sh" ''
docker run -d --name pd-server --network host pingcap/pd:latest \
--name="pd1" \
Expand All @@ -40,6 +42,8 @@ let
finalImageName = "pingcap/tikv";
};
# Starts the TiKV server.
# NOTE: This is a global script, which is run by default and is only
# necessary in scenarios where the server does not start automatically.
start-tikv-server = pkgs.writeShellScriptBin "start-tikv-server.sh" ''
docker run -d --name tikv-server --network host pingcap/tikv:latest \
--addr="127.0.0.1:20160" \
Expand All @@ -49,6 +53,8 @@ let
'';

# Creates the working directory, scripts & initializes the IPFS node.
# NOTE: This is a global script, which is run by default and is only
# necessary in scenarios where the systemd service fails.
setup-working-dir = pkgs.writeShellScriptBin "setup-working-dir.sh" ''
if [ -e "/app" ]; then
echo "Working directory already exists."
Expand Down Expand Up @@ -78,8 +84,9 @@ let
echo "Done"
exit 0
'';

# Initializes lasr_node environment variables and persists them between system boots.
# NOTE: This is a global script, which is run by default and is only
# necessary in scenarios where the systemd service fails.
init-env = pkgs.writeShellScriptBin "init-env.sh" ''
if [ -e "\$HOME/.bashrc" ]; then
echo "Environment already initialized."
Expand Down Expand Up @@ -117,21 +124,24 @@ let
executable = true;
destination = "/app/bin/start-ipfs.sh";
};

# TODO: Remove this and use either the cargo target bin, or nix bin directly.
# Starts the lasr_node from the release build.
# Starts the lasr_node from the release build specified by the nix flake.
start-lasr = pkgs.writeTextFile {
name = "start-lasr.sh";
text = ''
PREFIX=/app/lasr
cd $PREFIX
# For local development:
# The default behaviour will use the binary specified by the nix flake.
# This is important because it retains the flake.lock versioning.
# If this is not important to you, exchange the call to lasr_node
# with the following:
# ./target/release/lasr_node
lasr_node
'';
executable = true;
destination = "/app/bin/start-lasr.sh";
};

# Main process script. Re/starts the node and dependencies.
start-overmind = pkgs.writeTextFile {
name = "start-overmind.sh";
Expand Down Expand Up @@ -167,9 +177,9 @@ in
tmux
] ++ [
init-env
setup-working-dir
start-pd-server
start-tikv-server
setup-working-dir
];

# Enable docker socket
Expand Down Expand Up @@ -240,35 +250,45 @@ in
export IPFS_PATH=/app/tmp/kubo
"${pkgs.kubo}/bin/ipfs" init
'';
wantedBy = [ "default.target" ];
wantedBy = [ "node-start.service" ];
};
# init-env = {
# description = "Initializes lasr_node environment variables and persists them between system boots.";
# script = ''
# if [ -f "\$HOME/.bashrc" ]; then
# echo "Environment already initialized."
# exit 0
# fi
init-env = {
description = "Initializes lasr_node environment variables and persists them between system boots.";
script = ''
if [ -f "\$HOME/.bashrc" ]; then
echo "Environment already initialized."
exit 0
fi
# secret_key=$(${lasr_cli}/bin/lasr_cli wallet new | ${pkgs.jq}/bin/jq '.secret_key')
# block_path="/app/blocks_processed.dat"
# eth_rpc_url="https://u0anlnjcq5:xPYLI9OMwxRqJZqhfgEiKMeGdpVjGduGKmMCNBsu46Y@u0auvfalma-u0j1mdxq0w-rpc.us0-aws.kaleido.io/"
# eo_contract=0x563f0efeea703237b32ae7f66123b864f3e46a3c
# compute_rpc_url=ws://localhost:9125
# storage_rpc_url=ws://localhost:9126
# batch_interval=180
# echo "set -o noclobber" > ~/.bashrc
# echo "export SECRET_KEY=$secret_key" >> ~/.bashrc
# echo "export BLOCKS_PROCESSED_PATH=$block_path" >> ~/.bashrc
# echo "export ETH_RPC_URL=$eth_rpc_url" >> ~/.bashrc
# echo "export EO_CONTRACT_ADDRESS=$eo_contract" >> ~/.bashrc
# echo "export COMPUTE_RPC_URL=$compute_rpc_url" >> ~/.bashrc
# echo "export STORAGE_RPC_URL=$storage_rpc_url" >> ~/.bashrc
# echo "export BATCH_INTERVAL=$batch_interval" >> ~/.bashrc
# echo "[[ \$- == *i* && -f \"\$HOME/.bashrc\" ]] && source \"\$HOME/.bashrc\"" > ~/.bash_profile
# '';
# wantedBy = [ "default.target" ];
# };
secret_key=$(${lasr_pkgs.lasr_cli}/bin/lasr_cli wallet new | ${pkgs.jq}/bin/jq '.secret_key')
block_path="/app/blocks_processed.dat"
eth_rpc_url="https://u0anlnjcq5:xPYLI9OMwxRqJZqhfgEiKMeGdpVjGduGKmMCNBsu46Y@u0auvfalma-u0j1mdxq0w-rpc.us0-aws.kaleido.io/"
eo_contract=0x563f0efeea703237b32ae7f66123b864f3e46a3c
compute_rpc_url=ws://localhost:9125
storage_rpc_url=ws://localhost:9126
batch_interval=180
echo "set -o noclobber" > ~/.bashrc
echo "export SECRET_KEY=$secret_key" >> ~/.bashrc
echo "export BLOCKS_PROCESSED_PATH=$block_path" >> ~/.bashrc
echo "export ETH_RPC_URL=$eth_rpc_url" >> ~/.bashrc
echo "export EO_CONTRACT_ADDRESS=$eo_contract" >> ~/.bashrc
echo "export COMPUTE_RPC_URL=$compute_rpc_url" >> ~/.bashrc
echo "export STORAGE_RPC_URL=$storage_rpc_url" >> ~/.bashrc
echo "export BATCH_INTERVAL=$batch_interval" >> ~/.bashrc
echo "[[ \$- == *i* && -f \"\$HOME/.bashrc\" ]] && source \"\$HOME/.bashrc\"" > ~/.bash_profile
'';
wantedBy = [ "node-start.service" ];
};
# TODO: fix this, it no worky ):
node-start = {
description = "Start the lasr_node process.";
requires = [ "setup-working-dir.service" "init-env.service" ];
after = [ "setup-working-dir.service" "init-env.service" ];
script = ''
.${start-overmind}/app/bin/start-overmind.sh
'';
wantedBy = [ "default.target" ];
};
};

# Before changing, read this first:
Expand Down
26 changes: 20 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
# The linux virtual machine system architecture, derived from the host's environment
# Example: aarch64-darwin -> aarch64-linux
guest_system = builtins.replaceStrings [ "darwin" ] [ "linux" ] pkgs.stdenv.hostPlatform.system;
guest_pkgs = self.packages.${guest_system};
# Build packages for the linux variant of the host architecture, but preserve the host's
# version of nixpkgs to build the virtual machine with. This way, building and running a
# linux virtual environment works for all supported system architectures.
Expand Down Expand Up @@ -184,14 +185,20 @@
security.pam.services.sshd.allowNullPassword = true;

# Adding the LASR packages:
environment.systemPackages = [
self.packages.${guest_system}.lasr_node
self.packages.${guest_system}.lasr_cli
environment.systemPackages = with guest_pkgs; [
lasr_node
lasr_cli
];

nix.settings.experimental-features = ["nix-command" "flakes"];
})
];
specialArgs = {
lasr_pkgs = with guest_pkgs; {
lasr_node = lasr_node;
lasr_cli = lasr_cli;
};
};
};
in {
versa = versaNodeDrv;
Expand Down Expand Up @@ -347,6 +354,7 @@
}) // {
nixosConfigurations.lasr_nightly = let
system = flake-utils.lib.system.x86_64-linux;
nightly_pkgs = self.packages.${system};
in
nixpkgs.lib.nixosSystem {
inherit system;
Expand All @@ -357,12 +365,18 @@
imports = [ ./deployments/digital-ocean/digital-ocean-image.nix ];

# Adding the LASR packages:
environment.systemPackages = [
self.packages.${system}.lasr_node
self.packages.${system}.lasr_cli
environment.systemPackages = with nightly_pkgs; [
lasr_node
lasr_cli
];
})
];
specialArgs = {
lasr_pkgs = with nightly_pkgs; {
lasr_node = lasr_node;
lasr_cli = lasr_cli;
};
};
};
};
}

0 comments on commit 973fb66

Please sign in to comment.