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 61c43b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 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 }}
30 changes: 24 additions & 6 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

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 \
Expand Down

0 comments on commit 61c43b2

Please sign in to comment.