Skip to content

Commit ece243e

Browse files
committed
Slim down docker image by removing some temporary files
1 parent 33c4a29 commit ece243e

File tree

3 files changed

+57
-74
lines changed

3 files changed

+57
-74
lines changed

.ci/run-container-ci

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
set -e
2626
set -x
2727

28-
CONTAINER=shiftcrypto/firmware_v2:41
28+
CONTAINER=shiftcrypto/firmware_v2:test
2929

3030
if [ "$1" == "pull" ] ; then
3131
docker pull "$CONTAINER"

Dockerfile

Lines changed: 55 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,26 @@
1414
# limitations under the License.
1515

1616
# Latest Ubuntu LTS
17-
FROM ubuntu:22.04
18-
ENV DEBIAN_FRONTEND noninteractive
17+
FROM ubuntu:22.04@sha256:0eb0f877e1c869a300c442c41120e778db7161419244ee5cbc6fa5f134e74736
18+
ENV DEBIAN_FRONTEND=noninteractive
1919

20-
RUN apt-get update && apt-get upgrade -y && apt-get install -y wget nano rsync curl gnupg2 jq unzip bzip2
20+
RUN apt-get update && apt-get upgrade -y &&\
21+
apt-get install -y wget nano rsync curl gnupg2 jq unzip bzip2 &&\
22+
rm -r /var/lib/apt/lists/*
2123

22-
# for clang-*-15, see https://apt.llvm.org/
24+
# Install gcc8-arm-none-eabi
25+
RUN wget -O gcc.tar.bz2 https://developer.arm.com/-/media/Files/downloads/gnu-rm/8-2018q4/gcc-arm-none-eabi-8-2018-q4-major-linux.tar.bz2?revision=d830f9dd-cd4f-406d-8672-cca9210dd220?product=GNU%20Arm%20Embedded%20Toolchain,64-bit,,Linux,8-2018-q4-major &&\
26+
echo "fb31fbdfe08406ece43eef5df623c0b2deb8b53e405e2c878300f7a1f303ee52 gcc.tar.bz2" | sha256sum -c &&\
27+
tar -xjf gcc.tar.bz2 -C /usr/local --strip-components=1 &&\
28+
rm -f gcc.tar.bz2
29+
30+
# for clang-*-18, see https://apt.llvm.org/
2331
RUN echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" >> /etc/apt/sources.list && \
2432
echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" >> /etc/apt/sources.list && \
2533
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
2634

27-
# Install gcc8-arm-none-eabi
28-
RUN mkdir ~/Downloads &&\
29-
cd ~/Downloads &&\
30-
wget -O gcc.tar.bz2 https://developer.arm.com/-/media/Files/downloads/gnu-rm/8-2018q4/gcc-arm-none-eabi-8-2018-q4-major-linux.tar.bz2?revision=d830f9dd-cd4f-406d-8672-cca9210dd220?product=GNU%20Arm%20Embedded%20Toolchain,64-bit,,Linux,8-2018-q4-major &&\
31-
echo "fb31fbdfe08406ece43eef5df623c0b2deb8b53e405e2c878300f7a1f303ee52 gcc.tar.bz2" | sha256sum -c &&\
32-
cd ~/Downloads &&\
33-
tar -xjvf gcc.tar.bz2 &&\
34-
rm -f gcc.tar.bz2 &&\
35-
cd ~/Downloads && rsync -a gcc-arm-none-eabi-8-2018-q4-major/ /usr/local/
36-
37-
# Tools for building
3835
RUN apt-get update && apt-get install -y \
39-
build-essential \
36+
make \
4037
llvm-18 \
4138
gcc-10 \
4239
binutils \
@@ -54,95 +51,81 @@ RUN apt-get update && apt-get install -y \
5451
lib32z1 \
5552
libusb-1.0-0-dev \
5653
libudev-dev \
57-
libhidapi-dev
58-
59-
RUN apt-get update && apt-get install -y \
54+
libhidapi-dev \
6055
doxygen \
61-
graphviz
56+
graphviz \
57+
python3 \
58+
python3-pip \
59+
clang-format-18 \
60+
clang-tidy-18 \
61+
bash-completion \
62+
&& rm -r /var/lib/apt/lists/*
6263

6364
# Set gcc-10 as the default gcc
6465
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100
6566
RUN update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-10 100
6667

67-
# Tools for CI
68-
RUN apt-get update && apt-get install -y \
69-
python3 \
70-
python3-pip \
71-
clang-format-18 \
72-
clang-tidy-18
68+
# Make Python3 the default
69+
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1
7370

74-
RUN python3 -m pip install --upgrade pip
71+
# Install latest pip
72+
RUN python -m pip install --no-cache-dir --upgrade pip==24.2
7573

7674
# Python modules
77-
COPY py/bitbox02 /tmp/bitbox02
78-
RUN python3 -m pip install /tmp/bitbox02
79-
RUN rm -r /tmp/bitbox02
80-
COPY py/requirements.txt /tmp
81-
RUN python3 -m pip install --upgrade --requirement /tmp/requirements.txt
82-
RUN rm /tmp/requirements.txt
75+
RUN --mount=source=py/bitbox02,target=/mnt/bitbox02,rw \
76+
pip install --no-cache-dir /mnt/bitbox02
77+
RUN --mount=source=py/requirements.txt,target=/mnt/requirements.txt \
78+
pip install --no-cache-dir --upgrade --requirement /mnt/requirements.txt
8379

8480
# Python modules for CI
85-
RUN python3 -m pip install --upgrade \
81+
RUN pip install --no-cache-dir --upgrade \
8682
pylint==2.13.9 \
8783
pylint-protobuf==0.20.2 \
8884
black==22.3.0 \
8985
mypy==0.960 \
90-
mypy-protobuf==3.2.0
91-
92-
# Python modules for packaging
93-
RUN python3 -m pip install --upgrade \
86+
mypy-protobuf==3.2.0 \
9487
setuptools==41.2.0 \
9588
wheel==0.33.6 \
96-
twine==1.15.0
89+
twine==1.15.0 \
90+
gcovr==7.2
9791

9892
#Install protoc from release, because the version available on the repo is too old
9993
RUN mkdir -p /opt/protoc && \
10094
curl -L0 https://github.com/protocolbuffers/protobuf/releases/download/v21.2/protoc-21.2-linux-x86_64.zip -o /tmp/protoc-21.2-linux-x86_64.zip && \
101-
unzip /tmp/protoc-21.2-linux-x86_64.zip -d /opt/protoc
102-
ENV PATH /opt/protoc/bin:$PATH
103-
104-
# Make Python3 the default
105-
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1
106-
107-
# Developer tools
108-
RUN apt-get update && apt-get install -y \
109-
bash-completion
110-
# Install gcovr from PIP to get a newer version than in apt repositories
111-
RUN python3 -m pip install gcovr
95+
unzip /tmp/protoc-21.2-linux-x86_64.zip -d /opt/protoc &&\
96+
rm /tmp/protoc-21.2-linux-x86_64.zip
97+
ENV PATH=/opt/protoc/bin:$PATH
11298

11399
# Install Go, used for the tools in tools/go and for test/gounittest
114-
ENV GOPATH /opt/go
115-
ENV GOROOT /opt/go_dist/go
116-
ENV PATH $GOROOT/bin:$GOPATH/bin:$PATH
100+
ENV GOPATH=/opt/go
101+
ENV GOROOT=/opt/go_dist/go
102+
ENV PATH=$GOROOT/bin:$GOPATH/bin:$PATH
117103
RUN mkdir -p /opt/go_dist && \
118104
curl https://dl.google.com/go/go1.19.3.linux-amd64.tar.gz | tar -xz -C /opt/go_dist
119105

120106
# Install lcov from release (the one from the repos is too old).
121-
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
122-
ENV PATH /opt/lcov-1.14/bin:$PATH
107+
RUN curl -L https://github.com/linux-test-project/lcov/releases/download/v1.14/lcov-1.14.tar.gz | tar -xz -C /opt
108+
ENV PATH=/opt/lcov-1.14/bin:$PATH
123109

124110
# Install rust compiler
125-
ENV PATH /opt/cargo/bin:$PATH
111+
ENV PATH=/opt/cargo/bin:$PATH
126112
ENV RUSTUP_HOME=/opt/rustup
127-
COPY src/rust/rust-toolchain.toml /tmp/rust-toolchain.toml
128-
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
129-
RUN rustup target add thumbv7em-none-eabi
130-
RUN rustup component add rustfmt
131-
RUN rustup component add clippy
132-
RUN rustup component add rust-src
133-
RUN CARGO_HOME=/opt/cargo cargo install cbindgen --version 0.26.0 --locked
134-
RUN CARGO_HOME=/opt/cargo cargo install bindgen-cli --version 0.69.4 --locked
113+
RUN --mount=source=tools/prost-build-proto,target=/mnt/prost-build-proto,rw \
114+
--mount=source=src/rust/rust-toolchain.toml,target=/mnt/rust-toolchain.toml \
115+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs |\
116+
CARGO_HOME=/opt/cargo sh -s -- --default-toolchain $(grep -oP '(?<=channel = ")[^"]+' /mnt/rust-toolchain.toml) -y &&\
117+
rustup target add thumbv7em-none-eabi &&\
118+
rustup component add rustfmt &&\
119+
rustup component add clippy &&\
120+
rustup component add rust-src &&\
121+
CARGO_HOME=/opt/cargo cargo install cbindgen --version 0.26.0 --locked &&\
122+
CARGO_HOME=/opt/cargo cargo install bindgen-cli --version 0.69.4 --locked &&\
123+
CARGO_HOME=/opt/cargo cargo install --path /mnt/prost-build-proto --locked
135124

136125
# Until cargo vendor supports vendoring dependencies of the rust std libs we
137126
# need a copy of this file next to the toml file. It also has to be world
138127
# writable so that invocations of `cargo vendor` can update it. Below is the
139128
# tracking issue for `cargo vendor` to support rust std libs.
140129
# https://github.com/rust-lang/wg-cargo-std-aware/issues/23
141-
RUN cp "$(rustc --print=sysroot)/lib/rustlib/src/rust/Cargo.lock" "$(rustc --print=sysroot)/lib/rustlib/src/rust/library/test/"
142-
RUN chmod 777 $(rustc --print=sysroot)/lib/rustlib/src/rust/library/test/Cargo.lock
143-
144-
COPY tools/prost-build-proto prost-build-proto
145-
RUN CARGO_HOME=/opt/cargo cargo install --path prost-build-proto --locked
146-
147-
# Clean temporary files to reduce image size
148-
RUN rm -rf /var/lib/apt/lists/*
130+
RUN cp "$(rustc --print=sysroot)/lib/rustlib/src/rust/Cargo.lock" "$(rustc --print=sysroot)/lib/rustlib/src/rust/library/test/" &&\
131+
chmod 777 $(rustc --print=sysroot)/lib/rustlib/src/rust/library/test/Cargo.lock

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ jlink-flash-factory-setup: | build
129129
jlink-flash-firmware-semihosting: | build-semihosting
130130
JLinkExe -if SWD -device ATSAMD51J20 -speed 4000 -autoconnect 1 -CommanderScript ./build-semihosting/scripts/firmware.jlink
131131
dockerinit:
132-
./scripts/container.sh build --pull --platform linux/amd64 --force-rm --no-cache -t shiftcrypto/firmware_v2 .
132+
./scripts/container.sh build --pull --platform linux/amd64 --no-cache -t shiftcrypto/firmware_v2 .
133133
dockerdev:
134134
./scripts/dockerenv.sh
135135
dockerrel:

0 commit comments

Comments
 (0)