79 lines
2.7 KiB
Makefile
79 lines
2.7 KiB
Makefile
PROJECT_NAME := mycli
|
|
ARCH := linux-amd64
|
|
VERSION := $(shell go run main.go -v)
|
|
BUILD_DIR=build
|
|
IMAGE_NAME=rbehzadan/$(PROJECT_NAME)
|
|
DOCKER_REGISTRY=dcr.behzadan.ir
|
|
BUILD_DIR := build
|
|
|
|
PLATFORMS := linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
|
|
|
|
.PHONY: all run clean
|
|
|
|
build: build-$(ARCH)
|
|
@cp $(BUILD_DIR)/$(PROJECT_NAME)-$(ARCH) $(BUILD_DIR)/$(PROJECT_NAME)
|
|
@cp $(BUILD_DIR)/$(PROJECT_NAME)-$(ARCH) $(BUILD_DIR)/main
|
|
|
|
all: build-linux-amd64 build-linux-arm64 build-linux-arm7 build-linux-arm6 build-win64 build-win32
|
|
|
|
run:
|
|
go run main.go
|
|
|
|
build-linux-amd64:
|
|
@echo "Building for linux-amd64 ..."
|
|
@mkdir -p $(BUILD_DIR)
|
|
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(PROJECT_NAME)-linux-amd64 main.go
|
|
@echo "Build complete!"
|
|
|
|
build-linux-arm64:
|
|
@echo "Building for linux-arm64 ..."
|
|
@mkdir -p $(BUILD_DIR)
|
|
@CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(PROJECT_NAME)-linux-amd64 main.go
|
|
@echo "Build complete!"
|
|
|
|
build-linux-arm7:
|
|
@echo "Building for linux-arm7 ..."
|
|
@mkdir -p $(BUILD_DIR)
|
|
@CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build $(LDFLAGS) -o $(BUILD_DIR)/$(PROJECT_NAME)-linux-arm7 main.go
|
|
@echo "Build complete!"
|
|
|
|
build-linux-arm6:
|
|
@echo "Building for linux-arm6 ..."
|
|
@mkdir -p $(BUILD_DIR)
|
|
@CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build $(LDFLAGS) -o $(BUILD_DIR)/$(PROJECT_NAME)-linux-arm6 main.go
|
|
@echo "Build complete!"
|
|
|
|
build-win64:
|
|
@echo "Building for windows amd64 ..."
|
|
@mkdir -p $(BUILD_DIR)
|
|
@CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(PROJECT_NAME)-win64.exe main.go
|
|
@echo "Build complete!"
|
|
|
|
build-win32:
|
|
@echo "Building for windows x86 ..."
|
|
@mkdir -p $(BUILD_DIR)
|
|
@CGO_ENABLED=0 GOOS=windows GOARCH=386 go build $(LDFLAGS) -o $(BUILD_DIR)/$(PROJECT_NAME)-win32.exe main.go
|
|
@echo "Build complete!"
|
|
|
|
docker: build
|
|
@echo "Building Docker image with tag: ${IMAGE_NAME}:${VERSION}..."
|
|
@docker build -t ${IMAGE_NAME}:${VERSION} .
|
|
@echo "Docker build complete!"
|
|
|
|
docker-push: docker
|
|
@docker tag ${IMAGE_NAME}:${VERSION} ${DOCKER_REGISTRY}/${IMAGE_NAME}:${VERSION}
|
|
@docker push ${DOCKER_REGISTRY}/${IMAGE_NAME}:${VERSION}
|
|
@docker rmi ${DOCKER_REGISTRY}/${IMAGE_NAME}:${VERSION}
|
|
|
|
# TODO: Use docker-buildx to build multi-platform images
|
|
# docker:
|
|
# @echo "Building multi-architecture Docker image with tag: ${IMAGE_NAME}:${VERSION}..."
|
|
# @docker buildx create --driver-opt env.http_proxy=172.17.0.1:8250 --driver-opt env.https_proxy=172.17.0.1:8250 --driver-opt '"env.no_proxy='$no_proxy'"' --use --name mybuilder
|
|
# @docker buildx build --platform ${PLATFORMS} -t ${DOCKER_REGISTRY}/${IMAGE_NAME}:${VERSION} --push .
|
|
# @docker buildx rm mybuilder
|
|
# @echo "Docker build complete!"
|
|
|
|
clean:
|
|
@echo "Cleaning up..."
|
|
@rm -rf ${BUILD_DIR}
|