From 2a8857a4ff5e9e2da2ad2661ea8fdbecd5d7a34f Mon Sep 17 00:00:00 2001 From: Joshua Oladele Date: Wed, 12 Jun 2024 10:59:54 +0100 Subject: [PATCH] build(repo): allow starting & stopping nats server locally --- Makefile | 20 ++++++++++++++++++-- docker/.dockerignore | 1 + docker/docker-compose.yml | 7 +++++++ scripts/setup.sh | 13 ------------- 4 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 docker/.dockerignore create mode 100644 docker/docker-compose.yml diff --git a/Makefile b/Makefile index 0fb9595..98a808f 100644 --- a/Makefile +++ b/Makefile @@ -5,14 +5,23 @@ TARGET ?= aarch64-apple-darwin PACKAGE ?= fuel-core-nats -.PHONY: all build run clean lint fmt help test doc +.PHONY: all build run clean lint fmt help setup start-nats stop-nats test doc all: build install: cargo fetch -setup: +check-commands: + @for cmd in $(COMMANDS); do \ + if ! command -v $$cmd >/dev/null 2>&1; then \ + echo >&2 "$$cmd is not installed. Please install $$cmd and try again.."; \ + exit 1; \ + fi \ + done + +setup: COMMANDS=rustup pre-commit +setup: check-commands ./scripts/setup.sh # ------------------------------------------------------------ @@ -32,6 +41,13 @@ dev-watch: build: install cargo build --release --target "$(TARGET)" --package "$(PACKAGE)" +start-nats: CMDS=docker-compose +start-nats: check-commands + docker-compose -f docker/docker-compose.yml up + +stop-nats: + docker-compose -f docker/docker-compose.yml down + run: cargo run --release diff --git a/docker/.dockerignore b/docker/.dockerignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/docker/.dockerignore @@ -0,0 +1 @@ +/target diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..9b0912c --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,7 @@ +version: "3.9" + +services: + nats: + container_name: fuel-core-nats-server + image: nats:2.10.16 + ports: [4222:4222] diff --git a/scripts/setup.sh b/scripts/setup.sh index 331a008..4923517 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -1,18 +1,5 @@ #!/bin/bash -# Check if a command exists using which -check_command() { - if ! which "$1" >/dev/null 2>&1; then - echo "$1 is not installed. Please install $1 and try again." - exit 1 - fi -} - -# Check if Rust is installed -check_command rustup -# Check if pre-commit is installed -check_command pre-commit - # Install pre-commit hooks pre-commit install