Skip to content

Commit

Permalink
Simplify container build GH workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
afritzler committed Feb 20, 2025
1 parent c5f0a01 commit 3d811d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
24 changes: 21 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,33 @@ COPY hack/ hack/
ARG TARGETOS
ARG TARGETARCH

# Install dependencies (including architecture-specific GCC)
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 \
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/*

# Build
# Install ARM64 cross-compiler if needed
RUN if [ "$TARGETARCH" = "arm64" ]; then \
apt-get update && apt-get install -y --no-install-recommends \
gcc-aarch64-linux-gnu g++-aarch64-linux-gnu; \
fi

# Set correct compiler based on architecture
ENV CC="gcc"
ENV CXX="g++"
RUN if [ "$TARGETARCH" = "arm64" ]; then \
export CC="aarch64-linux-gnu-gcc"; \
export CXX="aarch64-linux-gnu-g++"; \
fi

# Build the binary (correctly setting CC and CXX)
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 \
CC=$CC CXX=$CXX 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 \
Expand Down

0 comments on commit 3d811d6

Please sign in to comment.