diff --git a/buildscripts/build.sh b/buildscripts/build.sh index 21d0cd04..dc804138 100755 --- a/buildscripts/build.sh +++ b/buildscripts/build.sh @@ -88,10 +88,6 @@ XC_ARCH=$(go env GOARCH) # Build! echo "==> Building ${CTLNAME} using $(go version)... " -if [ -n "$IN_NIX_SHELL" ]; then - MAYBE_STATIC="-linkmode external -extldflags -static" -fi - GOOS="${XC_OS}" GOARCH="${XC_ARCH}" output_name=bin/"$PNAME"/"$GOOS"_"$GOARCH"/"$CTLNAME" @@ -99,9 +95,15 @@ output_name=bin/"$PNAME"/"$GOOS"_"$GOARCH"/"$CTLNAME" if [ "$GOOS" = "windows" ]; then output_name+='.exe' fi + +if command -v musl-gcc; then + CC="musl-gcc" +fi + env GOOS="$GOOS" GOARCH="$GOARCH" go build -ldflags \ "-X github.com/openebs/lvm-localpv/pkg/version.GitCommit=${GIT_COMMIT} \ -X main.CtlName='${CTLNAME}' \ + -linkmode external -extldflags -static \ -X github.com/openebs/lvm-localpv/pkg/version.Version=${VERSION} \ -X github.com/openebs/lvm-localpv/pkg/version.VersionMeta=${VERSION_META}" \ -o "$output_name" \ diff --git a/buildscripts/lvm-driver/Dockerfile.buildx b/buildscripts/lvm-driver/Dockerfile.buildx index 1089cb88..41f0be7e 100644 --- a/buildscripts/lvm-driver/Dockerfile.buildx +++ b/buildscripts/lvm-driver/Dockerfile.buildx @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM golang:1.19.9 AS build +FROM golang:1.19.9-alpine AS build ARG BRANCH ARG RELEASE_TAG @@ -31,7 +31,7 @@ ENV GO111MODULE=on \ WORKDIR /go/src/github.com/openebs/lvm-localpv/ -RUN apt-get update && apt-get install -y make git +RUN apk add make git bash gcc musl-dev COPY go.mod go.sum ./ # Get dependencies - will also be cached if we won't change mod/sum @@ -44,7 +44,7 @@ RUN make buildx.csi-driver FROM alpine:3.18.4 RUN apk add --no-cache lvm2 lvm2-extra util-linux device-mapper RUN apk add --no-cache btrfs-progs xfsprogs xfsprogs-extra e2fsprogs e2fsprogs-extra -RUN apk add --no-cache ca-certificates libc6-compat +RUN apk add --no-cache ca-certificates ARG DBUILD_DATE ARG DBUILD_REPO_URL diff --git a/shell.nix b/shell.nix index f7818186..f09eee7d 100644 --- a/shell.nix +++ b/shell.nix @@ -20,6 +20,7 @@ pkgs.mkShell { curl cacert util-linux + musl ] ++ pkgs.lib.optional (builtins.getEnv "IN_NIX_SHELL" == "pure") docker; shellHook = '' export GOPATH=$(pwd)/nix/.go