|
1 | | -FROM --platform=linux/amd64 docker.io/golang:1.22.2-bullseye |
| 1 | +FROM --platform=linux/amd64 docker.io/golang:1.22.2 |
2 | 2 |
|
3 | | -ENV COMMIT=dev |
4 | | -ENV VERSION=0.0.0 |
| 3 | +# Build tools |
| 4 | +RUN apt-get update && apt-get install -y zip autoconf autopoint libtool |
5 | 5 |
|
6 | | -# Preparations |
7 | | -RUN apt-get update && apt-get install -y wget build-essential |
8 | | - |
9 | | -# Download and extract dependency sources |
10 | | -RUN cd /tmp && \ |
11 | | - wget http://www.alsa-project.org/files/pub/lib/alsa-lib-1.2.10.tar.bz2 && \ |
12 | | - tar -xvf alsa-lib-1.2.10.tar.bz2 |
13 | | -RUN cd /tmp && \ |
14 | | - wget https://downloads.xiph.org/releases/ogg/libogg-1.3.5.tar.xz && \ |
15 | | - tar -xvf libogg-1.3.5.tar.xz |
16 | | -RUN cd /tmp && \ |
17 | | - wget https://downloads.xiph.org/releases/vorbis/libvorbis-1.3.7.tar.xz && \ |
18 | | - tar -xvf libvorbis-1.3.7.tar.xz |
19 | | - |
20 | | -# Depencies arguments |
| 6 | +# Install toolchain |
21 | 7 | ARG TARGET |
22 | | -ARG CC |
23 | | - |
24 | | -# Install toolchain for anything besides arm-rpi-linux-gnueabihf |
25 | | -RUN if [ ${TARGET} != arm-rpi-linux-gnueabihf ]; then \ |
26 | | - apt-get install -y gcc-${TARGET} ; \ |
27 | | - fi |
28 | | - |
29 | | -# Install custom toolchain for arm-rpi-linux-gnueabihf |
30 | | -RUN if [ ${TARGET} = arm-rpi-linux-gnueabihf ]; then \ |
| 8 | +RUN if [ "$TARGET" = "arm-rpi-linux-gnueabihf" ]; then \ |
31 | 9 | cd /tmp && \ |
32 | 10 | wget https://github.com/devgianlu/rpi-toolchain/releases/download/v1/arm-rpi-linux-gnueabihf.tar.gz && \ |
33 | 11 | tar -C /usr --strip-components=1 -xzf arm-rpi-linux-gnueabihf.tar.gz ; \ |
| 12 | + else \ |
| 13 | + apt-get install -y "gcc-$TARGET" ; \ |
34 | 14 | fi |
35 | 15 |
|
36 | | -# Compile dependency sources |
37 | | -RUN cd /tmp/alsa-lib-1.2.10 && \ |
38 | | - ./configure --enable-shared=yes --enable-static=no --with-pic --host=${TARGET} --prefix=/tmp/deps/${TARGET} && \ |
39 | | - make -j $(nproc) && make install |
40 | | -RUN cd /tmp/libogg-1.3.5 && \ |
41 | | - ./configure --host=${TARGET} --prefix=/tmp/deps/${TARGET} && \ |
42 | | - make -j $(nproc) && make install |
43 | | -RUN cd /tmp/libvorbis-1.3.7 && \ |
44 | | - ./configure --host=${TARGET} --prefix=/tmp/deps/${TARGET} && \ |
45 | | - make -j $(nproc) && make install |
46 | | - |
47 | | -# Golang arguments |
| 16 | +# Move to build directory |
| 17 | +WORKDIR /build |
| 18 | + |
| 19 | +# Setup vcpkg |
| 20 | +ADD https://github.com/microsoft/vcpkg.git#2025.09.17 vcpkg |
| 21 | +RUN cd vcpkg && ./bootstrap-vcpkg.sh |
| 22 | +ENV VCPKG_ROOT=/build/vcpkg |
| 23 | +ENV PATH="$VCPKG_ROOT:$PATH" |
| 24 | + |
| 25 | +# Compile dependencies |
| 26 | +ARG TRIPLET |
| 27 | +COPY vcpkg.json vcpkg-configuration.json ./ |
| 28 | +COPY vcpkg-triplets ./vcpkg-triplets |
| 29 | +RUN --mount=type=cache,target=/build/vcpkg/downloads \ |
| 30 | + --mount=type=cache,target=/build/vcpkg/buildtrees \ |
| 31 | + vcpkg install --triplet "$TRIPLET" |
| 32 | + |
| 33 | +# Go compilation setup |
| 34 | +ARG GOCC |
48 | 35 | ARG GOARCH |
49 | 36 | ARG GOAMD64 |
50 | 37 | ARG GOARM |
51 | 38 |
|
52 | | -# Compile |
53 | 39 | WORKDIR /src |
54 | | -ENV CGO_ENABLED=1 PKG_CONFIG_PATH=/tmp/deps/${TARGET}/lib/pkgconfig/ CC=${CC} \ |
55 | | - GOARCH=${GOARCH} GOAMD64=${GOAMD64} GOARM=${GOARM} GOOUTSUFFIX='' \ |
| 40 | +ENV CGO_ENABLED=1 PKG_CONFIG_PATH="/build/vcpkg_installed/$TRIPLET/lib/pkgconfig" CC="$GOCC" \ |
| 41 | + GOARCH="$GOARCH" GOAMD64="$GOAMD64" GOARM="$GOARM" \ |
56 | 42 | GOCACHE=/src/.gocache/go-build GOMODCACHE=/src/.gocache/mod |
57 | | -CMD go build \ |
58 | | - -buildvcs=false \ |
59 | | - -ldflags="-X github.com/devgianlu/go-librespot.commit=${COMMIT} -X github.com/devgianlu/go-librespot.version=${VERSION}" \ |
60 | | - -o ./go-librespot${GOOUTSUFFIX} -a ./cmd/daemon |
| 43 | +CMD ["go", "build", "-o", "./go-librespot", "-a", "-ldflags", "-s -w", "./cmd/daemon"] |
0 commit comments