Skip to content

Commit

Permalink
build: force rebuilding without CGo
Browse files Browse the repository at this point in the history
Disable building with CGo support, so that only native Golang functions
are used. This makes it possible to build the executables in one
container, and run them in a distroless container.

Fore rebuilding all components with `-a` in the `Makefile`, this
prevents including artifacts that may have been built outside the
contains with CGo enabled.

Signed-off-by: Niels de Vos <[email protected]>
  • Loading branch information
nixpanic authored and mergify[bot] committed Jun 27, 2023
1 parent 22b6288 commit fcc6e23
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM quay.io/projectquay/golang:1.20 as builder
# Copy the contents of the repository
ADD . /workspace/go/src/github.com/csi-addons/kubernetes-csi-addons

ENV GOPATH=/workspace/go
ENV GOPATH=/workspace/go CGO_ENABLED=0
WORKDIR /workspace/go/src/github.com/csi-addons/kubernetes-csi-addons

# Build
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ bundle-validate: container-cmd operator-sdk

.PHONY: build
build: generate fmt vet ## Build manager binary.
go build -ldflags '$(LDFLAGS)' -o bin/csi-addons-manager cmd/manager/main.go
go build -ldflags '$(LDFLAGS)' -o bin/csi-addons-sidecar sidecar/main.go
go build -ldflags '$(LDFLAGS)' -o bin/csi-addons ./cmd/csi-addons
go build -ldflags '$(LDFLAGS)' -a -o bin/csi-addons-manager cmd/manager/main.go
go build -ldflags '$(LDFLAGS)' -a -o bin/csi-addons-sidecar sidecar/main.go
go build -ldflags '$(LDFLAGS)' -a -o bin/csi-addons ./cmd/csi-addons

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
Expand Down
2 changes: 1 addition & 1 deletion build/Containerfile.sidecar
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM quay.io/projectquay/golang:1.20 as builder
# Copy the contents of the repository
ADD . /workspace/go/src/github.com/csi-addons/kubernetes-csi-addons

ENV GOPATH=/workspace/go
ENV GOPATH=/workspace/go CGO_ENABLED=0
WORKDIR /workspace/go/src/github.com/csi-addons/kubernetes-csi-addons

# Build the sidecar and csi-addons tool for admin usage and testing
Expand Down

0 comments on commit fcc6e23

Please sign in to comment.