Skip to content

Commit

Permalink
Add Makefile for our project
Browse files Browse the repository at this point in the history
  • Loading branch information
rashed091 committed Nov 24, 2023
1 parent a704318 commit 32373a9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <PID>
```

0 comments on commit 32373a9

Please sign in to comment.