diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml index 6ee0eb96..bee52d90 100644 --- a/.github/workflows/publish-docker.yml +++ b/.github/workflows/publish-docker.yml @@ -67,8 +67,8 @@ jobs: uses: docker/build-push-action@v6 with: context: . - platforms: linux/amd64, linux/arm64 + platforms: linux/amd64 ,linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - target: ${{ matrix.image.target }} + target: ${{ matrix.image.target }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 07f23cca..c1f89f71 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,15 +20,33 @@ COPY hack/ hack/ ARG TARGETOS ARG TARGETARCH -RUN apt-get update && apt-get install -y --no-install-recommends \ - qemu-utils ca-certificates libvirt-clients libcephfs-dev librbd-dev librados-dev libc-bin gcc \ - && update-ca-certificates \ - && rm -rf /var/lib/apt/lists/* +# Install AMD64 dependencies +RUN if [ "$TARGETARCH" = "amd64" ]; then \ + apt-get update && apt-get install -y --no-install-recommends \ + qemu-user-static qemu-utils ca-certificates \ + libvirt-clients libcephfs-dev librbd-dev librados-dev libc-bin \ + gcc g++ \ + && update-ca-certificates \ + && rm -rf /var/lib/apt/lists/*; \ + fi -# Build +# Install ARM64 dependencies +RUN if [ "$TARGETARCH" = "arm64" ]; then \ + apt remove -y --allow-remove-essential libc-bin && \ + dpkg --add-architecture arm64 && \ + apt-get update && apt-get install -y --no-install-recommends \ + gcc-aarch64-linux-gnu g++-aarch64-linux-gnu librbd-dev:arm64 librados-dev:arm64 libc-bin:arm64 \ + && rm -rf /var/lib/apt/lists/*; \ + fi + +# Build the binary with the necessary flags RUN --mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/go/pkg \ - CGO_ENABLED=1 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o libvirt-provider ./cmd/libvirt-provider/main.go + CGO_ENABLED=1 GOOS=$TARGETOS GOARCH=$TARGETARCH \ + CGO_LDFLAGS=$(if [ "$TARGETARCH" = "arm64" ]; then echo "-L/usr/lib/aarch64-linux-gnu -Wl, -lrados -lrbd -lpthread -ldl -lresolv"; fi) \ + CC=$(if [ "$TARGETARCH" = "arm64" ]; then echo "aarch64-linux-gnu-gcc"; else echo "gcc"; fi) \ + CXX=$(if [ "$TARGETARCH" = "arm64" ]; then echo "aarch64-linux-gnu-g++"; else echo "g++"; fi) \ + go build -ldflags="-s -w" -o libvirt-provider ./cmd/libvirt-provider/main.go # Install irictl-machine RUN --mount=type=cache,target=/root/.cache/go-build \