fix: Add cross-compilation and fix QEMU ARM64 compatibility
- Added --platform=$BUILDPLATFORM to builder stage for cross-compilation - Added TARGETOS and TARGETARCH build args - Pinned Alpine to 3.19 for better QEMU emulation stability - Split apk add commands to prevent trigger failures under QEMU - Fixes ARM64 build failures in CI/CD pipeline
This commit is contained in:
26
Dockerfile
26
Dockerfile
@@ -1,5 +1,9 @@
|
|||||||
# Multi-stage build for minimal image size
|
# Multi-stage build for minimal image size
|
||||||
FROM golang:1.24-alpine AS builder
|
FROM --platform=$BUILDPLATFORM golang:1.24-alpine AS builder
|
||||||
|
|
||||||
|
# Build arguments for cross-compilation
|
||||||
|
ARG TARGETOS
|
||||||
|
ARG TARGETARCH
|
||||||
|
|
||||||
# Install build dependencies
|
# Install build dependencies
|
||||||
RUN apk add --no-cache git make
|
RUN apk add --no-cache git make
|
||||||
@@ -13,21 +17,21 @@ RUN go mod download
|
|||||||
# Copy source code
|
# Copy source code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Build binary
|
# Build binary with cross-compilation support
|
||||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-w -s" -o dbbackup .
|
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
|
||||||
|
go build -a -installsuffix cgo -ldflags="-w -s" -o dbbackup .
|
||||||
|
|
||||||
# Final stage - minimal runtime image
|
# Final stage - minimal runtime image
|
||||||
|
# Using pinned version 3.19 which has better QEMU compatibility
|
||||||
FROM alpine:3.19
|
FROM alpine:3.19
|
||||||
|
|
||||||
# Install database client tools
|
# Install database client tools
|
||||||
RUN apk add --no-cache \
|
# Split into separate commands for better QEMU compatibility
|
||||||
postgresql-client \
|
RUN apk add --no-cache postgresql-client
|
||||||
mysql-client \
|
RUN apk add --no-cache mysql-client
|
||||||
mariadb-client \
|
RUN apk add --no-cache mariadb-client
|
||||||
pigz \
|
RUN apk add --no-cache pigz pv
|
||||||
pv \
|
RUN apk add --no-cache ca-certificates tzdata
|
||||||
ca-certificates \
|
|
||||||
tzdata
|
|
||||||
|
|
||||||
# Create non-root user
|
# Create non-root user
|
||||||
RUN addgroup -g 1000 dbbackup && \
|
RUN addgroup -g 1000 dbbackup && \
|
||||||
|
|||||||
Reference in New Issue
Block a user