11# syntax=docker/dockerfile:1.4
22# artifacts: true
33# platforms: linux/amd64,linux/arm64/v8
4- # platforms_pr: linux/amd64
4+ # platforms_pr: linux/amd64,linux/arm64/v8
55# no-cache-filters: sunshine-base,artifacts,sunshine
66ARG BASE=ubuntu
77ARG TAG=22.04
8- FROM ${BASE}:${TAG} AS sunshine-base
8+ ARG DIST=jammy
9+ FROM --platform=$BUILDPLATFORM ${BASE}:${TAG} AS sunshine-base
910
1011ENV DEBIAN_FRONTEND=noninteractive
1112
1213FROM sunshine-base as sunshine-build
1314
15+ # reused args from base
16+ ARG TAG
17+ ENV TAG=${TAG}
18+ ARG DIST
19+ ENV DIST=${DIST}
20+
21+ ARG BUILDPLATFORM
1422ARG TARGETPLATFORM
23+ RUN echo "build_platform: ${BUILDPLATFORM}"
1524RUN echo "target_platform: ${TARGETPLATFORM}"
1625
26+ # args from ci workflow
1727ARG BRANCH
1828ARG BUILD_VERSION
1929ARG COMMIT
@@ -24,47 +34,125 @@ ENV BUILD_VERSION=${BUILD_VERSION}
2434ENV COMMIT=${COMMIT}
2535
2636SHELL ["/bin/bash" , "-o" , "pipefail" , "-c" ]
37+ # setup env
38+ WORKDIR /env
39+ RUN <<_ENV
40+ # !/bin/bash
41+ set -e
42+ case "${BUILDPLATFORM}" in
43+ linux/amd64)
44+ BUILDARCH=amd64
45+ ;;
46+ linux/arm64)
47+ BUILDARCH=arm64
48+ ;;
49+ *)
50+ echo "unsupported platform: ${TARGETPLATFORM}" ;
51+ exit 1
52+ ;;
53+ esac
54+
55+ case "${TARGETPLATFORM}" in
56+ linux/amd64)
57+ PACKAGEARCH=amd64
58+ TARGETARCH=x86_64
59+ ;;
60+ linux/arm64)
61+ PACKAGEARCH=arm64
62+ TARGETARCH=aarch64
63+ ;;
64+ *)
65+ echo "unsupported platform: ${TARGETPLATFORM}" ;
66+ exit 1
67+ ;;
68+ esac
69+
70+ mirror="http://ports.ubuntu.com/ubuntu-ports"
71+ extra_sources=$(cat <<- VAREOF
72+ deb [arch=$PACKAGEARCH] $mirror $DIST main restricted
73+ deb [arch=$PACKAGEARCH] $mirror $DIST-updates main restricted
74+ deb [arch=$PACKAGEARCH] $mirror $DIST universe
75+ deb [arch=$PACKAGEARCH] $mirror $DIST-updates universe
76+ deb [arch=$PACKAGEARCH] $mirror $DIST multiverse
77+ deb [arch=$PACKAGEARCH] $mirror $DIST-updates multiverse
78+ deb [arch=$PACKAGEARCH] $mirror $DIST-backports main restricted universe multiverse
79+ deb [arch=$PACKAGEARCH] $mirror $DIST-security main restricted
80+ deb [arch=$PACKAGEARCH] $mirror $DIST-security universe
81+ deb [arch=$PACKAGEARCH] $mirror $DIST-security multiverse
82+ VAREOF
83+ )
84+
85+ if [[ "${BUILDPLATFORM}" != "${TARGETPLATFORM}" ]]; then
86+ # fix original sources
87+ sed -i -e "s#deb http#deb [arch=$BUILDARCH] http#g" /etc/apt/sources.list
88+ dpkg --add-architecture $PACKAGEARCH
89+
90+ echo "$extra_sources" | tee -a /etc/apt/sources.list
91+ fi
92+
93+ echo PACKAGEARCH=${PACKAGEARCH}; \
94+ echo TARGETARCH=${TARGETARCH}; \
95+ echo TUPLE=${TARGETARCH}-linux-gnu >> ./env
96+ _ENV
97+
2798# install dependencies
2899RUN <<_DEPS
29100# !/bin/bash
30101set -e
31- apt-get update -y
32- apt-get install -y --no-install-recommends \
33- build-essential \
34- cmake=3.22.* \
35- ca-certificates \
36- git \
37- libayatana-appindicator3-dev \
38- libavdevice-dev \
39- libboost-filesystem-dev=1.74.* \
40- libboost-locale-dev=1.74.* \
41- libboost-log-dev=1.74.* \
42- libboost-program-options-dev=1.74.* \
43- libcap-dev \
44- libcurl4-openssl-dev \
45- libdrm-dev \
46- libevdev-dev \
47- libminiupnpc-dev \
48- libnotify-dev \
49- libnuma-dev \
50- libopus-dev \
51- libpulse-dev \
52- libssl-dev \
53- libva-dev \
54- libvdpau-dev \
55- libwayland-dev \
56- libx11-dev \
57- libxcb-shm0-dev \
58- libxcb-xfixes0-dev \
59- libxcb1-dev \
60- libxfixes-dev \
61- libxrandr-dev \
62- libxtst-dev \
63- wget
64- if [[ "${TARGETPLATFORM}" == 'linux/amd64' ]]; then
65- apt-get install -y --no-install-recommends \
66- libmfx-dev
102+
103+ # shellcheck source=/dev/null
104+ source /env/env
105+
106+ # Initialize an array for packages
107+ packages=(
108+ "build-essential"
109+ "cmake=3.22.*"
110+ "ca-certificates"
111+ "git"
112+ "libayatana-appindicator3-dev"
113+ "libavdevice-dev"
114+ "libboost-filesystem-dev=1.74.*"
115+ "libboost-locale-dev=1.74.*"
116+ "libboost-log-dev=1.74.*"
117+ "libboost-program-options-dev=1.74.*"
118+ "libcap-dev"
119+ "libcurl4-openssl-dev"
120+ "libdrm-dev"
121+ "libevdev-dev"
122+ "libminiupnpc-dev"
123+ "libnotify-dev"
124+ "libnuma-dev"
125+ "libopus-dev"
126+ "libpulse-dev"
127+ "libssl-dev"
128+ "libva-dev"
129+ "libvdpau-dev"
130+ "libwayland-dev"
131+ "libx11-dev"
132+ "libxcb-shm0-dev"
133+ "libxcb-xfixes0-dev"
134+ "libxcb1-dev"
135+ "libxfixes-dev"
136+ "libxrandr-dev"
137+ "libxtst-dev"
138+ "wget"
139+ )
140+
141+ # Conditionally include arch specific packages
142+ if [[ "${TARGETARCH}" == 'x86_64' ]]; then
143+ packages+=(
144+ "libmfx-dev"
145+ )
67146fi
147+ if [[ "${BUILDPLATFORM}" != "${TARGETPLATFORM}" ]]; then
148+ packages+=(
149+ "g++-${TUPLE}=4:11.2.*"
150+ "gcc-${TUPLE}=4:11.2.*"
151+ )
152+ fi
153+
154+ apt-get update -y
155+ apt-get install -y --no-install-recommends "${packages[@]}"
68156apt-get clean
69157rm -rf /var/lib/apt/lists/*
70158_DEPS
@@ -91,7 +179,7 @@ RUN <<_INSTALL_CUDA
91179set -e
92180cuda_prefix="https://developer.download.nvidia.com/compute/cuda/"
93181cuda_suffix=""
94- if [[ "${TARGETPLATFORM }" == 'linux/arm64 ' ]]; then
182+ if [[ "${TARGETARCH }" == 'aarch64 ' ]]; then
95183 cuda_suffix="_sbsa"
96184fi
97185url="${cuda_prefix}${CUDA_VERSION}/local_installers/cuda_${CUDA_VERSION}_${CUDA_BUILD}_linux${cuda_suffix}.run"
@@ -117,8 +205,20 @@ set -e
117205# Set Node version
118206source "$HOME/.nvm/nvm.sh"
119207nvm use 20.9.0
208+
209+ # shellcheck source=/dev/null
210+ source /env/env
211+
212+ TOOLCHAIN_OPTION=""
213+ if [[ "${BUILDPLATFORM}" != "${TARGETPLATFORM}" ]]; then
214+ export "CCPREFIX=/usr/bin/${TUPLE}-"
215+
216+ TOOLCHAIN_OPTION="-DCMAKE_TOOLCHAIN_FILE=toolchain-${TUPLE}-debian.cmake"
217+ fi
218+
120219# Actually build
121220cmake \
221+ "$TOOLCHAIN_OPTION" \
122222 -DCMAKE_CUDA_COMPILER:PATH=/build/cuda/bin/nvcc \
123223 -DCMAKE_BUILD_TYPE=Release \
124224 -DCMAKE_INSTALL_PREFIX=/usr \
@@ -139,7 +239,7 @@ ARG TAG
139239ARG TARGETARCH
140240COPY --link --from=sunshine-build /build/sunshine/build/cpack_artifacts/Sunshine.deb /sunshine-${BASE}-${TAG}-${TARGETARCH}.deb
141241
142- FROM sunshine-base as sunshine
242+ FROM ${BASE}:${TAG} as sunshine
143243
144244# copy deb from builder
145245COPY --link --from=artifacts /sunshine*.deb /sunshine.deb
0 commit comments