-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
40 lines (32 loc) · 1019 Bytes
/
Makefile
File metadata and controls
40 lines (32 loc) · 1019 Bytes
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
# Define variables
DOCKER_COMPOSE_FILE=docker-compose.yml
DOCKER_SERVICE=db
APP_NAME=bank-api
# Define Go version
GO_VERSION=1.22
# Ensure the correct Go version is used
ensure-go-version:
@echo "Ensuring Go version $(GO_VERSION) is used..."
@if [ "$(shell go version | grep -o 'go[0-9].[0-9]\{1,2\}')" != "go$(GO_VERSION)" ]; then \
echo "Go version mismatch. Please use Go $(GO_VERSION)."; \
exit 1; \
fi
# Clean up Docker containers
clean:
@echo "Stopping and removing Docker containers..."
docker-compose -f $(DOCKER_COMPOSE_FILE) down
# Start fresh Docker containers
start:
@echo "Starting Docker containers..."
docker-compose -f $(DOCKER_COMPOSE_FILE) up -d
# Build the Go application
build: ensure-go-version
@echo "Building the Go application..."
go build -o $(APP_NAME) main.go
# Run the Go application
run:
@echo "Running the Go application..."
./$(APP_NAME)
# Complete process: clean, start, build, and run
all: clean start build run
.PHONY: clean start build run all ensure-go-version