Removed go dependency on make
This commit is contained in:
@@ -55,8 +55,6 @@ Prerequisites
|
|||||||
* make
|
* make
|
||||||
* Docker
|
* Docker
|
||||||
* curl (downloading dependency packages, kubelet, crio, etc)
|
* curl (downloading dependency packages, kubelet, crio, etc)
|
||||||
* go (building clitools, control-agent)
|
|
||||||
* controller-gen (see [clitools readme](clitools/README.md))
|
|
||||||
* git (cloning uboot repo because uboot does not provide direct downloads)
|
* git (cloning uboot repo because uboot does not provide direct downloads)
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
14
clitools/docker/crdgen.Dockerfile
Normal file
14
clitools/docker/crdgen.Dockerfile
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
ARG BASE_IMAGE=localhost/monok8s/ctl-build-base:dev
|
||||||
|
FROM ${BASE_IMAGE} AS build
|
||||||
|
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
RUN GOBIN=/usr/local/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.20.1
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN mkdir -p /out && \
|
||||||
|
controller-gen crd paths=./pkg/apis/... output:crd:dir=/out
|
||||||
|
|
||||||
|
FROM scratch
|
||||||
|
COPY --from=build /out/ /
|
||||||
8
clitools/docker/ctl-build-base.Dockerfile
Normal file
8
clitools/docker/ctl-build-base.Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
FROM golang:1.26-alpine
|
||||||
|
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
RUN apk add --no-cache git build-base
|
||||||
|
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
24
clitools/docker/ctl-builder-local.Dockerfile
Normal file
24
clitools/docker/ctl-builder-local.Dockerfile
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
FROM golang:1.26-alpine AS build
|
||||||
|
|
||||||
|
ARG VERSION
|
||||||
|
ARG KUBE_VERSION
|
||||||
|
ARG GIT_REV=unknown
|
||||||
|
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
RUN apk add --no-cache git build-base
|
||||||
|
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN test -f pkg/buildinfo/buildinfo_gen.go
|
||||||
|
|
||||||
|
RUN mkdir -p /out && \
|
||||||
|
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 \
|
||||||
|
go build -trimpath -ldflags="-s -w" \
|
||||||
|
-o /out/ctl-${VERSION} ./cmd/ctl
|
||||||
|
|
||||||
|
FROM scratch
|
||||||
|
COPY --from=build /out/ /
|
||||||
20
clitools/docker/ctl-builder.Dockerfile
Normal file
20
clitools/docker/ctl-builder.Dockerfile
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
ARG BASE_IMAGE=localhost/monok8s/ctl-build-base:dev
|
||||||
|
FROM ${BASE_IMAGE} AS build
|
||||||
|
|
||||||
|
ARG VERSION=dev
|
||||||
|
ARG TARGETOS=linux
|
||||||
|
ARG TARGETARCH=arm64
|
||||||
|
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN test -f pkg/buildinfo/buildinfo_gen.go
|
||||||
|
|
||||||
|
RUN mkdir -p /out && \
|
||||||
|
GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 \
|
||||||
|
go build -trimpath -ldflags="-s -w" \
|
||||||
|
-o /out/ctl-linux-aarch64-${VERSION} ./cmd/ctl
|
||||||
|
|
||||||
|
FROM scratch
|
||||||
|
COPY --from=build /out/ /
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
module example.com/monok8s
|
module example.com/monok8s
|
||||||
|
|
||||||
go 1.24.0
|
go 1.26.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/klauspost/compress v1.18.5
|
github.com/klauspost/compress v1.18.5
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
include ../build.env
|
include ../build.env
|
||||||
|
|
||||||
|
BUILD_PLATFORM ?= linux/amd64
|
||||||
|
|
||||||
# Should be the same as upstream version in production
|
# Should be the same as upstream version in production
|
||||||
VERSION ?= dev
|
VERSION ?= dev
|
||||||
UBOOT_VERSION=v2026.01
|
UBOOT_VERSION ?= v2026.01
|
||||||
|
|
||||||
# Target kube version
|
# Target kube version
|
||||||
KUBE_VERSION ?= v1.33.3
|
KUBE_VERSION ?= v1.33.3
|
||||||
@@ -13,15 +15,28 @@ PACKAGES_DIR := packages
|
|||||||
BIN_DIR := bin
|
BIN_DIR := bin
|
||||||
OUT_DIR := out
|
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
|
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):
|
$(PACKAGES_DIR):
|
||||||
mkdir -p $@
|
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:
|
.buildinfo:
|
||||||
@mkdir -p $(dir $(BUILDINFO_FILE))
|
@mkdir -p $(dir $(BUILDINFO_FILE))
|
||||||
@printf '%s\n' \
|
@printf '%s\n' \
|
||||||
@@ -35,11 +50,41 @@ $(PACKAGES_DIR):
|
|||||||
')' \
|
')' \
|
||||||
> $(BUILDINFO_FILE)
|
> $(BUILDINFO_FILE)
|
||||||
|
|
||||||
$(UBOOT_TAR): | $(PACKAGES_DIR)
|
ensure-buildx:
|
||||||
git clone --depth 1 --branch v2026.01 --filter=blob:none https://github.com/u-boot/u-boot.git $(OUT_DIR)/u-boot-$(UBOOT_VERSION)
|
@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 "$@" .
|
tar -C "$(OUT_DIR)/u-boot-$(UBOOT_VERSION)" -zcf "$@" .
|
||||||
rm -rf $(OUT_DIR)/u-boot-$(UBOOT_VERSION)
|
rm -rf "$(OUT_DIR)/u-boot-$(UBOOT_VERSION)"
|
||||||
test -f $@
|
test -f "$@"
|
||||||
|
|
||||||
uboot-tools: $(UBOOT_TAR)
|
uboot-tools: $(UBOOT_TAR)
|
||||||
docker buildx build --platform linux/arm64 \
|
docker buildx build --platform linux/arm64 \
|
||||||
@@ -48,40 +93,78 @@ uboot-tools: $(UBOOT_TAR)
|
|||||||
--build-arg UBOOT_TAR=$(UBOOT_TAR) \
|
--build-arg UBOOT_TAR=$(UBOOT_TAR) \
|
||||||
--output type=local,dest=./$(OUT_DIR) .
|
--output type=local,dest=./$(OUT_DIR) .
|
||||||
|
|
||||||
build: .buildinfo
|
ctl-build-base: ensure-buildx ensure-registry
|
||||||
mkdir -p $(BIN_DIR) $(OUT_DIR)/crds
|
docker buildx build \
|
||||||
controller-gen crd paths=$(CRD_PATHS) output:crd:dir=$(OUT_DIR)/crds
|
--platform linux/amd64,linux/arm64 \
|
||||||
GOOS=linux GOARCH=arm64 go build -o $(BIN_DIR)/ctl-linux-aarch64-$(VERSION) ./cmd/ctl
|
-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
|
build-agent: build uboot-tools
|
||||||
docker build \
|
docker buildx build \
|
||||||
|
--platform linux/arm64 \
|
||||||
-f docker/ctl-agent.Dockerfile \
|
-f docker/ctl-agent.Dockerfile \
|
||||||
--platform=linux/arm64 \
|
|
||||||
--build-arg VERSION=$(VERSION) \
|
--build-arg VERSION=$(VERSION) \
|
||||||
|
--load \
|
||||||
-t localhost/monok8s/control-agent:$(VERSION) .
|
-t localhost/monok8s/control-agent:$(VERSION) .
|
||||||
|
|
||||||
build-local: .buildinfo
|
build-local: .buildinfo | $(BIN_DIR)
|
||||||
mkdir -p $(BIN_DIR)
|
docker buildx build \
|
||||||
go build -o $(BIN_DIR)/ctl-$(VERSION) ./cmd/ctl
|
-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:
|
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:
|
clean:
|
||||||
-docker image rm localhost/monok8s/control-agent:$(VERSION)
|
-docker image rm localhost/monok8s/control-agent:$(VERSION) >/dev/null 2>&1 || true
|
||||||
rm -rf $(BIN_DIR) \
|
rm -rf \
|
||||||
$(BUILDINFO_FILE) \
|
$(BIN_DIR) \
|
||||||
$(OUT_DIR)/crds
|
$(OUT_DIR)/crds \
|
||||||
|
$(BUILDINFO_FILE)
|
||||||
|
|
||||||
dockerclean:
|
dockerclean:
|
||||||
@echo "Removing tagged images..."
|
@echo "Removing tagged images..."
|
||||||
- docker rmi \
|
- docker rmi \
|
||||||
localhost/monok8s/control-agent:$(VERSION) \
|
localhost/monok8s/control-agent:$(VERSION) \
|
||||||
|
localhost/monok8s/ctl-builder:$(VERSION) \
|
||||||
|
localhost/monok8s/crdgen:$(VERSION) \
|
||||||
2>/dev/null || true
|
2>/dev/null || true
|
||||||
|
|
||||||
@echo "Removing dangling images..."
|
@echo "Removing dangling build cache/images..."
|
||||||
- docker image prune -f
|
- docker image prune -f
|
||||||
|
- docker builder prune -f
|
||||||
|
|
||||||
all: build build-agent build-local
|
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