From 32373a913cac483aef77d445e89618e066068fed Mon Sep 17 00:00:00 2001 From: mrasheduzzaman Date: Fri, 24 Nov 2023 10:54:21 +0600 Subject: [PATCH] Add Makefile for our project --- Makefile | 43 +++++++++++++++++++++++++++++++++++++++++++ README.md | 13 +++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5d9b62e --- /dev/null +++ b/Makefile @@ -0,0 +1,43 @@ +NAME=restful +VERSION=$(shell git rev-parse HEAD) +SEMVER_VERSION=$(shell grep version Cargo.toml | awk -F"\"" '{print $$2}' | head -n 1) +REPO=mrasheduzzaman +SHELL := /bin/bash + +no_postgres: + @[ -z "$$(docker ps -q -f ancestor="postgres:latest")" ] || (echo "db running"; exit 2) +has_postgres: + @[ -n "$$(docker ps -q -f ancestor="postgres:latest")" ] || (echo "db not running"; exit 2) + +db: no_postgres + @echo "Starting postgres container" + docker compose up -d db + +stop: + @docker ps -aq | xargs -r docker rm -f + @pkill $(NAME) || true + +setup: + cargo install cargo-watch + cargo install diesel_cli --no-default-features --features postgres + +test: + ./test.sh + +compose: + docker compose up -d + docker compose logs $(NAME) + +run: has_postgres + cargo watch -q -c -w src/ -x run + +compile: has_postgres + cargo build --release + +build: + @echo "Reusing built binary in current directory from make compile" + @ls -lah ./$(NAME) + docker build -t $(REPO)/$(NAME):$(VERSION) . + +tag-latest: build + docker tag $(REPO)/$(NAME):$(VERSION) $(REPO)/$(NAME):latest diff --git a/README.md b/README.md index 232b7df..730d4b5 100644 --- a/README.md +++ b/README.md @@ -232,3 +232,16 @@ make test **NB:** With `docker-compose` our migration would have to wait for postgres to initialize, either via a sleep or a `psql` "select 1" attempt. See `make compose` for more info. **NB:** The compile step is required before any build step, so `docker-compose up` would fail without it. It's possible to fix this by using a multistep docker build for the app, but it makes local build caching harder. + + +**NB:** Sometime run command can give you address/port in use error compile. Please follow the steps below to resolve it: + +```bash +#Find: +netstat -vanp tcp | grep 5001 +lsof -i tcp:5001 +lsof -i :5001 + +#Kill: +kill -9 +```