Skip to content

Commit 3d30ad0

Browse files
committed
Makefile: build targets use go build directly
Signed-off-by: Joe Lanford <[email protected]>
1 parent 22afecf commit 3d30ad0

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

.github/workflows/e2e.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ jobs:
1313
steps:
1414

1515
- uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0
1618

1719
- uses: actions/setup-go@v4
1820
with:

.goreleaser.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
env:
2-
- GOPROXY=https://proxy.golang.org|direct
3-
- GO111MODULE=on
4-
- CGO_ENABLED=0
51
before:
62
hooks:
73
- go mod tidy
@@ -10,16 +6,18 @@ builds:
106
- id: operator-controller
117
main: ./cmd/manager/
128
binary: bin/manager
13-
tags: $GO_BUILD_TAGS
9+
asmflags: "{{ .Env.GO_BUILD_ASMFLAGS }}"
10+
gcflags: "{{ .Env.GO_BUILD_GCFLAGS }}"
11+
ldflags: "{{ .Env.GO_BUILD_LDFLAGS }}"
12+
tags:
13+
- "{{ .Env.GO_BUILD_TAGS }}"
1414
goos:
1515
- linux
1616
goarch:
1717
- amd64
1818
- arm64
1919
- ppc64le
2020
- s390x
21-
ldflags:
22-
- -X main.Version={{ .Version }}
2321
dockers:
2422
- image_templates:
2523
- "{{ .Env.IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-amd64"

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ EXPOSE 8080
1111

1212
USER 65532:65532
1313

14-
ENTRYPOINT ["/manager"]
14+
ENTRYPOINT ["/manager"]

Makefile

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# Image URL to use all building/pushing image targets
55
export IMAGE_REPO ?= quay.io/operator-framework/operator-controller
66
export IMAGE_TAG ?= devel
7-
export GO_BUILD_TAGS ?= upstream
87
export CERT_MGR_VERSION ?= v1.9.0
98
export CATALOGD_VERSION ?= v0.2.0
109
export RUKPAK_VERSION=$(shell go list -mod=mod -m -f "{{.Version}}" github.com/operator-framework/rukpak)
@@ -112,17 +111,28 @@ kind-load-test-artifacts: $(KIND) ## Load the e2e testdata container images into
112111

113112
##@ Build
114113

115-
BUILDCMD = sh -c 'mkdir -p $(BUILDBIN) && $(GORELEASER) build ${GORELEASER_ARGS} --single-target -o $(BUILDBIN)/manager'
116-
BUILDDEPS = manifests generate fmt vet $(GORELEASER)
114+
export VERSION ?= $(shell git describe --tags --always --dirty)
115+
export CGO_ENABLED ?= 0
116+
export GO_BUILD_ASMFLAGS ?= all=-trimpath=${PWD}
117+
export GO_BUILD_LDFLAGS ?= -s -w -X $(shell go list -m)/version.Version=$(VERSION)
118+
export GO_BUILD_GCFLAGS ?= all=-trimpath=${PWD}
119+
export GO_BUILD_TAGS ?= upstream
117120

118-
.PHONY: build
119-
build: BUILDBIN = bin
120-
build: $(BUILDDEPS) ## Build manager binary using goreleaser for current GOOS and GOARCH.
121+
BUILDCMD = go build -tags '$(GO_BUILD_TAGS)' -ldflags '$(GO_BUILD_LDFLAGS)' -gcflags '$(GO_BUILD_GCFLAGS)' -asmflags '$(GO_BUILD_ASMFLAGS)' -o $(BUILDBIN)/manager ./cmd/manager
122+
123+
.PHONY: build-deps
124+
build-deps: manifests generate fmt vet
125+
126+
.PHONY: build go-build-local
127+
build: build-deps go-build-local ## Build manager binary for current GOOS and GOARCH.
128+
go-build-local: BUILDBIN = bin
129+
go-build-local:
121130
$(BUILDCMD)
122131

123-
.PHONY: build-linux
124-
build-linux: BUILDBIN = bin/linux
125-
build-linux: $(BUILDDEPS) ## Build manager binary using goreleaser for GOOS=linux and local GOARCH.
132+
.PHONY: build-linux go-build-linux
133+
build-linux: build-deps go-build-linux ## Build manager binary for GOOS=linux and local GOARCH.
134+
go-build-linux: BUILDBIN = bin/linux
135+
go-build-linux:
126136
GOOS=linux $(BUILDCMD)
127137

128138
.PHONY: run
@@ -143,7 +153,6 @@ docker-build: build-linux ## Build docker image for operator-controller with GOO
143153
##@ Release:
144154
export ENABLE_RELEASE_PIPELINE ?= false
145155
export GORELEASER_ARGS ?= --snapshot --clean
146-
export VERSION ?= $(shell git describe --abbrev=0 --tags)
147156

148157
release: $(GORELEASER) ## Runs goreleaser for the operator-controller. By default, this will run only as a snapshot and will not publish any artifacts unless it is run with different arguments. To override the arguments, run with "GORELEASER_ARGS=...". When run as a github action from a tag, this target will publish a full release.
149158
$(GORELEASER) $(GORELEASER_ARGS)

0 commit comments

Comments
 (0)