From f89e6645dd22adc88301770ba34141fd0920cead Mon Sep 17 00:00:00 2001 From: Joshua Oladele Date: Tue, 11 Jun 2024 20:13:47 +0100 Subject: [PATCH] build(repo): allow starting & stopping nats server with docker-compose --- Makefile | 20 ++++++++++++++++++-- docker/.dockerignore | 1 + docker/docker-compose.yml | 6 ++++++ scripts/setup.sh | 13 ------------- 4 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 docker/.dockerignore create mode 100644 docker/docker-compose.yml diff --git a/Makefile b/Makefile index 0fb95954..98a808f7 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 00000000..ea8c4bf7 --- /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 00000000..5ebd24cb --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,6 @@ +version: "3.9" + +services: + nats: + image: nats:2.10.16 + ports: [4222:4222] diff --git a/scripts/setup.sh b/scripts/setup.sh index 331a008a..4923517a 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