From 0e4da4848bd663cf87140b3e80e27ec3ae4b2199 Mon Sep 17 00:00:00 2001 From: Alistair Date: Thu, 15 Aug 2024 11:53:47 +0100 Subject: [PATCH] feat(nix): configure treefmt for `nix fmt` This commit configures rustfmt, alejandra, prettier, and shfmt. --- crates/jstz_rollup/entrypoint.sh | 154 +++++++++--------- flake.lock | 23 ++- flake.nix | 25 ++- scripts/install-jstz-cli.sh | 148 ++++++++--------- scripts/pre-commit-hook.sh | 2 +- scripts/pre-push-hook.sh | 1 - scripts/run-operator.sh | 267 +++++++++++++++---------------- 7 files changed, 330 insertions(+), 290 deletions(-) diff --git a/crates/jstz_rollup/entrypoint.sh b/crates/jstz_rollup/entrypoint.sh index 60fe355d0..007db2ee6 100644 --- a/crates/jstz_rollup/entrypoint.sh +++ b/crates/jstz_rollup/entrypoint.sh @@ -7,7 +7,7 @@ mkdir -p "$JSTZ_ROLLUP_OCTEZ_CLIENT_DIR" export JSTZ_ROLLUP_OCTEZ_ROLLUP_NODE_DIR="/root/.octez-smart-rollup-node" mkdir -p "$JSTZ_ROLLUP_OCTEZ_ROLLUP_NODE_DIR" -# shellcheck disable=SC2034 +# shellcheck disable=SC2034 # JSTZ_ROLLUP_OCTEZ_NODE_ENDPOINT is used in the jstz-rollup command export JSTZ_ROLLUP_OCTEZ_NODE_ENDPOINT="https://rpc.$NETWORK.teztnets.com/" @@ -16,96 +16,96 @@ installer_dir="root/installer" logs_dir="root/logs" if [ ! -f "$JSTZ_ROLLUP_OCTEZ_CLIENT_DIR/secret_keys" ]; then - echo "Importing operator secret key..." - if [ -z "$OPERATOR_SK" ]; then - echo "OPERATOR_SK is not set" - exit 1 - fi - jstz-rollup operator import-keys --secret-key "$OPERATOR_SK" + echo "Importing operator secret key..." + if [ -z "$OPERATOR_SK" ]; then + echo "OPERATOR_SK is not set" + exit 1 + fi + jstz-rollup operator import-keys --secret-key "$OPERATOR_SK" fi make-installer() { - jstz-rollup make-installer \ - --kernel "$kernel_path" \ - --bridge "$JSTZ_ROLLUP_BRIDGE_ADDRESS" \ - --output "$installer_dir" - - # Check the exit status of the last command - if [ $? -eq 0 ]; then - echo "Installer created successfully in $installer_dir." - else - echo "Failed to create installer. Please check the parameters and try again." - exit 1 - fi + jstz-rollup make-installer \ + --kernel "$kernel_path" \ + --bridge "$JSTZ_ROLLUP_BRIDGE_ADDRESS" \ + --output "$installer_dir" + + # Check the exit status of the last command + if [ $? -eq 0 ]; then + echo "Installer created successfully in $installer_dir." + else + echo "Failed to create installer. Please check the parameters and try again." + exit 1 + fi } deploy-bridge() { - jstz-rollup deploy-bridge \ - --operator "$OPERATOR_ADDRESS" + jstz-rollup deploy-bridge \ + --operator "$OPERATOR_ADDRESS" } deploy-installer() { - jstz-rollup deploy-installer \ - --installer "$installer_dir/installer.wasm" \ - --bridge "$JSTZ_ROLLUP_BRIDGE_ADDRESS" + jstz-rollup deploy-installer \ + --installer "$installer_dir/installer.wasm" \ + --bridge "$JSTZ_ROLLUP_BRIDGE_ADDRESS" } run() { - if [ -z "$(ls -A $installer_dir)" ]; then - make-installer - fi - - mkdir -p "$logs_dir" - - jstz-rollup run \ - --preimages "$installer_dir/preimages" \ - --rollup "$JSTZ_ROLLUP_ADDRESS" \ - --logs "$logs_dir" \ - --addr "0.0.0.0" - - exit_status=$? - - if [ $exit_status -eq 0 ]; then - echo "jstz-rollup node started successfully." - else - echo "Failed to start jstz-rollup node. Exit status: $exit_status" - exit $exit_status - fi + if [ -z "$(ls -A $installer_dir)" ]; then + make-installer + fi + + mkdir -p "$logs_dir" + + jstz-rollup run \ + --preimages "$installer_dir/preimages" \ + --rollup "$JSTZ_ROLLUP_ADDRESS" \ + --logs "$logs_dir" \ + --addr "0.0.0.0" + + exit_status=$? + + if [ $exit_status -eq 0 ]; then + echo "jstz-rollup node started successfully." + else + echo "Failed to start jstz-rollup node. Exit status: $exit_status" + exit $exit_status + fi } deploy() { - JSTZ_ROLLUP_BRIDGE_ADDRESS=$(deploy-bridge | grep -oE 'KT1[a-zA-Z0-9]{33}' | uniq | tr -d '\n') - echo "Bridge address: $JSTZ_ROLLUP_BRIDGE_ADDRESS" - - jstz-rollup deploy \ - --kernel "$kernel_path" \ - --bridge "$JSTZ_ROLLUP_BRIDGE_ADDRESS" \ - --output "$installer_dir" \ - --operator "$OPERATOR_ADDRESS" + JSTZ_ROLLUP_BRIDGE_ADDRESS=$(deploy-bridge | grep -oE 'KT1[a-zA-Z0-9]{33}' | uniq | tr -d '\n') + echo "Bridge address: $JSTZ_ROLLUP_BRIDGE_ADDRESS" + + jstz-rollup deploy \ + --kernel "$kernel_path" \ + --bridge "$JSTZ_ROLLUP_BRIDGE_ADDRESS" \ + --output "$installer_dir" \ + --operator "$OPERATOR_ADDRESS" } main() { - command="$1" - shift 1 - - case $command in - "run") - run - ;; - "deploy") - deploy - ;; - "deploy-bridge") - deploy-bridge - ;; - "deploy-installer") - deploy-installer - ;; - "make-installer") - make-installer - ;; - *) - cat < Commands: @@ -115,11 +115,11 @@ Commands: deploy-installer make-installer EOF - exit 1 - ;; - esac + exit 1 + ;; + esac } if [ "$0" == "${BASH_SOURCE[0]}" ]; then - main "$@" + main "$@" fi diff --git a/flake.lock b/flake.lock index 426984fd0..4e190b6e5 100644 --- a/flake.lock +++ b/flake.lock @@ -79,7 +79,8 @@ "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", "npm-buildpackage": "npm-buildpackage", - "rust-overlay": "rust-overlay" + "rust-overlay": "rust-overlay", + "treefmt": "treefmt" } }, "rust-overlay": { @@ -119,6 +120,26 @@ "repo": "default", "type": "github" } + }, + "treefmt": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1723656612, + "narHash": "sha256-6Sx+/VhRPLR+kRf6rnNUFMQ66DUz1DMYajixYUe+CUU=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "4a6d7dccf80a1aa2d04cfaa88d9e5511542a2486", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 99b76701d..6c88f2578 100644 --- a/flake.nix +++ b/flake.nix @@ -2,6 +2,10 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs"; flake-utils.url = "github:numtide/flake-utils"; + treefmt = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; # Rust support rust-overlay = { @@ -54,9 +58,28 @@ rust-toolchain = pkgs.callPackage ./nix/rust-toolchain.nix {}; crates = pkgs.callPackage ./nix/crates.nix {inherit crane rust-toolchain;}; js-packages = pkgs.callPackage ./nix/js-packages.nix {}; + + fmt = treefmt.lib.evalModule pkgs { + projectRootFile = "flake.nix"; + + programs.rustfmt.enable = true; + programs.alejandra.enable = true; + programs.prettier.enable = true; + programs.shfmt.enable = true; + + # TODO(https://linear.app/tezos/issue/JSTZ-64) + # Configure shellcheck for shell scripts + # programs.shellcheck.enable = true; + + # TODO(https://linear.app/tezos/issue/JSTZ-63) + # Configure formatter for LIGO contracts + settings.global.excludes = ["target" "result" "node_modules/**" ".github" ".direnv" "contracts/**" "Dockerfile" "*.toml"]; + }; in { packages = crates.packages // js-packages.packages // {default = self.packages.${system}.jstz_kernel;}; - checks = crates.checks; + checks = crates.checks // {formatting = fmt.config.build.check self;}; + + formatter = fmt.config.build.wrapper; # Rust dev environment devShells.default = pkgs.mkShell { diff --git a/scripts/install-jstz-cli.sh b/scripts/install-jstz-cli.sh index f4306465b..2a1cc95ff 100755 --- a/scripts/install-jstz-cli.sh +++ b/scripts/install-jstz-cli.sh @@ -2,50 +2,50 @@ { # this ensures the entire script is downloaded -version="20240703" -network="ghostnet" -# FIXME: https://app.asana.com/0/1205770721173533/1207698416028745/f -# Update the container URL to point to jstz-dev instead of trilitech -# (once the runners have been transferred) -container="ghcr.io/trilitech/jstz-cli:$version" -jstz_home="$HOME/.jstz" - -# ps -p filters on the parent process, -o comm= prints the command name (supressing the header) -current_shell=$(basename "$(ps -p $$ -o comm=)") -shell=$(basename "$SHELL") - -# (--rm): remove the container after it exits -# (-v): the container mounts the following volumes: -# - /tmp for temporary files -# - $HOME/.jstz for configuration -# - $PWD for the current working directory -# (-it): for interactive mode & tty support -# (--network=host): use the host's network stack -# (-w): set the working directory to the current working directory -shell_alias="alias jstz='docker run --rm -v \"/tmp:/tmp\" -v \"$jstz_home:/root/.jstz\" -v \"\$PWD:\$PWD\" -w \"\$PWD\" --network=host -it $container'" - -jstz_download() { + version="20240703" + network="ghostnet" + # FIXME: https://app.asana.com/0/1205770721173533/1207698416028745/f + # Update the container URL to point to jstz-dev instead of trilitech + # (once the runners have been transferred) + container="ghcr.io/trilitech/jstz-cli:$version" + jstz_home="$HOME/.jstz" + + # ps -p filters on the parent process, -o comm= prints the command name (supressing the header) + current_shell=$(basename "$(ps -p $$ -o comm=)") + shell=$(basename "$SHELL") + + # (--rm): remove the container after it exits + # (-v): the container mounts the following volumes: + # - /tmp for temporary files + # - $HOME/.jstz for configuration + # - $PWD for the current working directory + # (-it): for interactive mode & tty support + # (--network=host): use the host's network stack + # (-w): set the working directory to the current working directory + shell_alias="alias jstz='docker run --rm -v \"/tmp:/tmp\" -v \"$jstz_home:/root/.jstz\" -v \"\$PWD:\$PWD\" -w \"\$PWD\" --network=host -it $container'" + + jstz_download() { # Check if Docker is installed - if ! command -v docker &> /dev/null; then - echo "Docker is not installed. Please install Docker and try again." - return 1 + if ! command -v docker &>/dev/null; then + echo "Docker is not installed. Please install Docker and try again." + return 1 fi # Pull the Docker CLI container from GitHub Container Registry echo "Pulling jstz-cli docker container from GHCR..." DOCKER_CLI_HINTS=false docker pull "$container" echo "" -} + } -jstz_configure() { + jstz_configure() { echo -n "Configuring jstz..." mkdir -p "$jstz_home" - + config_file="$jstz_home/config.json" temp_file=$(mktemp) - cat >"$temp_file" << EOF + cat >"$temp_file" <&2 "Unsupported shell: $shell. Please manually add the following alias to your shell's configuration file." - echo >&2 " $shell_alias" - return 1 + echo >&2 "Unsupported shell: $shell. Please manually add the following alias to your shell's configuration file." + echo >&2 " $shell_alias" + return 1 fi if ! [ -w "$shellrc" ]; then - echo "Warning: $shellrc is not writable. Please manually add the following alias to your shell's configuration file:" - echo "$shell_alias" + echo "Warning: $shellrc is not writable. Please manually add the following alias to your shell's configuration file:" + echo "$shell_alias" - echo "Once you have added the alias, run the following command to reload the configuration file in your default shell:" - echo " source $shellrc" - return 1 + echo "Once you have added the alias, run the following command to reload the configuration file in your default shell:" + echo " source $shellrc" + return 1 fi if grep -q "alias jstz=" "$shellrc"; then - sed -i'' -e "/alias jstz=/c\\ + sed -i'' -e "/alias jstz=/c\\ $shell_alias" "$shellrc" - echo "Alias updated in $shellrc." + echo "Alias updated in $shellrc." else - echo "$shell_alias" >> "$shellrc" - echo "Alias added to $shellrc." + echo "$shell_alias" >>"$shellrc" + echo "Alias added to $shellrc." fi echo "$shell_alias" # shellcheck disable=SC1090 # `$shellrc` can only be determined at runtime, so we need to disable the warning. - # - # Reload the shell configuration file to apply the changes - if [[ "$shell" == "$current_shell" ]]; then - echo "Reloading shell configuration file: $shellrc" - . "$shellrc" + # + # Reload the shell configuration file to apply the changes + if [[ $shell == "$current_shell" ]]; then + echo "Reloading shell configuration file: $shellrc" + . "$shellrc" else - echo "The current shell session does not match the default shell. Configuration file not reloaded." - echo "Please run the following command from your default shell to reload the configuration file:" - echo " source $shellrc" + echo "The current shell session does not match the default shell. Configuration file not reloaded." + echo "Please run the following command from your default shell to reload the configuration file:" + echo " source $shellrc" fi -} + } -do_install() { + do_install() { jstz_download jstz_configure jstz_reset -} + } -jstz_reset() { + jstz_reset() { unset -f jstz_download jstz_configure jstz_reset do_install -} + } -do_install + do_install -} \ No newline at end of file +} diff --git a/scripts/pre-commit-hook.sh b/scripts/pre-commit-hook.sh index 523aa38ef..e4db1e695 100644 --- a/scripts/pre-commit-hook.sh +++ b/scripts/pre-commit-hook.sh @@ -20,7 +20,7 @@ You can use 'git diff' to see the changes made by 'make fmt'. If your git index originally contained some unstaged files, they have been stashed. Run 'git stash pop' to retrieve them. EOF - exit 1 + exit 1 fi # Pop the stash if we stashed earlier (if there were no formatting changes) diff --git a/scripts/pre-push-hook.sh b/scripts/pre-push-hook.sh index f669ccb74..9b61bfadf 100644 --- a/scripts/pre-push-hook.sh +++ b/scripts/pre-push-hook.sh @@ -1,7 +1,6 @@ #!/usr/bin/env bash set -euo pipefail - # Run linting make lint diff --git a/scripts/run-operator.sh b/scripts/run-operator.sh index 9c16fc5af..3e0466f5c 100755 --- a/scripts/run-operator.sh +++ b/scripts/run-operator.sh @@ -2,169 +2,166 @@ set -e jstz_check_context() { - if ! docker context ls --format '{{.Name}}' | grep -w "$1"; then - echo "Docker context \"$1\" does not exist" - exit 1 - fi + if ! docker context ls --format '{{.Name}}' | grep -w "$1"; then + echo "Docker context \"$1\" does not exist" + exit 1 + fi } jstz_load_dotenv() { - set -a - # shellcheck source=../.env - source .env - set +a + set -a + # shellcheck source=../.env + source .env + set +a } jstz_configure_env_network() { - IFS= read -r -p "Enter network: " network - sed -i"" -e "s|NETWORK=.*|NETWORK=\"$network\"|g" .env + IFS= read -r -p "Enter network: " network + sed -i"" -e "s|NETWORK=.*|NETWORK=\"$network\"|g" .env - IFS= read -r -p "Enter tag for jstz containers: " jstz_tag - sed -i"" -e "s|JSTZ_TAG=.*|JSTZ_TAG=\"$jstz_tag\"|g" .env + IFS= read -r -p "Enter tag for jstz containers: " jstz_tag + sed -i"" -e "s|JSTZ_TAG=.*|JSTZ_TAG=\"$jstz_tag\"|g" .env } jstz_configure_env_rollup() { - IFS= read -r -p "Enter jstz rollup address: " jstz_rollup_address - sed -i"" -e "s|JSTZ_ROLLUP_ADDRESS=.*|JSTZ_ROLLUP_ADDRESS=\"$jstz_rollup_address\"|g" .env + IFS= read -r -p "Enter jstz rollup address: " jstz_rollup_address + sed -i"" -e "s|JSTZ_ROLLUP_ADDRESS=.*|JSTZ_ROLLUP_ADDRESS=\"$jstz_rollup_address\"|g" .env - IFS= read -r -p "Enter jstz bridge address: " jstz_rollup_bridge_address - sed -i"" -e "s|JSTZ_ROLLUP_BRIDGE_ADDRESS=.*|JSTZ_ROLLUP_BRIDGE_ADDRESS=\"$jstz_rollup_bridge_address\"|g" .env + IFS= read -r -p "Enter jstz bridge address: " jstz_rollup_bridge_address + sed -i"" -e "s|JSTZ_ROLLUP_BRIDGE_ADDRESS=.*|JSTZ_ROLLUP_BRIDGE_ADDRESS=\"$jstz_rollup_bridge_address\"|g" .env } jstz_configure_env() { - do_configure_rollup="$1" - - if [ ! -f ".env" ]; then - cp .env.example .env - echo ".env file created from .env.example" - - IFS= read -r -p "Enter operator secret key: " operator_sk - sed -i"" -e "s|OPERATOR_SK=.*|OPERATOR_SK=\"$operator_sk\"|g" .env - - IFS= read -r -p "Enter operator address: " operator_address - sed -i"" -e "s|OPERATOR_ADDRESS=.*|OPERATOR_ADDRESS=\"$operator_address\"|g" .env - - IFS= read -r -p "Enter docker registry: " docker_registry - sed -i"" -e "s|DOCKER_REGISTRY=.*|DOCKER_REGISTRY=\"$docker_registry\"|g" .env - - jstz_configure_env_network - - if [ "$do_configure_rollup" = "--configure-rollup" ]; then - jstz_configure_env_rollup - fi - echo ".env file setup" - else - echo ".env file already exists" - - IFS= read -r -p "Do you want to configure a new network (y/n): " update_network - if [ "$update_network" = "y" ]; then - jstz_configure_env_network - echo "new network setup" - fi - - if [ "$do_configure_rollup" = "--configure-rollup" ]; then - IFS= read -r -p "Do you want to configure a new rollup (y/n): " update_rollup - if [ "$update_rollup" = "y" ]; then - jstz_configure_env_rollup - echo "new network setup" - fi - fi - fi -} - -jstz_deploy() { - context="$1" - if [ -z "$context" ]; then - echo "Usage: start " - exit 1 - fi - jstz_check_context "$1" - - jstz_configure_env - - - if [ "$1" = "remote" ] - then - echo "Pulling latest images from GHCR" - docker-compose --context "$1" pull - else - echo "Context is not remote. Skipping pull." - fi + do_configure_rollup="$1" - echo "Deploying rollup..." + if [ ! -f ".env" ]; then + cp .env.example .env + echo ".env file created from .env.example" - # Load the .env file to obtain the various environment variables - jstz_load_dotenv + IFS= read -r -p "Enter operator secret key: " operator_sk + sed -i"" -e "s|OPERATOR_SK=.*|OPERATOR_SK=\"$operator_sk\"|g" .env - network=${NETWORK:?Unset NETWORK in .env} - operator_sk=${OPERATOR_SK:?Unset OPERATOR_SK in .env} - operator_address=${OPERATOR_ADDRESS:?Unset OPERATOR_ADDRESS in .env} - jstz_tag=${JSTZ_TAG:?Unset JSTZ_TAG in .env} - docker_registry=${DOCKER_REGISTRY} + IFS= read -r -p "Enter operator address: " operator_address + sed -i"" -e "s|OPERATOR_ADDRESS=.*|OPERATOR_ADDRESS=\"$operator_address\"|g" .env - output=$(docker --context "$1" run -v /var/run/docker.sock:/var/run/docker.sock \ - -e NETWORK="$network" -e OPERATOR_SK="$operator_sk" -e OPERATOR_ADDRESS="$operator_address" \ - "${docker_registry}jstz-rollup:$jstz_tag" deploy) + IFS= read -r -p "Enter docker registry: " docker_registry + sed -i"" -e "s|DOCKER_REGISTRY=.*|DOCKER_REGISTRY=\"$docker_registry\"|g" .env - echo "$output" + jstz_configure_env_network - IFS= read -r -p "Do you want to update .env with the rollup and bridge addresses (y/n): " update_env - if [ "$update_env" = "y" ]; then - bridge_address=$(echo "$output" | grep -oE "KT1[a-zA-Z0-9]{33}" | uniq | tr -d '\n') - rollup_address=$(echo "$output" | grep -oE "sr1[a-zA-Z0-9]{33}" | uniq | tr -d '\n') + if [ "$do_configure_rollup" = "--configure-rollup" ]; then + jstz_configure_env_rollup + fi + echo ".env file setup" + else + echo ".env file already exists" + + IFS= read -r -p "Do you want to configure a new network (y/n): " update_network + if [ "$update_network" = "y" ]; then + jstz_configure_env_network + echo "new network setup" + fi - echo "Updating .env with rollup and bridge addresses" - sed -i"" -e "s|JSTZ_ROLLUP_ADDRESS=.*|JSTZ_ROLLUP_ADDRESS=\"$rollup_address\"|g" .env - sed -i"" -e "s|JSTZ_ROLLUP_BRIDGE_ADDRESS=.*|JSTZ_ROLLUP_BRIDGE_ADDRESS=\"$bridge_address\"|g" .env + if [ "$do_configure_rollup" = "--configure-rollup" ]; then + IFS= read -r -p "Do you want to configure a new rollup (y/n): " update_rollup + if [ "$update_rollup" = "y" ]; then + jstz_configure_env_rollup + echo "new network setup" + fi fi + fi +} - echo "Rollup deployed" +jstz_deploy() { + context="$1" + if [ -z "$context" ]; then + echo "Usage: start " + exit 1 + fi + jstz_check_context "$1" + + jstz_configure_env + + if [ "$1" = "remote" ]; then + echo "Pulling latest images from GHCR" + docker-compose --context "$1" pull + else + echo "Context is not remote. Skipping pull." + fi + + echo "Deploying rollup..." + + # Load the .env file to obtain the various environment variables + jstz_load_dotenv + + network=${NETWORK:?Unset NETWORK in .env} + operator_sk=${OPERATOR_SK:?Unset OPERATOR_SK in .env} + operator_address=${OPERATOR_ADDRESS:?Unset OPERATOR_ADDRESS in .env} + jstz_tag=${JSTZ_TAG:?Unset JSTZ_TAG in .env} + docker_registry=${DOCKER_REGISTRY} + + output=$(docker --context "$1" run -v /var/run/docker.sock:/var/run/docker.sock \ + -e NETWORK="$network" -e OPERATOR_SK="$operator_sk" -e OPERATOR_ADDRESS="$operator_address" \ + "${docker_registry}jstz-rollup:$jstz_tag" deploy) + + echo "$output" + + IFS= read -r -p "Do you want to update .env with the rollup and bridge addresses (y/n): " update_env + if [ "$update_env" = "y" ]; then + bridge_address=$(echo "$output" | grep -oE "KT1[a-zA-Z0-9]{33}" | uniq | tr -d '\n') + rollup_address=$(echo "$output" | grep -oE "sr1[a-zA-Z0-9]{33}" | uniq | tr -d '\n') + + echo "Updating .env with rollup and bridge addresses" + sed -i"" -e "s|JSTZ_ROLLUP_ADDRESS=.*|JSTZ_ROLLUP_ADDRESS=\"$rollup_address\"|g" .env + sed -i"" -e "s|JSTZ_ROLLUP_BRIDGE_ADDRESS=.*|JSTZ_ROLLUP_BRIDGE_ADDRESS=\"$bridge_address\"|g" .env + fi + + echo "Rollup deployed" } jstz_start() { - context="$1" - if [ -z "$context" ]; then - echo "Usage: start " - exit 1 - fi - jstz_check_context "$1" - - jstz_configure_env --configure-rollup - - echo "Stopping current containers (if running)" - docker-compose --context "$1" down - - if [ "$1" = "remote" ] - then - echo "Pulling latest images from GHCR" - docker-compose --context "$1" pull - else - echo "Context is not remote. Skipping pull." - fi - - echo "Spinning up containers" - docker-compose --context "$1" up -d + context="$1" + if [ -z "$context" ]; then + echo "Usage: start " + exit 1 + fi + jstz_check_context "$1" + + jstz_configure_env --configure-rollup + + echo "Stopping current containers (if running)" + docker-compose --context "$1" down + + if [ "$1" = "remote" ]; then + echo "Pulling latest images from GHCR" + docker-compose --context "$1" pull + else + echo "Context is not remote. Skipping pull." + fi + + echo "Spinning up containers" + docker-compose --context "$1" up -d } main() { - command="$1" - shift 1 - - case "$command" in - start) - jstz_start "$@" - ;; - deploy) - jstz_deploy "$@" - ;; - *) - echo "Usage: scripts/run-operator.sh " - echo "Commands:" - echo " start " - echo " deploy " - exit 1 - ;; - esac + command="$1" + shift 1 + + case "$command" in + start) + jstz_start "$@" + ;; + deploy) + jstz_deploy "$@" + ;; + *) + echo "Usage: scripts/run-operator.sh " + echo "Commands:" + echo " start " + echo " deploy " + exit 1 + ;; + esac } -main "$@" \ No newline at end of file +main "$@"