-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
69 lines (57 loc) · 2.33 KB
/
Copy pathDockerfile
File metadata and controls
69 lines (57 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# syntax=docker/dockerfile:1
ARG GO_VERSION=1.24.0
# ── Builder base images ────────────────────────────────────────────────────────
# amd64: Trixie (native build)
# arm64/arm: RaspiOS (Trixie-based, runs natively via QEMU — no cross-compiler needed for CGO)
FROM debian:trixie-slim AS base-amd64
FROM vascoguita/raspios:arm64 AS base-arm64
FROM vascoguita/raspios:armhf AS base-arm
# ── Builder ───────────────────────────────────────────────────────────────────
ARG TARGETARCH
FROM base-${TARGETARCH} AS builder
ARG GO_VERSION
ARG VERSION=dev
ARG TARGETARCH
ARG TARGETVARIANT
RUN apt-get update && apt-get install -y --no-install-recommends \
wget \
ca-certificates \
gcc \
libc6-dev \
libdiscid-dev \
libgudev-1.0-dev \
libasound2-dev \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
# Install Go for the running architecture.
# For ARM targets, Docker runs the raspios image natively via QEMU binfmt_misc —
# uname -m returns the actual target arch, so no cross-compiler is needed.
RUN set -eux; \
GOARCH=$(case "$(uname -m)" in \
x86_64) echo "amd64" ;; \
aarch64) echo "arm64" ;; \
arm*) echo "armv6l" ;; \
*) uname -m ;; \
esac); \
wget -q "https://go.dev/dl/go${GO_VERSION}.linux-${GOARCH}.tar.gz" -O /tmp/go.tar.gz && \
tar -C /usr/local -xzf /tmp/go.tar.gz && \
rm /tmp/go.tar.gz
ENV PATH="/usr/local/go/bin:$PATH"
ENV GOPATH="/go"
ENV CGO_ENABLED=1
WORKDIR /build
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# GOARM is derived from TARGETVARIANT (v6 → 6, v7 → 7) for 32-bit ARM targets
RUN set -eux; \
if [ "${TARGETARCH}" = "arm" ] && [ -n "${TARGETVARIANT}" ]; then \
export GOARM="${TARGETVARIANT#v}"; \
fi; \
go build \
-ldflags "-s -w -X 'github.com/b0bbywan/go-mpd-discplayer/cmd.AppVersion=${VERSION}'" \
-o mpd-discplayer \
.
# ── Binary export: extracted via --output type=local ─────────────────────────
FROM scratch AS export
COPY --from=builder /build/mpd-discplayer /mpd-discplayer