You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.2 KiB
50 lines
1.2 KiB
# Start with a Go base image
|
|
FROM golang:1.21-bullseye as builder
|
|
|
|
# Install dependencies for cross-compilation
|
|
RUN apt-get update && apt-get install -y \
|
|
gcc-aarch64-linux-gnu \
|
|
libc6-dev-arm64-cross \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Set up working directory
|
|
WORKDIR /app
|
|
|
|
# Copy go.mod and go.sum files first for better caching
|
|
COPY go.mod ./
|
|
# COPY go.sum ./ # Uncomment if you have a go.sum file
|
|
|
|
# Download dependencies
|
|
RUN go mod download
|
|
|
|
# Copy the source code
|
|
COPY . .
|
|
|
|
# Set environment variables for cross-compilation to ARM64 (Raspberry Pi 4)
|
|
ENV GOOS=linux
|
|
ENV GOARCH=arm64
|
|
ENV CC=aarch64-linux-gnu-gcc
|
|
ENV CGO_ENABLED=1
|
|
|
|
# Build the application
|
|
RUN go build -o track-gopher-arm64 ./examples/main.go
|
|
|
|
# Create a minimal runtime image
|
|
FROM arm64v8/debian:bullseye-slim
|
|
|
|
# Install required runtime dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
ca-certificates \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Set up working directory
|
|
WORKDIR /app
|
|
|
|
# Copy the binary from the builder stage
|
|
COPY --from=builder /app/track-gopher-arm64 .
|
|
|
|
# Make the binary executable
|
|
RUN chmod +x ./track-gopher-arm64
|
|
|
|
# Command to run when the container starts
|
|
ENTRYPOINT ["./track-gopher-arm64"] |