Skip to content

Commit e72b198

Browse files
committed
AVRO-4272: Modernize share/docker/Dockerfile with BuildKit and reduce image size
Use BuildKit cache mounts (--mount=type=cache) for apt, npm, cpanm, and bundler. Eliminates repeated apt-get update/clean cycles, produces smaller layers, and speeds up rebuilds. Use bind mounts for Ruby gem resolution, replacing COPY layers. Add # syntax=docker/dockerfile:1 directive for portability. Replace libboost-all-dev (~70+ sub-packages) with the four Boost packages actually needed by the C++ test suite: libboost-dev, libboost-test-dev, libboost-random-dev, libboost-math-dev. Remove redundant packages provided by build-essential (g++, gcc, make) or by other -dev packages (libsnappy1v5). Remove apt-transport-https (unnecessary on Ubuntu 24.04). Add --no-install-recommends to all apt-get install calls. Add php-zip and unzip (previously pulled as recommends, needed by Composer). Move libbz2-dev and libzstd-dev from PHP section to main packages. Move libyaml-dev from Ruby section to main packages. Remove Rust toolchain (no longer needed). Fix .NET SDK install to use && instead of ; (fail-fast on errors). Convert build-only variables (MAVEN_VERSION, APACHE_DIST_URLS, PHP8_VERSION) from ENV to ARG. Remove dead PIP_NO_CACHE_DIR=off (misleading and moot with uv). Move Ruby bundle install after .NET/Java layers for better cache efficiency. Fix PHP extension build to use /tmp/lang/php (consistent naming, proper cleanup). Requires Docker BuildKit (default builder since Docker 23.0). Assisted-by: GitHub Copilot:claude-opus-4.6
1 parent 840dc81 commit e72b198

3 files changed

Lines changed: 75 additions & 64 deletions

File tree

