Removed go dependency on make
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
include ../build.env
|
||||
|
||||
BUILD_PLATFORM ?= linux/amd64
|
||||
|
||||
# Should be the same as upstream version in production
|
||||
VERSION ?= dev
|
||||
UBOOT_VERSION=v2026.01
|
||||
UBOOT_VERSION ?= v2026.01
|
||||
|
||||
# Target kube version
|
||||
KUBE_VERSION ?= v1.33.3
|
||||
@@ -13,15 +15,28 @@ PACKAGES_DIR := packages
|
||||
BIN_DIR := bin
|
||||
OUT_DIR := out
|
||||
|
||||
UBOOT_TAR := $(PACKAGES_DIR)/uboot-$(UBOOT_VERSION).tar.gz
|
||||
|
||||
UBOOT_TAR := $(PACKAGES_DIR)/uboot-$(UBOOT_VERSION).tar.gz
|
||||
BUILDINFO_FILE := pkg/buildinfo/buildinfo_gen.go
|
||||
CRD_PATHS := ./pkg/apis/...
|
||||
CRD_PATHS := ./pkg/apis/...
|
||||
|
||||
|
||||
BUILDX_BUILDER := container-builder
|
||||
LOCAL_REGISTRY := registry
|
||||
LOCAL_REGISTRY_PORT := 5000
|
||||
|
||||
CTL_BUILD_BASE_IMAGE := localhost:5000/monok8s/ctl-build-base:$(VERSION)
|
||||
CTL_BINARY := ctl-linux-aarch64-$(VERSION)
|
||||
|
||||
$(PACKAGES_DIR):
|
||||
mkdir -p $@
|
||||
|
||||
# Never cache this
|
||||
$(BIN_DIR):
|
||||
mkdir -p $@
|
||||
|
||||
$(OUT_DIR):
|
||||
mkdir -p $@
|
||||
|
||||
# Keep buildinfo host-side since it is just generated source and lets Docker see it in build context.
|
||||
.buildinfo:
|
||||
@mkdir -p $(dir $(BUILDINFO_FILE))
|
||||
@printf '%s\n' \
|
||||
@@ -35,11 +50,41 @@ $(PACKAGES_DIR):
|
||||
')' \
|
||||
> $(BUILDINFO_FILE)
|
||||
|
||||
$(UBOOT_TAR): | $(PACKAGES_DIR)
|
||||
git clone --depth 1 --branch v2026.01 --filter=blob:none https://github.com/u-boot/u-boot.git $(OUT_DIR)/u-boot-$(UBOOT_VERSION)
|
||||
ensure-buildx:
|
||||
@if ! docker buildx inspect $(BUILDX_BUILDER) >/dev/null 2>&1; then \
|
||||
echo "Creating buildx builder $(BUILDX_BUILDER)..."; \
|
||||
docker buildx create \
|
||||
--name $(BUILDX_BUILDER) \
|
||||
--driver docker-container \
|
||||
--driver-opt network=host \
|
||||
--bootstrap --use; \
|
||||
else \
|
||||
echo "Using existing buildx builder $(BUILDX_BUILDER)"; \
|
||||
docker buildx use $(BUILDX_BUILDER); \
|
||||
fi
|
||||
|
||||
ensure-registry:
|
||||
@if ! docker container inspect $(LOCAL_REGISTRY) >/dev/null 2>&1; then \
|
||||
echo "Creating local registry..."; \
|
||||
docker run -d \
|
||||
--restart=always \
|
||||
-p $(LOCAL_REGISTRY_PORT):5000 \
|
||||
--name $(LOCAL_REGISTRY) \
|
||||
registry:2; \
|
||||
else \
|
||||
if [ "$$(docker inspect -f '{{.State.Running}}' $(LOCAL_REGISTRY))" != "true" ]; then \
|
||||
echo "Starting existing local registry..."; \
|
||||
docker start $(LOCAL_REGISTRY); \
|
||||
fi; \
|
||||
fi
|
||||
|
||||
$(UBOOT_TAR): | $(PACKAGES_DIR) $(OUT_DIR)
|
||||
rm -rf "$(OUT_DIR)/u-boot-$(UBOOT_VERSION)"
|
||||
git clone --depth 1 --branch "$(UBOOT_VERSION)" --filter=blob:none \
|
||||
https://github.com/u-boot/u-boot.git "$(OUT_DIR)/u-boot-$(UBOOT_VERSION)"
|
||||
tar -C "$(OUT_DIR)/u-boot-$(UBOOT_VERSION)" -zcf "$@" .
|
||||
rm -rf $(OUT_DIR)/u-boot-$(UBOOT_VERSION)
|
||||
test -f $@
|
||||
rm -rf "$(OUT_DIR)/u-boot-$(UBOOT_VERSION)"
|
||||
test -f "$@"
|
||||
|
||||
uboot-tools: $(UBOOT_TAR)
|
||||
docker buildx build --platform linux/arm64 \
|
||||
@@ -48,40 +93,78 @@ uboot-tools: $(UBOOT_TAR)
|
||||
--build-arg UBOOT_TAR=$(UBOOT_TAR) \
|
||||
--output type=local,dest=./$(OUT_DIR) .
|
||||
|
||||
build: .buildinfo
|
||||
mkdir -p $(BIN_DIR) $(OUT_DIR)/crds
|
||||
controller-gen crd paths=$(CRD_PATHS) output:crd:dir=$(OUT_DIR)/crds
|
||||
GOOS=linux GOARCH=arm64 go build -o $(BIN_DIR)/ctl-linux-aarch64-$(VERSION) ./cmd/ctl
|
||||
ctl-build-base: ensure-buildx ensure-registry
|
||||
docker buildx build \
|
||||
--platform linux/amd64,linux/arm64 \
|
||||
-f docker/ctl-build-base.Dockerfile \
|
||||
-t $(CTL_BUILD_BASE_IMAGE) \
|
||||
--output type=image,push=true,registry.insecure=true .
|
||||
|
||||
build-bin: ctl-build-base | $(BIN_DIR)
|
||||
docker buildx build \
|
||||
--platform $(BUILD_PLATFORM) \
|
||||
-f docker/ctl-builder.Dockerfile \
|
||||
--build-arg BASE_IMAGE=$(CTL_BUILD_BASE_IMAGE) \
|
||||
--build-arg VERSION=$(VERSION) \
|
||||
--build-arg TARGETOS=linux \
|
||||
--build-arg TARGETARCH=arm64 \
|
||||
--output type=local,dest=./$(BIN_DIR) .
|
||||
|
||||
build-crds: ctl-build-base | $(OUT_DIR)
|
||||
mkdir -p "$(OUT_DIR)/crds"
|
||||
docker buildx build \
|
||||
--platform $(BUILD_PLATFORM) \
|
||||
-f docker/crdgen.Dockerfile \
|
||||
--build-arg BASE_IMAGE=$(CTL_BUILD_BASE_IMAGE) \
|
||||
--output type=local,dest=./$(OUT_DIR)/crds .
|
||||
|
||||
build-agent: build uboot-tools
|
||||
docker build \
|
||||
docker buildx build \
|
||||
--platform linux/arm64 \
|
||||
-f docker/ctl-agent.Dockerfile \
|
||||
--platform=linux/arm64 \
|
||||
--build-arg VERSION=$(VERSION) \
|
||||
--load \
|
||||
-t localhost/monok8s/control-agent:$(VERSION) .
|
||||
|
||||
build-local: .buildinfo
|
||||
mkdir -p $(BIN_DIR)
|
||||
go build -o $(BIN_DIR)/ctl-$(VERSION) ./cmd/ctl
|
||||
build-local: .buildinfo | $(BIN_DIR)
|
||||
docker buildx build \
|
||||
-f docker/ctl-builder-local.Dockerfile \
|
||||
--build-arg VERSION=$(VERSION) \
|
||||
--build-arg KUBE_VERSION=$(KUBE_VERSION) \
|
||||
--build-arg GIT_REV=$(GIT_REV) \
|
||||
--output type=local,dest=./$(BIN_DIR) .
|
||||
|
||||
run-agent:
|
||||
go run -tags dev ./cmd/ctl agent --env-file ./out/cluster.env
|
||||
docker run --rm \
|
||||
-v "$$(pwd)/out:/work/out" \
|
||||
localhost/monok8s/control-agent:$(VERSION) \
|
||||
agent --env-file /work/out/cluster.env
|
||||
|
||||
build: build-bin build-crds
|
||||
|
||||
clean:
|
||||
-docker image rm localhost/monok8s/control-agent:$(VERSION)
|
||||
rm -rf $(BIN_DIR) \
|
||||
$(BUILDINFO_FILE) \
|
||||
$(OUT_DIR)/crds
|
||||
-docker image rm localhost/monok8s/control-agent:$(VERSION) >/dev/null 2>&1 || true
|
||||
rm -rf \
|
||||
$(BIN_DIR) \
|
||||
$(OUT_DIR)/crds \
|
||||
$(BUILDINFO_FILE)
|
||||
|
||||
dockerclean:
|
||||
@echo "Removing tagged images..."
|
||||
- docker rmi \
|
||||
localhost/monok8s/control-agent:$(VERSION) \
|
||||
localhost/monok8s/ctl-builder:$(VERSION) \
|
||||
localhost/monok8s/crdgen:$(VERSION) \
|
||||
2>/dev/null || true
|
||||
|
||||
@echo "Removing dangling images..."
|
||||
@echo "Removing dangling build cache/images..."
|
||||
- docker image prune -f
|
||||
- docker builder prune -f
|
||||
|
||||
all: build build-agent build-local
|
||||
|
||||
.PHONY: clean all run .buildinfo build build-local build-agent uboot-tools
|
||||
.PHONY: \
|
||||
all clean dockerclean \
|
||||
.buildinfo ensure-buildx ensure-registry \
|
||||
build build-bin build-crds build-local build-agent \
|
||||
uboot-tools run-agent
|
||||
|
||||
Reference in New Issue
Block a user