-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
101 lines (87 loc) · 2.98 KB
/
Makefile
File metadata and controls
101 lines (87 loc) · 2.98 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Variables
APP_NAME := operator
DOCKER_USERNAME := aaronnguyenillumio
DOCKER_IMAGE := $(DOCKER_USERNAME)/$(APP_NAME)
LOCAL_REGISTRY := localhost:5000
LOCAL_IMAGE := $(LOCAL_REGISTRY)/$(APP_NAME)
COMMIT := $(shell git rev-parse --short HEAD)
DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
LDFLAGS := -ldflags "-X main.Version=latest -X main.Commit=$(COMMIT) -X main.Date=$(DATE)"
# Default target
.PHONY: all
all: build
# Build the Go project
.PHONY: build
build:
@echo "Building the project..."
go build $(LDFLAGS) -o $(APP_NAME) ./cmd
# Run tests
.PHONY: test
test:
@echo "Running tests..."
go test ./...
# Clean the build
.PHONY: clean
clean:
@echo "Cleaning up..."
rm -f $(APP_NAME)
# Build Docker image
.PHONY: docker-build
docker-build:
@echo "Building Docker image..."
docker buildx build --platform linux/amd64,linux/arm64 --load -t $(DOCKER_IMAGE):latest .
# Push Docker image to Docker Hub
.PHONY: docker-push
docker-push:
@echo "Pushing Docker image to Docker Hub..."
docker push $(DOCKER_IMAGE):latest
# Deploy target (build and push Docker image to Docker Hub)
.PHONY: deploy
deploy: docker-build docker-push
# Check if Docker is running
.PHONY: docker-check
docker-check:
@docker info > /dev/null 2>&1 || (echo "Docker is not running. Please start Docker." && exit 1)
# Create and run a local Docker registry
.PHONY: docker-registry-local
docker-registry-local: docker-check
@echo "Creating Local Docker Registry..."
@if [ "`docker ps -a -q -f name=registry`" ]; then \
echo "Local registry already running"; \
else \
docker run -d -p 5000:5000 --name registry registry:2; \
fi
# Build Docker image for local registry
.PHONY: docker-build-local
docker-build-local: build
@echo "Building Docker image for local registry..."
docker build -t $(LOCAL_IMAGE):latest .
# Build Docker image for local registry and push it
.PHONY: docker-push-local
docker-push-local: docker-build-local
@echo "Pushing Docker image to local registry..."
docker push $(LOCAL_IMAGE):latest
# Deploy target (build and push Docker image to local registry)
.PHONY: deploy-local
deploy-local: docker-build-local docker-push-local
# Run the Go project
.PHONY: run
run:
@echo "Running the project..."
go run $(LDFLAGS) ./cmd/main.go
# Help target to display available commands
.PHONY: help
help:
@echo "Available targets:"
@echo " build Build the Go project"
@echo " test Run tests"
@echo " clean Clean the build"
@echo " docker-build Build Docker image"
@echo " docker-push Push Docker image to Docker Hub"
@echo " deploy Build and push Docker image to Docker Hub"
@echo " docker-registry-local Create and run a local Docker registry"
@echo " docker-build-local Build Docker image for local registry"
@echo " docker-push-local Push Docker image to local registry"
@echo " deploy-local Build and push Docker image to local registry"
@echo " run Run the Go project"
@echo " help Display this help message"