Skip to content

Commit f037d93

Browse files
committed
Dockerfile: Maintenance
Improve build/push/pull speed by reducing the layers sizes
1 parent 73aa02f commit f037d93

File tree

5 files changed

+55
-75
lines changed

5 files changed

+55
-75
lines changed

.containerversion

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
42
1+
43

Dockerfile

+51-72
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,23 @@
1919
# $ docker run --privileged --rm tonistiigi/binfmt --install arm64
2020

2121
FROM ubuntu:22.04
22-
ENV DEBIAN_FRONTEND noninteractive
2322

2423
# These are automatically provided by docker (no need for --build-arg)
2524
ARG TARGETPLATFORM
2625
ARG TARGETARCH
2726

28-
RUN apt-get update && apt-get upgrade -y && apt-get install -y wget nano rsync curl gnupg2 jq unzip bzip2 xz-utils
27+
RUN export DEBIAN_FRONTEND=noninteractive; \
28+
apt-get update && \
29+
apt-get upgrade -y && \
30+
apt-get install -y wget nano rsync curl gnupg2 jq unzip bzip2 xz-utils && \
31+
rm -rf /var/lib/apt/lists/*
32+
2933

30-
# for clang-*-15, see https://apt.llvm.org/
3134
RUN echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" >> /etc/apt/sources.list && \
3235
echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" >> /etc/apt/sources.list && \
33-
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
36+
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \
37+
rm /root/.wget-hsts
3438

35-
# Install gcc8-arm-none-eabi
3639
RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
3740
GNU_TOOLCHAIN=https://developer.arm.com/-/media/Files/downloads/gnu/13.3.rel1/binrel/arm-gnu-toolchain-13.3.rel1-aarch64-arm-none-eabi.tar.xz \
3841
GNU_TOOLCHAIN_HASH=c8824bffd057afce2259f7618254e840715f33523a3d4e4294f471208f976764 \
@@ -42,13 +45,13 @@ RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
4245
GNU_TOOLCHAIN_HASH=fb31fbdfe08406ece43eef5df623c0b2deb8b53e405e2c878300f7a1f303ee52 \
4346
GNU_TOOLCHAIN_FORMAT=bz2; \
4447
fi; \
45-
wget -O gcc.tar.${GNU_TOOLCHAIN_FORMAT} ${GNU_TOOLCHAIN} &&\
46-
echo "$GNU_TOOLCHAIN_HASH gcc.tar.${GNU_TOOLCHAIN_FORMAT}" | sha256sum -c &&\
47-
tar -xvf gcc.tar.${GNU_TOOLCHAIN_FORMAT} -C /usr/local --strip-components=1 &&\
48-
rm -f gcc.tar.${GNU_TOOLCHAIN_FORMAT}
48+
wget -O gcc.tar.${GNU_TOOLCHAIN_FORMAT} ${GNU_TOOLCHAIN} && \
49+
echo "$GNU_TOOLCHAIN_HASH gcc.tar.${GNU_TOOLCHAIN_FORMAT}" | sha256sum -c && \
50+
tar -xvf gcc.tar.${GNU_TOOLCHAIN_FORMAT} -C /usr/local --strip-components=1 && \
51+
rm -f gcc.tar.${GNU_TOOLCHAIN_FORMAT} /root/.wget-hsts
4952

50-
# Tools for building
51-
RUN apt-get update && apt-get install -y \
53+
RUN export DEBIAN_FRONTEND=noninteractive; \
54+
apt-get update && apt-get install -y \
5255
make \
5356
llvm-18 \
5457
gcc-10 \
@@ -64,48 +67,38 @@ RUN apt-get update && apt-get install -y \
6467
libcmocka-dev \
6568
libusb-1.0-0-dev \
6669
libudev-dev \
67-
libhidapi-dev
68-
69-
RUN apt-get update && apt-get install -y \
70-
doxygen \
71-
graphviz
72-
73-
# Set gcc-10 as the default gcc
74-
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100
75-
RUN update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-10 100
76-
77-
# Tools for CI
78-
RUN apt-get update && apt-get install -y \
70+
libhidapi-dev \
7971
python3 \
8072
python3-pip \
73+
doxygen \
74+
graphviz \
8175
clang-format-18 \
82-
clang-tidy-18
76+
clang-tidy-18 \
77+
bash-completion \
78+
&& rm -rf /var/lib/apt/lists/*
8379

84-
RUN python3 -m pip install --upgrade pip
80+
# Set gcc-10 as the default gcc
81+
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 && \
82+
update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-10 100 && \
83+
rm /var/log/alternatives.log
8584

8685
# Python modules
87-
COPY py/bitbox02 /tmp/bitbox02
88-
RUN python3 -m pip install /tmp/bitbox02
89-
RUN rm -r /tmp/bitbox02
90-
COPY py/requirements.txt /tmp
91-
RUN python3 -m pip install --upgrade --requirement /tmp/requirements.txt
92-
RUN rm /tmp/requirements.txt
93-
94-
# Python modules for CI
95-
RUN python3 -m pip install --upgrade \
86+
RUN --mount=source=py,target=/mnt,rw \
87+
python3 -m pip install --no-compile --no-cache-dir /mnt/bitbox02 && \
88+
python3 -m pip install --no-compile --no-cache-dir --upgrade --requirement /mnt/requirements.txt && \
89+
python3 -m pip install --no-compile --no-cache-dir --upgrade \
9690
pylint==2.13.9 \
9791
pylint-protobuf==0.20.2 \
9892
black==22.3.0 \
9993
mypy==0.960 \
100-
mypy-protobuf==3.2.0
101-
102-
# Python modules for packaging
103-
RUN python3 -m pip install --upgrade \
94+
mypy-protobuf==3.2.0 \
10495
setuptools==41.2.0 \
10596
wheel==0.33.6 \
106-
twine==1.15.0
97+
twine==1.15.0 \
98+
gcovr==7.2
10799

108100
#Install protoc from release, because the version available on the repo is too old
101+
ENV PATH /opt/protoc/bin:$PATH
109102
RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
110103
PROTOC_URL=https://github.com/protocolbuffers/protobuf/releases/download/v21.2/protoc-21.2-linux-aarch_64.zip; \
111104
else \
@@ -115,50 +108,36 @@ RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
115108
curl -L0 ${PROTOC_URL} -o /tmp/protoc-21.2.zip && \
116109
unzip /tmp/protoc-21.2.zip -d /opt/protoc && \
117110
rm /tmp/protoc-21.2.zip
118-
ENV PATH /opt/protoc/bin:$PATH
119-
120-
# Make Python3 the default
121-
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1
122-
123-
# Developer tools
124-
RUN apt-get update && apt-get install -y \
125-
bash-completion
126-
# Install gcovr from PIP to get a newer version than in apt repositories
127-
RUN python3 -m pip install gcovr
128111

129112
# Install Go, used for the tools in tools/go and for test/gounittest
130-
ENV GOPATH /opt/go
131-
ENV GOROOT /opt/go_dist/go
132-
ENV PATH $GOROOT/bin:$GOPATH/bin:$PATH
113+
ENV PATH=$GOROOT/bin:$GOPATH/bin:$PATH GOPATH=/opt/go GOROOT=/opt/go_dist/go
133114
RUN mkdir -p /opt/go_dist && \
134115
curl https://dl.google.com/go/go1.19.3.linux-${TARGETARCH}.tar.gz | tar -xz -C /opt/go_dist
135116

136117
# Install lcov from release (the one from the repos is too old).
137-
RUN cd /opt && wget https://github.com/linux-test-project/lcov/releases/download/v1.14/lcov-1.14.tar.gz && tar -xf lcov-1.14.tar.gz
138-
ENV PATH /opt/lcov-1.14/bin:$PATH
118+
ENV PATH=/opt/lcov-1.14/bin:$PATH
119+
RUN curl -L https://github.com/linux-test-project/lcov/releases/download/v1.14/lcov-1.14.tar.gz | tar -xz -C /opt
139120

140121
# Install rust compiler
141-
ENV PATH /opt/cargo/bin:$PATH
142-
ENV RUSTUP_HOME=/opt/rustup
143-
COPY src/rust/rust-toolchain.toml /tmp/rust-toolchain.toml
144-
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | CARGO_HOME=/opt/cargo sh -s -- --default-toolchain $(grep -oP '(?<=channel = ")[^"]+' /tmp/rust-toolchain.toml) -y
145-
RUN rustup target add thumbv7em-none-eabi
146-
RUN rustup component add rustfmt
147-
RUN rustup component add clippy
148-
RUN rustup component add rust-src
149-
RUN CARGO_HOME=/opt/cargo cargo install cbindgen --version 0.26.0 --locked
150-
RUN CARGO_HOME=/opt/cargo cargo install bindgen-cli --version 0.69.4 --locked
122+
# Since bindgen embeds information about its target directory, use a deterministic path for it.
123+
ENV PATH=/opt/cargo/bin:$PATH RUSTUP_HOME=/opt/rustup
124+
RUN --mount=source=tools/prost-build-proto,target=/mnt/prost-build-proto,rw \
125+
--mount=source=src/rust/rust-toolchain.toml,target=/mnt/rust-toolchain.toml \
126+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
127+
CARGO_HOME=/opt/cargo sh -s -- --default-toolchain $(grep -oP '(?<=channel = ")[^"]+' /mnt/rust-toolchain.toml) -y && \
128+
rustup target add thumbv7em-none-eabi && \
129+
rustup component add rustfmt && \
130+
rustup component add clippy && \
131+
rustup component add rust-src && \
132+
CARGO_HOME=/opt/cargo cargo install cbindgen --version 0.26.0 --locked && \
133+
CARGO_HOME=/opt/cargo cargo install bindgen-cli --version 0.69.4 --locked --target-dir=/tmp/bindgen-target && \
134+
CARGO_HOME=/opt/cargo cargo install --path /mnt/prost-build-proto --locked && \
135+
rm -r /tmp/bindgen-target /opt/cargo/registry/index /opt/cargo/.global-cache
151136

152137
# Until cargo vendor supports vendoring dependencies of the rust std libs we
153138
# need a copy of this file next to the toml file. It also has to be world
154139
# writable so that invocations of `cargo vendor` can update it. Below is the
155140
# tracking issue for `cargo vendor` to support rust std libs.
156141
# https://github.com/rust-lang/wg-cargo-std-aware/issues/23
157-
RUN cp "$(rustc --print=sysroot)/lib/rustlib/src/rust/Cargo.lock" "$(rustc --print=sysroot)/lib/rustlib/src/rust/library/test/"
158-
RUN chmod 777 $(rustc --print=sysroot)/lib/rustlib/src/rust/library/test/Cargo.lock
159-
160-
COPY tools/prost-build-proto prost-build-proto
161-
RUN CARGO_HOME=/opt/cargo cargo install --path prost-build-proto --locked
162-
163-
# Clean temporary files to reduce image size
164-
RUN rm -rf /var/lib/apt/lists/*
142+
RUN cp "$(rustc --print=sysroot)/lib/rustlib/src/rust/Cargo.lock" "$(rustc --print=sysroot)/lib/rustlib/src/rust/library/test/" && \
143+
chmod 777 $(rustc --print=sysroot)/lib/rustlib/src/rust/library/test/Cargo.lock

external/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ ExternalProject_Add(libwally-core
5252
COMMAND ${CMAKE_COMMAND} -E env
5353
"CFLAGS=${LIBWALLY_CFLAGS}"
5454
"LDFLAGS=${LIBWALLY_LDFLAGS}"
55+
PYTHON_VERSION=3
5556
${CMAKE_CURRENT_SOURCE_DIR}/libwally-core/configure
5657
${CONFIGURE_FLAGS}
5758
${LIBWALLY_CONFIGURE_FLAGS}

scripts/expand_template

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
"""Expand python templates"""
33

44
from string import Template

scripts/get_version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
"""
33
Parse the tags and strip the prefix
44
First argument should be prefix to match against

0 commit comments

Comments
 (0)