Skip to content

Commit

Permalink
build: Various build system improvements (#1074)
Browse files Browse the repository at this point in the history
Reviewed-by: Cezar Craciunoiu <[email protected]>
Approved-by: Cezar Craciunoiu <[email protected]>
  • Loading branch information
craciunoiuc authored Dec 9, 2023
2 parents b9cb746 + a052100 commit d4dd2fa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
26 changes: 23 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ GOMOD ?= kraftkit.sh
IMAGE_TAG ?= latest
GO_VERSION ?= 1.21

# Add a special version tag for pull requests
ifneq ($(shell grep 'refs/pull' $(WORKDIR)/.git/FETCH_HEAD),)
HASH_COMMIT ?= HEAD
HASH += pr-$(shell cat $(WORKDIR)/.git/FETCH_HEAD | awk -F/ '{print $$3}')
endif

# Calculate the project version based on git history
ifeq ($(HASH),)
HASH_COMMIT ?= HEAD
HASH ?= $(shell git update-index -q --refresh && \
Expand Down Expand Up @@ -98,7 +105,7 @@ ifneq ($(DOCKER_RUN),)
.PROXY := docker-proxy-
$(BIN): ENVIRONMENT ?= myself-full
$(BIN):
$(info Running target via Docker...)
$(info Running target via $(DOCKER)...)
$(Q)$(call DOCKER_RUN,,$(ENVIRONMENT),$(MAKE) GOOS=$(GOOS) GOARCH=$(GOARCH) -e $@)
$(Q)exit 0
endif
Expand Down Expand Up @@ -130,12 +137,25 @@ $(addprefix $(.PROXY), $(BIN)):
.PHONY: tools
tools: $(TOOLS)

ifeq ($(DEBUG),y)
$(addprefix $(.PROXY), $(TOOLS)): GO_GCFLAGS ?= -N -l
else
$(addprefix $(.PROXY), $(TOOLS)): GO_LDFLAGS ?= -s -w
endif
$(addprefix $(.PROXY), $(TOOLS)): GO_LDFLAGS += -X "$(GOMOD)/internal/version.version=$(VERSION)"
$(addprefix $(.PROXY), $(TOOLS)): GO_LDFLAGS += -X "$(GOMOD)/internal/version.commit=$(GIT_SHA)"
$(addprefix $(.PROXY), $(TOOLS)): GO_LDFLAGS += -X "$(GOMOD)/internal/version.buildTime=$(shell date)"
$(addprefix $(.PROXY), $(TOOLS)):
cd $(WORKDIR)/tools/$@ && $(GO) build -o $(DISTDIR)/$@ . && cd $(WORKDIR)
(cd $(WORKDIR)/tools/$@ && \
$(GO) build -v \
-o $(DISTDIR)/$@ \
-gcflags=all='$(GO_GCFLAGS)' \
-ldflags='$(GO_LDFLAGS)' \
./...)

# Proxy all "build environment" (buildenvs) targets
buildenv-%:
$(MAKE) -C $(WORKDIR)/buildenvs $*
$(MAKE) -C $(WORKDIR)/buildenvs $*

# Run an environment where we can build
.PHONY: devenv
Expand Down
8 changes: 3 additions & 5 deletions buildenvs/github-action.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ FROM golang:${GO_VERSION}-bullseye AS build

COPY . /go/src/kraftkit.sh

WORKDIR /go/src/kraftkit.sh/tools/github-action
WORKDIR /go/src/kraftkit.sh

ENV GOROOT=/usr/local/go

RUN set -xe; \
git config \
--global \
--add safe.directory /go/src/kraftkit.sh/tools/github-action; \
go build \
-o /github-action \
-a;
--add safe.directory /go/src/kraftkit.sh; \
DOCKER= DISTDIR=/ make github-action;

FROM ${REGISTRY}/qemu:${QEMU_VERSION} AS qemu
FROM ${REGISTRY}/myself:${KRAFTKIT_VERSION} AS kraftkit
Expand Down

0 comments on commit d4dd2fa

Please sign in to comment.