netboot/Makefile.inc
2019-01-22 21:26:10 -08:00

65 lines
1.3 KiB
Makefile

# -*- mode: makefile-gmake -*-
# Inputs. Invoke from the parent makefile with these options set.
GOARCH:=
BINARY:=
TAG:=
REGISTRY:=
GOCMD:=go
DOCKER_SUDO:=
GITCOMMIT:=
GITBRANCH:=
ifeq ($(GOARCH),)
$(error GOARCH not specified)
endif
ifeq ($(BINARY),)
$(error BINARY not specified)
endif
ifeq ($(TAG),)
$(error TAG not specified)
endif
ifeq ($(REGISTRY),)
$(error REGISTRY not specified)
endif
# Other variables.
GITCOMMIT:=$(shell git describe --dirty --always)
BUILD_DIR:=build/$(GOARCH)/$(BINARY)
DOCKERCMD:=docker
ifneq ($(DOCKER_SUDO),)
DOCKERCMD:=sudo docker
endif
DOCKERFILE_BASE:=alpine:latest
ifneq ($(GOARCH),amd64)
DOCKERFILE_BASE:=$(GOARCH)/alpine:latest
endif
ifeq ($(GOARCH),arm)
DOCKERFILE_BASE:=arm32v6/alpine:latest
endif
ifeq ($(GOARCH),arm64)
DOCKERFILE_BASE:=arm64v8/alpine:latest
endif
.PHONY: push
push: image
$(DOCKERCMD) push $(REGISTRY)/$(BINARY):$(TAG)
.PHONY: image
image: dockerfile binary
$(DOCKERCMD) build -t $(REGISTRY)/$(BINARY):$(TAG) $(BUILD_DIR)
.PHONY: dockerfile
dockerfile: build-dir
perl -pe "s#alpine:latest#$(DOCKERFILE_BASE)#g" ./cmd/$(BINARY)/Dockerfile >$(BUILD_DIR)/Dockerfile
.PHONY: binary
binary: build-dir
GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=$(GOARCH) GOARM=6 \
$(GOCMD) build -o $(BUILD_DIR)/$(BINARY) \
./cmd/$(BINARY)
.PHONY: build-dir
build-dir:
mkdir -p $(BUILD_DIR)