Skip to content

Commit

Permalink
fix: add cross build in build script and docker
Browse files Browse the repository at this point in the history
  • Loading branch information
orangedeng committed Oct 18, 2024
1 parent 2b6bd9b commit c1d6a98
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion package/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
FROM registry.suse.com/bci/bci-base:15.5
ARG TARGETPLATFORM
ENV TARGETPATH=${TARGETPLATFORM:-"."}
RUN zypper -n update && \
zypper -n clean -a && \
rm -rf /tmp/* /var/tmp/* /usr/share/doc/packages/*
RUN useradd --uid 1007 tke-operator
ENV KUBECONFIG /home/tke-operator/.kube/config
ENV SSL_CERT_DIR /etc/rancher/ssl

COPY bin/tke-operator /usr/bin/
COPY bin/${TARGETPATH}/tke-operator /usr/bin/
COPY package/entrypoint.sh /usr/bin
RUN chmod +x /usr/bin/entrypoint.sh

Expand Down
14 changes: 13 additions & 1 deletion scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,16 @@ mkdir -p bin
if [ "$(uname)" = "Linux" ]; then
OTHER_LINKFLAGS="-extldflags -static -s"
fi
CGO_ENABLED=0 go build -ldflags "$OTHER_LINKFLAGS" -o bin/tke-operator
CGO_ENABLED=0 go build -ldflags "$OTHER_LINKFLAGS" -o bin/tke-operator

if [ -n "$CROSS" ]; then
for platform in linux/amd64 linux/arm64; do
os="${platform%/*}"
arch="${platform#*/}"
FLAGS="$LINKFLAGS"
[ "$os" = "linux" ] && FLAGS="-extldflags -static -s $FLAGS"
echo "building $os $arch binary"
mkdir -p bin/$os/$arch
GOOS=$os GOARCH=$arch go build -ldflags "$FLAGS" -o bin/$os/$arch/tke-operator
done
fi

0 comments on commit c1d6a98

Please sign in to comment.