-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13a8cd8
commit 79e636d
Showing
6 changed files
with
101 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,96 @@ | ||
# Makefile for building and pushing Docker images | ||
SHELL := /bin/bash | ||
|
||
# Image URL to use all building/pushing image targets | ||
IMG ?= hobbyfarm/gargantua:dev | ||
SVC ?= usersvc | ||
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion) | ||
CRD_OPTIONS ?= "crd:trivialVersions=true" | ||
# Default values | ||
IMAGE_REGISTRY ?= hobbyfarm | ||
IMAGE_TAG ?= latest | ||
PLATFORMS ?= linux/amd64 | ||
DOCKER_COMMAND ?= $(notdir $(shell command -v docker || command -v podman)) | ||
DOCKER_BUILD_COMMAND ?= buildx build | ||
SERVICE_BASE_PATH ?= $(shell realpath ./v3/services) | ||
SERVICE_DOCKERFILE ?= $(shell realpath ./v3/Dockerfile) | ||
GARGANTUA_DOCKERFILE ?= $(shell realpath ./Dockerfile) | ||
DOCKER_PUSH ?= | ||
SERVICES ?= | ||
|
||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) | ||
ifeq (,$(shell go env GOBIN)) | ||
GOBIN=$(shell go env GOPATH)/bin | ||
ifeq ($(DOCKER_COMMAND),podman) | ||
DOCKER_BUILD_COMMAND := build | ||
PLATFORM_ARG := | ||
else | ||
GOBIN=$(shell go env GOBIN) | ||
PLATFORM_ARG := --platform $(PLATFORMS) | ||
endif | ||
|
||
all: manager | ||
|
||
# Run tests | ||
test: generate fmt vet | ||
go test ./... -coverprofile cover.out | ||
|
||
# Build manager binary | ||
manager: generate fmt vet | ||
go build -o bin/gargantua main.go | ||
|
||
# Run against the configured Kubernetes cluster in ~/.kube/config | ||
run: generate fmt vet | ||
go run ./main.go | ||
# Validate Docker/Podman installation | ||
ifeq ($(DOCKER_COMMAND),) | ||
$(error Neither "docker" nor "podman" exists on the system) | ||
endif | ||
|
||
# Run go fmt against code | ||
fmt: | ||
go fmt ./... | ||
# If no services are specified, get all service directories | ||
ifeq ($(SERVICES),) | ||
SERVICES := gargantua $(shell find $(SERVICE_BASE_PATH) -maxdepth 1 -type d -exec basename {} \; | tail -n +2) | ||
endif | ||
|
||
# Run go vet against code | ||
vet: | ||
go vet ./... | ||
.PHONY: help | ||
help: | ||
@echo "Usage:" | ||
@echo " make docker-setup" | ||
@echo " make docker-build [SERVICES=service1 service2] [IMAGE_TAG=tag] [IMAGE_REGISTRY=registry] [PLATFORMS=os/arch,os/arch] [PUSH=true]" | ||
@echo " make docker-push [SERVICES=service1 service2] [IMAGE_TAG=tag] [IMAGE_REGISTRY=registry] [PLATFORMS=os/arch,os/arch]" | ||
@echo " make generate-client" | ||
@echo " make generate-protos" | ||
@echo " make list-services" | ||
@echo " make help" | ||
@echo "" | ||
@echo "Targets:" | ||
@echo " docker-setup Sets up and configures Docker Buildx for the first time" | ||
@echo " docker-build Build the docker images with multi-platform support" | ||
@echo " docker-push Build and push the docker images with multi-platform support" | ||
@echo " generate-client Generate kubernetes glue code for go" | ||
@echo " generate-protos Generate go code from proto files" | ||
@echo " list-services Prints the available services for building" | ||
@echo " help Prints help" | ||
@echo "" | ||
@echo "Options:" | ||
@echo " SERVICES List of services to build (default: all detected)" | ||
@echo " IMAGE_TAG Tag for the built images (default: latest)" | ||
@echo " IMAGE_REGISTRY Registry for images (default: hobbyfarm)" | ||
@echo " PLATFORMS Comma-separated list of target platforms (default: linux/amd64)" | ||
@echo " PUSH If set to true, push images to the registry (default: false)" | ||
|
||
# Generate code | ||
generate: | ||
.PHONY: generate-client | ||
generate-client: | ||
./generate-client.sh | ||
|
||
# Build the docker image | ||
docker-build: fmt vet | ||
docker build . -t ${IMG} | ||
|
||
# Push the docker image | ||
docker-push: | ||
docker push ${IMG} | ||
.PHONY: generate-protos | ||
generate-protos: | ||
./generate-protos.sh | ||
|
||
build-svc: | ||
docker build -f ./v3/Dockerfile --build-arg SERVICE_NAME=${SVC} -t ${IMG} . | ||
.PHONY: docker-setup | ||
docker-setup: | ||
@if [ "$(DOCKER_COMMAND)" = "docker" ]; then \ | ||
docker buildx create --use --name hobbyfarm || true; \ | ||
docker buildx inspect --bootstrap; \ | ||
fi | ||
|
||
push-svc: build-svc | ||
docker push ${IMG} | ||
.PHONY: docker-build | ||
docker-build: | ||
@for service in $(SERVICES); do \ | ||
if [ "$$service" = "gargantua" ]; then \ | ||
echo "Building gargantua..."; \ | ||
$(DOCKER_COMMAND) $(DOCKER_BUILD_COMMAND) $(if $(PUSH),--push,--load) $(PLATFORM_ARG) --file $(GARGANTUA_DOCKERFILE) --tag $(IMAGE_REGISTRY)/$$service:$(IMAGE_TAG) .; \ | ||
else \ | ||
echo "Building $$service..."; \ | ||
image_tag=$(IMAGE_REGISTRY)/$${service/%svc/-service}:$(IMAGE_TAG); \ | ||
$(DOCKER_COMMAND) $(DOCKER_BUILD_COMMAND) $(if $(PUSH),--push,--load) $(PLATFORM_ARG) --build-arg SERVICE_NAME=$$service --file $(SERVICE_DOCKERFILE) --tag $$image_tag .; \ | ||
fi; \ | ||
done | ||
|
||
build-gargantua: | ||
docker build -t ${IMG} . | ||
.PHONY: docker-push | ||
docker-push: | ||
@make docker-build PUSH=true | ||
|
||
push-gargantua: build-gargantua | ||
docker push ${IMG} | ||
.PHONY: list-services | ||
list-services: | ||
@for service in $(SERVICES); do \ | ||
echo "$$service"; \ | ||
done |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters