1# use debian stable as default distribution 2ARG DISTRO=stable 3ARG VENDOR=debian 4 5############################################################################### 6# Prepare apt config and eventually repackage 7FROM ${VENDOR}:${DISTRO} AS tool-builder 8 9ARG DISTRO 10ENV DEBIAN_FRONTEND noninteractive 11 12RUN apt-get -y update && \ 13 apt-get install -y --no-install-recommends ca-certificates 14 15############################################################################### 16# For older distros: Add backports packages needed 17# * debhelper dwz libdebhelper-perl: build tool releate update 18# * lintian: to keep an acceptable recent version 19# * linux-libc-dev: acrn-dm needs >= 4.20 for udmabuf UAPI 20RUN REPOBASE=$(cat /etc/apt/sources.list | grep -v -E '^#' | head -1 | awk '{print $3}') && \ 21 eval $(cat /etc/os-release) && \ 22 if [ -n "${VERSION_CODENAME}" ]; then \ 23 DISTRONAME=${VERSION_CODENAME}; \ 24 else \ 25 DISTRONAME=${REPOBASE}; \ 26 fi && \ 27 case ${DISTRONAME} in \ 28 buster) \ 29 echo "deb https://deb.debian.org/debian ${DISTRONAME}-backports main" > /etc/apt/sources.list.d/${DISTRONAME}-backports.list; \ 30 for p in debhelper dwz libdebhelper-perl lintian linux-libc-dev; do \ 31 (echo "Package: $p"; \ 32 echo "Pin: release a=${DISTRONAME}-backports"; \ 33 echo "Pin-Priority: 900"; \ 34 echo "") >> /etc/apt/preferences.d/pin-${DISTRONAME}-backports; \ 35 done; \ 36 ;; \ 37 focal) \ 38 for p in debhelper dwz libdebhelper-perl lintian; do \ 39 (echo "Package: $p"; \ 40 echo "Pin: release a=${DISTRONAME}-backports"; \ 41 echo "Pin-Priority: 900"; \ 42 echo "") >> /etc/apt/preferences.d/pin-${DISTRONAME}-backports; \ 43 done; \ 44 ;; \ 45 esac 46 47############################################################################### 48# Install packages needed for git buildpackage based build 49RUN apt-get -y update && \ 50 apt-get install -y --no-install-recommends \ 51 build-essential git-buildpackage devscripts dpkg-dev equivs \ 52 lintian sudo apt-utils pristine-tar 53 54 55############################################################################### 56# Repackage packages 57 58# prepare local apt repo for backported packages 59RUN mkdir -p /opt/apt && cd /opt/apt && \ 60 echo "Origin: ACRN Local Build" > .Release.header && \ 61 echo "Label: acrn-local-build" >> .Release.header && \ 62 apt-ftparchive packages . > Packages && \ 63 apt-ftparchive sources . > Sources && \ 64 (cat .Release.header && apt-ftparchive release .) > Release && \ 65 echo "deb [trusted=yes] file:/opt/apt ./" > /etc/apt/sources.list.d/acrn-local.list && \ 66 echo "deb-src [trusted=yes] file:/opt/apt ./" >> /etc/apt/sources.list.d/acrn-local.list && \ 67 touch /etc/apt/preferences.d/pin-acrn 68 69# setup git config for temporary use 70RUN git config --global user.name "ACRN Debian Package Build" && \ 71 git config --global user.email "acrn-dev@lists.projectacrn.org" 72 73# elementpath >=2.5.0 74RUN NEEDEDVERSION="2.5.0"; \ 75 PKGVERSION=$(apt-cache policy python3-elementpath | grep "Candidate:" | awk '{ print $2}'); \ 76 if [ -z "${PKGVERSION}" -o "${NEEDEDVERSION}" != "$(echo ${NEEDEDVERSION}\\n${PKGVERSION} | sort -V | head -n1)" ]; then \ 77 srcpkg="elementpath" && \ 78 url="https://salsa.debian.org/debian/${srcpkg}.git" && \ 79 upstream_tag="upstream/${NEEDEDVERSION}" && \ 80 debian_tag="debian/${NEEDEDVERSION}-1" && \ 81 debian_branch="master" && \ 82 upstream_branch="upstream" && \ 83 mkdir -p /usr/src/${srcpkg} && cd /usr/src/${srcpkg} && \ 84 git init && git remote add origin ${url} && \ 85 git fetch origin --depth 1 refs/tags/${upstream_tag}:refs/tags/${upstream_tag} && \ 86 git fetch origin --depth 1 refs/tags/${debian_tag}:refs/tags/${debian_tag} && \ 87 if git show ${debian_tag}:debian | grep -qw gbp.conf; then \ 88 pristine_tar=$(git show ${debian_tag}:debian/gbp.conf | awk -F "=" '/pristine-tar/ {print $2}' | tr '[:upper:]' '[:lower:]' | xargs); \ 89 if [ "${pristine_tar}" = "true" ]; then \ 90 git fetch origin pristine-tar; git branch -t pristine-tar origin/pristine-tar; \ 91 fi; \ 92 debian_branch=$(git show ${debian_tag}:debian/gbp.conf | awk -F "=" '/debian-branch/ {print $2}' | xargs) && \ 93 if [ -z "${debian_branch}" ]; then \ 94 debian_branch="master"; \ 95 fi; \ 96 upstream_branch=$(git show ${debian_tag}:debian/gbp.conf | awk -F "=" '/upstream-branch/ {print $2}' | xargs) && \ 97 if [ -z "${upstream_branch}" ]; then \ 98 upstream_branch="upstream"; \ 99 fi; \ 100 fi && \ 101 git checkout -b ${upstream_branch} ${upstream_tag} && \ 102 git checkout -b ${debian_branch} ${debian_tag} && \ 103 mk-build-deps --tool='apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends --yes' --install debian/control --remove && \ 104 rm -f $(dpkg-parsechangelog -Ssource)-build-deps_$(dpkg-parsechangelog -Sversion)_*.* && \ 105 DEB_BUILD_OPTIONS="nocheck" gbp buildpackage -F -us -uc && \ 106 for p in $(grep -E '^Package:' debian/control | awk '{print $2}'); do \ 107 echo "Package: $p" >> /etc/apt/preferences.d/pin-acrn; \ 108 echo "Pin: release l=acrn-local-build" >> /etc/apt/preferences.d/pin-acrn; \ 109 echo "Pin-Priority: 900" >> /etc/apt/preferences.d/pin-acrn; \ 110 echo "" >> /etc/apt/preferences.d/pin-acrn; \ 111 done && \ 112 cd /usr/src && \ 113 mv *.deb /opt/apt && \ 114 mv ${srcpkg}_*.dsc /opt/apt && \ 115 mv ${srcpkg}_*.tar.* /opt/apt && \ 116 cd /opt/apt && \ 117 apt-ftparchive packages . > Packages && \ 118 apt-ftparchive sources . > Sources && \ 119 (cat .Release.header && apt-ftparchive release .) > Release && \ 120 apt-get update -y; \ 121 fi 122 123# xmlschema >=1.10.0 124RUN NEEDEDVERSION="1.10.0"; \ 125 PKGVERSION=$(apt-cache policy python3-xmlschema | grep "Candidate:" | awk '{ print $2}'); \ 126 if [ -z "${PKGVERSION}" -o "${NEEDEDVERSION}" != "$(echo ${NEEDEDVERSION}\\n${PKGVERSION} | sort -V | head -n1)" ]; then \ 127 srcpkg="xmlschema" && \ 128 url="https://salsa.debian.org/python-team/packages/python-${srcpkg}.git" && \ 129 upstream_tag="upstream/${NEEDEDVERSION}" && \ 130 debian_tag="debian/${NEEDEDVERSION}-1" && \ 131 debian_branch="master" && \ 132 upstream_branch="upstream" && \ 133 mkdir -p /usr/src/${srcpkg} && cd /usr/src/${srcpkg} && \ 134 git init && git remote add origin ${url} && \ 135 git fetch origin --depth 1 refs/tags/${upstream_tag}:refs/tags/${upstream_tag} && \ 136 git fetch origin --depth 1 refs/tags/${debian_tag}:refs/tags/${debian_tag} && \ 137 if git show ${debian_tag}:debian | grep -qw gbp.conf; then \ 138 pristine_tar=$(git show ${debian_tag}:debian/gbp.conf | awk -F "=" '/pristine-tar/ {print $2}' | tr '[:upper:]' '[:lower:]' | xargs); \ 139 if [ "${pristine_tar}" = "true" ]; then \ 140 git fetch origin pristine-tar; git branch -t pristine-tar origin/pristine-tar; \ 141 fi; \ 142 debian_branch=$(git show ${debian_tag}:debian/gbp.conf | awk -F "=" '/debian-branch/ {print $2}' | xargs) && \ 143 if [ -z "${debian_branch}" ]; then \ 144 debian_branch="master"; \ 145 fi; \ 146 upstream_branch=$(git show ${debian_tag}:debian/gbp.conf | awk -F "=" '/upstream-branch/ {print $2}' | xargs) && \ 147 if [ -z "${upstream_branch}" ]; then \ 148 upstream_branch="upstream"; \ 149 fi; \ 150 fi && \ 151 git checkout -b ${upstream_branch} ${upstream_tag} && \ 152 git checkout -b ${debian_branch} ${debian_tag} && \ 153 mk-build-deps --tool='apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends --yes' --install debian/control --remove && \ 154 rm -f $(dpkg-parsechangelog -Ssource)-build-deps_$(dpkg-parsechangelog -Sversion)_*.* && \ 155 DEB_BUILD_OPTIONS="nocheck" gbp buildpackage -F -us -uc && \ 156 for p in $(grep -E '^Package:' debian/control | awk '{print $2}'); do \ 157 echo "Package: $p" >> /etc/apt/preferences.d/pin-acrn; \ 158 echo "Pin: release l=acrn-local-build" >> /etc/apt/preferences.d/pin-acrn; \ 159 echo "Pin-Priority: 900" >> /etc/apt/preferences.d/pin-acrn; \ 160 echo "" >> /etc/apt/preferences.d/pin-acrn; \ 161 done && \ 162 cd /usr/src && \ 163 mv *.deb /opt/apt && \ 164 mv python-${srcpkg}_*.dsc /opt/apt && \ 165 mv python-${srcpkg}_*.tar.* /opt/apt && \ 166 cd /opt/apt && \ 167 apt-ftparchive packages . > Packages && \ 168 apt-ftparchive sources . > Sources && \ 169 (cat .Release.header && apt-ftparchive release .) > Release && \ 170 apt-get update -y; \ 171 fi 172 173# acpica-unix >= 20200925 174RUN NEEDEDVERSION="20200925"; \ 175 PKGVERSION=$(apt-cache policy acpica-tools | grep "Candidate:" | awk '{ print $2}'); \ 176 if [ -z "${PKGVERSION}" -o "${NEEDEDVERSION}" != "$(echo ${NEEDEDVERSION}\\n${PKGVERSION} | sort -V | head -n1)" ]; then \ 177 srcpkg="acpica-unix" && \ 178 url="https://github.com/ahs3/acpica-tools" && \ 179 upstream_tag="upstream/${NEEDEDVERSION}" && \ 180 debian_tag="debian/${NEEDEDVERSION}-1" && \ 181 debian_branch="master" && \ 182 upstream_branch="upstream" && \ 183 mkdir -p /usr/src/${srcpkg} && cd /usr/src/${srcpkg} && \ 184 git init && git remote add origin ${url} && \ 185 git fetch origin --depth 1 refs/tags/${upstream_tag}:refs/tags/${upstream_tag} && \ 186 git fetch origin --depth 1 refs/tags/${debian_tag}:refs/tags/${debian_tag} && \ 187 if git show ${debian_tag}:debian | grep -qw gbp.conf; then \ 188 pristine_tar=$(git show ${debian_tag}:debian/gbp.conf | awk -F "=" '/pristine-tar/ {print $2}' | tr '[:upper:]' '[:lower:]' | xargs); \ 189 if [ "${pristine_tar}" = "true" ]; then \ 190 git fetch origin pristine-tar; git branch -t pristine-tar origin/pristine-tar; \ 191 fi; \ 192 debian_branch=$(git show ${debian_tag}:debian/gbp.conf | awk -F "=" '/debian-branch/ {print $2}' | xargs) && \ 193 if [ -z "${debian_branch}" ]; then \ 194 debian_branch="master"; \ 195 fi; \ 196 upstream_branch=$(git show ${debian_tag}:debian/gbp.conf | awk -F "=" '/upstream-branch/ {print $2}' | xargs) && \ 197 if [ -z "${upstream_branch}" ]; then \ 198 upstream_branch="upstream"; \ 199 fi; \ 200 fi && \ 201 git checkout -b ${upstream_branch} ${upstream_tag} && \ 202 git checkout -b ${debian_branch} ${debian_tag} && \ 203 mk-build-deps --tool='apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends --yes' --install debian/control --remove && \ 204 rm -f $(dpkg-parsechangelog -Ssource)-build-deps_$(dpkg-parsechangelog -Sversion)_*.* && \ 205 DEB_BUILD_OPTIONS="nocheck" gbp buildpackage -F -us -uc && \ 206 for p in $(grep -E '^Package:' debian/control | awk '{print $2}'); do \ 207 echo "Package: $p" >> /etc/apt/preferences.d/pin-acrn; \ 208 echo "Pin: release l=acrn-local-build" >> /etc/apt/preferences.d/pin-acrn; \ 209 echo "Pin-Priority: 900" >> /etc/apt/preferences.d/pin-acrn; \ 210 echo "" >> /etc/apt/preferences.d/pin-acrn; \ 211 done && \ 212 cd /usr/src && \ 213 mv *.deb /opt/apt && \ 214 mv ${srcpkg}_*.dsc /opt/apt && \ 215 mv ${srcpkg}_*.tar.* /opt/apt && \ 216 cd /opt/apt && \ 217 apt-ftparchive packages . > Packages && \ 218 apt-ftparchive sources . > Sources && \ 219 (cat .Release.header && apt-ftparchive release .) > Release && \ 220 apt-get update -y; \ 221 fi 222 223############################################################################### 224# the final image 225FROM ${VENDOR}:${DISTRO} 226 227ARG VENDOR 228ARG DISTRO 229 230ENV DEBIAN_FRONTEND=noninteractive 231 232RUN apt-get -y update && \ 233 apt-get install -y --no-install-recommends ca-certificates 234 235COPY --from=tool-builder /etc/apt/sources.list.d/* /etc/apt/sources.list.d/ 236COPY --from=tool-builder /etc/apt/preferences.d/* /etc/apt/preferences.d/ 237COPY --from=tool-builder /opt/apt /opt/apt 238 239############################################################################### 240# Install build script requirements 241RUN apt-get -y update && apt-get install -y --no-install-recommends \ 242 devscripts \ 243 equivs \ 244 git-buildpackage \ 245 lintian \ 246 apt-utils \ 247 sudo 248 249############################################################################### 250# pre-install build dependencies 251COPY debian-control-${VENDOR}-${DISTRO} /tmp/debian-control 252RUN tmpdir=$(mktemp -d) && cd ${tmpdir} && \ 253 mk-build-deps --tool='apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends --yes' --install /tmp/debian-control && \ 254 cd / && rm -rf ${tmpdir} 255 256############################################################################### 257# cleanup apt cache 258RUN apt-get clean && rm -rf /var/lib/apt/lists/* 259 260 261############################################################################### 262# Mount the topdir of the Debian git repository at /source 263VOLUME /source/ 264WORKDIR /source/ 265 266############################################################################### 267# Get default settings and helper scripts 268ADD gbp.conf /etc/git-buildpackage/ 269ADD debian-pkg-build.sh /usr/local/bin/debian-pkg-build.sh 270ADD create-apt-repo.sh /usr/local/bin/create-apt-repo.sh 271ADD lintian.sh /usr/local/bin/lintian.sh 272 273