-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
70 lines (54 loc) · 1.33 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Define Docker Compose command
DOCKER_COMPOSE := docker-compose
# Docker Compose file
COMPOSE_FILE := ./deployment/docker-compose.yml
# Variables
BINARY_NAME=heartbeat_shard_app
MAIN_GO=main.go
PID_FILE=app.pid
# Targets
build:
@echo "Building the application..."
@go build -o $(BINARY_NAME) $(MAIN_GO)
run: build
@echo "Running the application..."
@./$(BINARY_NAME) & echo $$! > $(PID_FILE)
clean:
@echo "Cleaning up..."
@rm -f $(BINARY_NAME)
#Generate SQL
generate-sql:
sqlc generate
# Build Docker containers
db-build:
$(DOCKER_COMPOSE) -f $(COMPOSE_FILE) build
# Run Docker containers
db-up:
$(DOCKER_COMPOSE) -f $(COMPOSE_FILE) up -d
# Stop Docker containers
db-down:
$(DOCKER_COMPOSE) -f $(COMPOSE_FILE) down
# Restart Docker containers
db-restart: down up
# View logs of Docker containers
db-logs:
$(DOCKER_COMPOSE) -f $(COMPOSE_FILE) logs -f
# Remove Docker containers and associated volumes
db-clean:
$(DOCKER_COMPOSE) -f $(COMPOSE_FILE) down -v
# Sleep for 1 second
sleep:
@sleep 1
# Create Setup
setup: db-up sleep run
# Bring down the setup
teardown: db-clean
@echo "Stopping the application..."
@if [ -f $(PID_FILE) ]; then \
PID=$$(cat $(PID_FILE)); \
kill $$PID && rm -f $(PID_FILE); \
echo "Application stopped."; \
else \
echo "No PID file found. Is the application running?"; \
fi
@rm -f $(BINARY_NAME)