diff --git a/source/Dockerfile b/source/Dockerfile index 2f93893..8ae08c9 100644 --- a/source/Dockerfile +++ b/source/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:latest +FROM --platform=$BUILDPLATFORM alpine:latest AS builder # Install build dependencies RUN apk add --no-cache \ @@ -31,4 +31,6 @@ RUN cmake -G Ninja -B build_static -DCMAKE_BUILD_TYPE=Release \ RUN cmake --build build_static -# The resulting binary will be in build_static/dropshell \ No newline at end of file +# Final stage that only contains the binary +FROM scratch AS dropshell +COPY --from=builder /build/build_static/dropshell /dropshell \ No newline at end of file diff --git a/source/build_static.sh b/source/build_static.sh index 6ecafa2..8575951 100755 --- a/source/build_static.sh +++ b/source/build_static.sh @@ -1,11 +1,31 @@ #!/bin/bash -# Build the Docker image -docker build -t dropshell-static-builder . +# Create output directory +mkdir -p output -# Create a container and copy the binary -docker create --name temp-container dropshell-static-builder -docker cp temp-container:/build/build_static/dropshell ./output/dropshell-static -docker rm temp-container +# Create and use a new builder instance +docker buildx create --name multiarch-builder --use || true -echo "Static binary has been created as 'output/dropshell-static'" \ No newline at end of file +# Build for amd64 +docker buildx build --platform linux/amd64 \ + --tag dropshell-static-builder \ + --output type=local,dest=./output/amd64 \ + --target dropshell \ + . + +# Build for arm64 +docker buildx build --platform linux/arm64 \ + --tag dropshell-static-builder \ + --output type=local,dest=./output/arm64 \ + --target dropshell \ + . + +# Move the binaries to the output directory with architecture-specific names +cp output/amd64/dropshell output/dropshell.amd64 +cp output/arm64/dropshell output/dropshell.arm64 + +# Clean up intermediate directories +rm -rf output/amd64 output/arm64 + +echo "Static binaries have been created:" +ls -la output