lang/py/pyproject.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ version = "1.13.0"
2424
requires-python = ">=3.10"
2525
authors = [{name = "Apache Avro", email = "dev@avro.apache.org"}]
2626
keywords = ["avro", "serialization", "rpc"]
27-
license-files = ["LICENSE.txt"]
27+
license = "Apache-2.0"
28+
license-files = ["avro/LICENSE"]
2829
readme = "README.md"
2930
classifiers = [
30-
"License :: OSI Approved :: Apache Software License",
3131
"Programming Language :: Python :: 3.10",
3232
"Programming Language :: Python :: 3.11",
3333
"Programming Language :: Python :: 3.12",
@@ -56,9 +56,12 @@ zstandard = ["zstandard"]
5656
[tool.ruff]
5757
line-length = 150
5858

59+
[tool.setuptools.packages.find]
60+
include = ["avro*"]
61+
5962
[tool.setuptools.package-data]
6063
"avro" = [
61-
"HandshakeRequest.avsc", "HandshakeResponse.avsc", "LICENSE.txt",
64+
"HandshakeRequest.avsc", "HandshakeResponse.avsc", "LICENSE",
6265
"NOTICE", "README.md", "VERSION.txt" ]
6366
"avro.tether" = ["InputProtocol.avpr", "OutputProtocol.avpr"]
6467

lang/py/uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

share/docker/Dockerfile

Lines changed: 68 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1
12
# Licensed to the Apache Software Foundation (ASF) under one
23
# or more contributor license agreements. See the NOTICE file
34
# distributed with this work for additional information
@@ -22,17 +23,17 @@ ARG BUILDPLATFORM
2223
FROM --platform=$BUILDPLATFORM ubuntu:24.04
2324
WORKDIR /root
2425

25-
#ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=isolemnlysweariamuptonogood
2626
ENV DEBIAN_FRONTEND=noninteractive
2727

2828
# Install dependencies from vanilla system packages
29-
RUN apt-get -qqy update \
30-
&& apt-get -qqy install software-properties-common \
29+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
30+
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
31+
apt-get -qqy update \
32+
&& apt-get -qqy install --no-install-recommends software-properties-common \
3133
&& add-apt-repository ppa:deadsnakes/ppa \
3234
&& add-apt-repository ppa:longsleep/golang-backports \
3335
&& apt-get -qqy update \
3436
&& apt-get -qqy install --no-install-recommends ant \
35-
apt-transport-https \
3637
apt-utils \
3738
asciidoc \
3839
bison \
@@ -43,38 +44,41 @@ RUN apt-get -qqy update \
4344
curl \
4445
doxygen \
4546
flex \
46-
g++ \
47-
gcc \
4847
git \
4948
gnupg2 \
5049
golang-go \
5150
hugo \
52-
libboost-all-dev \
51+
libboost-dev \
52+
libboost-math-dev \
53+
libboost-random-dev \
54+
libboost-test-dev \
55+
libbz2-dev \
5356
libfontconfig1-dev \
5457
libfreetype6-dev \
5558
libglib2.0-dev \
5659
libjansson-dev \
5760
libreadline-dev \
5861
libsnappy-dev \
59-
libsnappy1v5 \
6062
libssl-dev \
61-
make \
63+
libyaml-dev \
64+
libzstd-dev \
6265
openjdk-11-jdk \
6366
openjdk-17-jdk \
6467
openjdk-21-jdk \
6568
perl \
6669
source-highlight \
6770
subversion \
71+
tmux \
72+
unzip \
6873
valgrind \
6974
vim \
70-
wget \
71-
&& apt-get -qqy clean
75+
wget
7276

7377
# Install a maven release -------------------------------------------
7478
# Inspired from https://github.com/apache/accumulo-docker/blob/bbb9892e165d40fb35fa19f38929effc5d0c709b/Dockerfile#L30
75-
ENV MAVEN_VERSION=3.9.11
79+
ARG MAVEN_VERSION=3.9.11
7680
# Ideally we use the 1st URL only, but if the version is outdated (or we're grabbing the .asc file), we might have to pull from the dist/archive :/
77-
ENV APACHE_DIST_URLS="https://www.apache.org/dyn/closer.cgi?action=download&filename= \
81+
ARG APACHE_DIST_URLS="https://www.apache.org/dyn/closer.cgi?action=download&filename= \
7882
https://www-us.apache.org/dist/ \
7983
https://www.apache.org/dist/ \
8084
https://archive.apache.org/dist/"
@@ -99,28 +103,29 @@ RUN set -eux; \
99103
ENV PATH="/opt/maven/bin:${PATH}"
100104

101105
# Install nodejs
102-
RUN curl -sSL https://deb.nodesource.com/setup_24.x \
103-
| bash \
104-
&& apt-get -qqy install nodejs \
105-
&& apt-get -qqy clean \
106+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
107+
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
108+
--mount=type=cache,target=/root/.npm \
109+
curl -sSL https://deb.nodesource.com/setup_24.x | bash \
110+
&& apt-get -qqy install --no-install-recommends nodejs \
106111
&& npm install -g grunt-cli \
107-
&& npm install -g browserify \
108-
&& npm cache clean --force
112+
&& npm install -g browserify
109113

110114
# Install PHP
111-
RUN apt-get -qqy install --no-install-recommends libzstd-dev \
112-
libbz2-dev \
113-
php \
115+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
116+
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
117+
apt-get -qqy install --no-install-recommends php \
114118
php-bz2 \
115119
php-curl \
120+
php-dev \
116121
php-gmp \
117-
php-xml \
118122
php-mbstring \
119-
php-dev
123+
php-xml \
124+
php-zip
120125
# Install PHP-snappy and PHP-zstd
121-
ENV PHP8_VERSION=8.3
122-
RUN mkdir -p "/etc/php/${PHP8_VERSION}/cli/conf.d"
123-
RUN mkdir tmp && cd tmp \
126+
ARG PHP8_VERSION=8.3
127+
RUN mkdir -p "/etc/php/${PHP8_VERSION}/cli/conf.d" \
128+
&& mkdir -p /tmp/lang/php && cd /tmp/lang/php \
124129
&& git clone --recursive --depth=1 https://github.com/kjdev/php-ext-zstd.git \
125130
&& cd php-ext-zstd \
126131
&& phpize \
@@ -138,12 +143,14 @@ RUN mkdir tmp && cd tmp \
138143
&& echo "extension=snappy.so" > "/etc/php/${PHP8_VERSION}/cli/conf.d/10-snappy.ini" \
139144
&& cd .. && rm -rf php-ext-snappy \
140145
&& php -m \
141-
&& apt-get -qqy clean
146+
&& rm -rf /tmp/lang/php
142147

143148
RUN curl -sS https://getcomposer.org/installer | php -- --version=2.8.12 --install-dir=/usr/local/bin --filename=composer
144149

145150
# Install Perl modules
146-
RUN apt-get -qqy install --no-install-recommends libcompress-raw-zlib-perl \
151+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
152+
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
153+
apt-get -qqy install --no-install-recommends libcompress-raw-zlib-perl \
147154
libcpan-uploader-perl \
148155
libencode-perl \
149156
libio-string-perl \
@@ -155,18 +162,16 @@ RUN apt-get -qqy install --no-install-recommends libcompress-raw-zlib-perl \
155162
libregexp-common-perl \
156163
libtest-exception-perl \
157164
libtest-pod-perl \
158-
libtry-tiny-perl \
159-
&& apt-get -qqy clean
165+
libtry-tiny-perl
160166

161-
RUN curl -sSL https://cpanmin.us \
167+
RUN --mount=type=cache,target=/root/.cpanm \
168+
curl -sSL https://cpanmin.us \
162169
| perl - --self-upgrade \
163-
&& cpanm --mirror https://www.cpan.org/ install Compress::Zstd \
164-
Module::Install::Repository \
165-
&& rm -rf .cpanm
170+
&& cpanm --mirror https://www.cpan.org/ Compress::Zstd \
171+
Module::Install::Repository
166172

167173
# Install Python3
168-
ENV PATH="${PATH}:/opt/pypy3.11/bin:/opt/pypy3.10/bin" \
169-
PIP_NO_CACHE_DIR=off
174+
ENV PATH="${PATH}:/opt/pypy3.11/bin:/opt/pypy3.10/bin"
170175

171176
# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope
172177
ARG BUILDARCH
@@ -178,46 +183,49 @@ RUN case "${BUILDARCH:?}" in \
178183
&& for url in \
179184
https://downloads.python.org/pypy/pypy3.11-v7.3.20-"$pypyarch".tar.bz2 \
180185
https://downloads.python.org/pypy/pypy3.10-v7.3.19-"$pypyarch".tar.bz2 \
181-
; do curl -fsSL "$url" | tar -xvjpf -; \
186+
; do curl -fsSL "$url" | tar -xjpf -; \
182187
done \
183188
&& ln -s pypy3.11* pypy3.11 && ln -s pypy3.10* pypy3.10
184189

185190
# Note: python3-distutils was removed with Python 3.12; see here for migration advise: https://peps.python.org/pep-0632/#migration-advice
186-
RUN apt-get -qqy install --no-install-recommends mypy \
191+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
192+
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
193+
apt-get -qqy install --no-install-recommends mypy \
187194
python3 \
188195
python3.10 \
189196
python3.11 \
190197
python3.12 \
191198
python3.13 \
192199
python3.14 \
193200
python3.14-dev \
194-
&& apt-get -qqy clean \
195-
&& curl -LsSf https://astral.sh/uv/0.10.4/install.sh | sh
201+
&& curl -LsSf https://astral.sh/uv/0.11.23/install.sh | sh
196202

197203
# Install Ruby
198-
RUN apt-get -qqy install ruby-full \
199-
&& apt-get -qqy clean
200-
RUN mkdir -p /tmp/lang/ruby/lib/avro && mkdir -p /tmp/share
201-
COPY lang/ruby/* /tmp/lang/ruby/
202-
COPY share/VERSION.txt /tmp/share/
203-
RUN gem install bundler --no-document && \
204-
apt-get install -qqy libyaml-dev && \
205-
cd /tmp/lang/ruby && bundle install
206-
207-
# Install Rust
208-
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.73.0
209-
ENV PATH=$PATH:/root/.cargo/bin/:/root/.local/bin
204+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
205+
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
206+
apt-get -qqy install --no-install-recommends ruby ruby-dev
210207

211208
# Install .NET SDK
212-
RUN cd /opt ; \
213-
wget https://dot.net/v1/dotnet-install.sh ; \
214-
bash ./dotnet-install.sh --channel "6.0" --install-dir "/opt/dotnet" ; \
215-
bash ./dotnet-install.sh --channel "7.0" --install-dir "/opt/dotnet" ; \
216-
bash ./dotnet-install.sh --channel "8.0" --install-dir "/opt/dotnet" ;
209+
RUN set -eux && \
210+
wget -nv -O /opt/dotnet-install.sh https://dot.net/v1/dotnet-install.sh && \
211+
bash /opt/dotnet-install.sh --channel "6.0" --install-dir "/opt/dotnet" && \
212+
bash /opt/dotnet-install.sh --channel "7.0" --install-dir "/opt/dotnet" && \
213+
bash /opt/dotnet-install.sh --channel "8.0" --install-dir "/opt/dotnet" && \
214+
rm /opt/dotnet-install.sh
217215

218-
ENV PATH=$PATH:/opt/dotnet
216+
ENV PATH=$PATH:/opt/dotnet:/root/.local/bin
219217

220218
# Since we want the JDK21 as a default, we have to re-prepend it to the PATH.
221-
RUN update-java-alternatives -s "java-1.21.*"
219+
RUN update-java-alternatives -s "java-1.21.*"
220+
221+
# Install Ruby gems
222+
RUN --mount=type=bind,source=lang/ruby/Gemfile,target=/tmp/lang/ruby/Gemfile \
223+
--mount=type=bind,source=lang/ruby/avro.gemspec,target=/tmp/lang/ruby/avro.gemspec \
224+
--mount=type=bind,source=lang/ruby/Manifest,target=/tmp/lang/ruby/Manifest \
225+
--mount=type=bind,source=share/VERSION.txt,target=/tmp/share/VERSION.txt \
226+
--mount=type=cache,target=/usr/local/bundle/cache \
227+
mkdir -p /tmp/lang/ruby/lib/avro && \
228+
gem install bundler --no-document && \
229+
cd /tmp/lang/ruby && bundle install
222230

223231
CMD ["/bin/bash", "-i"]

0 commit comments

Comments
 (0)