-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
68 lines (58 loc) · 2.17 KB
/
Makefile
File metadata and controls
68 lines (58 loc) · 2.17 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
.PHONY: all registry build push install clean uninstall
# Variables
REGISTRY_NAME := local-registry
REGISTRY_PORT := 8447
RANDOM_STRING := $(shell date +%s | sha256sum | base64 | head -c 8 | tr '[:upper:]' '[:lower:]')
IMAGE_NAME := agent-injector-$(RANDOM_STRING)
LOCAL_IMAGE := localhost:$(REGISTRY_PORT)/$(IMAGE_NAME)
CHART_DIR := ./helm
RELEASE_NAME := agent-injector
# ? Note(Daniel): If need be, you can change this to windows/amd64 to build the windows image.
PLATFORM := linux/amd64 # linux/amd64|windows/amd64
BUILD_TARGET := linux # linux|windows2019|windows2022
# Default target
up-dev: uninstall registry build push install
# Create local docker registry if it doesn't exist
registry:
@echo "Checking for local registry..."
@if [ ! "$$(docker ps -q -f name=$(REGISTRY_NAME))" ]; then \
if [ "$$(docker ps -aq -f status=exited -f name=$(REGISTRY_NAME))" ]; then \
echo "Starting existing registry container..."; \
docker start $(REGISTRY_NAME); \
else \
echo "Creating new local registry on port $(REGISTRY_PORT)..."; \
docker run -d \
--name $(REGISTRY_NAME) \
--restart=always \
-p $(REGISTRY_PORT):5000 \
registry:2; \
fi \
else \
echo "Registry already running"; \
fi
# Build the docker image
build:
@echo "Building Docker image: $(IMAGE_NAME) for $(PLATFORM)..."
docker build --target $(BUILD_TARGET) --platform $(PLATFORM) -t $(IMAGE_NAME):latest -f Dockerfile .
docker tag $(IMAGE_NAME):latest $(LOCAL_IMAGE):latest
# Push image to local registry
push:
@echo "Pushing image to local registry..."
docker push $(LOCAL_IMAGE):latest
# Install helm chart directly from directory
install:
@echo "Installing Helm chart from $(CHART_DIR)..."
helm upgrade --install $(RELEASE_NAME) $(CHART_DIR) \
--set image.repository=localhost:$(REGISTRY_PORT)/$(IMAGE_NAME) \
--set image.tag=latest \
--wait
# Uninstall the helm release
uninstall:
@echo "Uninstalling Helm release $(RELEASE_NAME)..."
helm uninstall $(RELEASE_NAME) || true
# Clean up everything including the local registry
clean: uninstall
@echo "Stopping and removing local registry..."
docker stop $(REGISTRY_NAME) || true
docker rm $(REGISTRY_NAME) || true
@echo "Cleanup complete"