19
19
# $ docker run --privileged --rm tonistiigi/binfmt --install arm64
20
20
21
21
FROM ubuntu:22.04
22
- ENV DEBIAN_FRONTEND noninteractive
23
22
24
23
# These are automatically provided by docker (no need for --build-arg)
25
24
ARG TARGETPLATFORM
26
25
ARG TARGETARCH
27
26
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 nano rsync curl gnupg2 jq unzip bzip2 xz-utils && \
31
+ rm -rf /var/lib/apt/lists/*
32
+
29
33
30
- # for clang-*-15, see https://apt.llvm.org/
31
34
RUN echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" >> /etc/apt/sources.list && \
32
35
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
+ curl -sSL https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
34
37
35
- # Install gcc8-arm-none-eabi
36
38
RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
37
39
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 \
38
40
GNU_TOOLCHAIN_HASH=c8824bffd057afce2259f7618254e840715f33523a3d4e4294f471208f976764 \
@@ -42,13 +44,14 @@ RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
42
44
GNU_TOOLCHAIN_HASH=fb31fbdfe08406ece43eef5df623c0b2deb8b53e405e2c878300f7a1f303ee52 \
43
45
GNU_TOOLCHAIN_FORMAT=bz2; \
44
46
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 &&\
47
+ curl -sSL -o gcc.tar.${GNU_TOOLCHAIN_FORMAT} ${GNU_TOOLCHAIN} && \
48
+ echo "$GNU_TOOLCHAIN_HASH gcc.tar.${GNU_TOOLCHAIN_FORMAT}" | sha256sum -c && \
49
+ tar -xf gcc.tar.${GNU_TOOLCHAIN_FORMAT} -C /usr/local --strip-components=1 && \
48
50
rm -f gcc.tar.${GNU_TOOLCHAIN_FORMAT}
49
51
50
52
# 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 \
52
55
make \
53
56
llvm-18 \
54
57
gcc-10 \
@@ -64,98 +67,105 @@ RUN apt-get update && apt-get install -y \
64
67
libcmocka-dev \
65
68
libusb-1.0-0-dev \
66
69
libudev-dev \
67
- libhidapi-dev
70
+ libhidapi-dev \
71
+ && rm -rf /var/lib/apt/lists/*
68
72
69
- RUN apt-get update && apt-get install -y \
73
+ RUN export DEBIAN_FRONTEND=noninteractive; \
74
+ apt-get update && apt-get install -y \
70
75
doxygen \
71
- graphviz
76
+ graphviz \
77
+ && rm -rf /var/lib/apt/lists/*
72
78
73
79
# 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
80
+ RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 && \
81
+ update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-10 100 && \
82
+ rm /var/log/alternatives.log
76
83
77
84
# Tools for CI
78
- RUN apt-get update && apt-get install -y \
85
+ RUN export DEBIAN_FRONTEND=noninteractive; \
86
+ apt-get update && apt-get install -y \
79
87
python3 \
80
88
python3-pip \
81
89
clang-format-18 \
82
- clang-tidy-18
83
-
84
- RUN python3 -m pip install --upgrade pip
90
+ clang-tidy-18 \
91
+ && rm -rf /var/lib/apt/lists/*
85
92
86
93
# 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
94
+ RUN --mount=source=py,target=/mnt,rw \
95
+ python3 -m pip install --no-compile --no-cache-dir /mnt/bitbox02 && \
96
+ python3 -m pip install --no-compile --no-cache-dir --upgrade --requirement /mnt/requirements.txt && \
93
97
94
98
# Python modules for CI
95
- RUN python3 -m pip install --upgrade \
99
+ RUN python3 -m pip install --no-compile --no-cache-dir -- upgrade \
96
100
pylint==2.13.9 \
97
101
pylint-protobuf==0.20.2 \
98
102
black==22.3.0 \
99
103
mypy==0.960 \
100
104
mypy-protobuf==3.2.0
101
105
102
106
# Python modules for packaging
103
- RUN python3 -m pip install --upgrade \
107
+ RUN python3 -m pip install --no-compile --no-cache-dir -- upgrade \
104
108
setuptools==41.2.0 \
105
109
wheel==0.33.6 \
106
110
twine==1.15.0
107
111
108
112
# Install protoc from release, because the version available on the repo is too old
113
+ ENV PATH /opt/protoc/bin:$PATH
109
114
RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
110
115
PROTOC_URL=https://github.com/protocolbuffers/protobuf/releases/download/v21.2/protoc-21.2-linux-aarch_64.zip; \
111
116
else \
112
117
PROTOC_URL=https://github.com/protocolbuffers/protobuf/releases/download/v21.2/protoc-21.2-linux-x86_64.zip; \
113
118
fi; \
114
119
mkdir -p /opt/protoc && \
115
- curl -L0 ${PROTOC_URL} -o /tmp/protoc-21.2.zip && \
120
+ curl -sSL0 ${PROTOC_URL} -o /tmp/protoc-21.2.zip && \
116
121
unzip /tmp/protoc-21.2.zip -d /opt/protoc && \
117
122
rm /tmp/protoc-21.2.zip
118
- ENV PATH /opt/protoc/bin:$PATH
119
123
120
124
# Developer tools
121
- RUN apt-get update && apt-get install -y \
122
- bash-completion
125
+ RUN export DEBIAN_FRONTEND=noninteractive; \
126
+ apt-get update && apt-get install -y \
127
+ bash-completion \
128
+ && rm -rf /var/lib/apt/lists/*
123
129
# Install gcovr from PIP to get a newer version than in apt repositories
124
- RUN python3 -m pip install gcovr
130
+ RUN python3 -m pip install --no-compile --no-cache-dir --upgrade \
131
+ gcovr==7.2
125
132
126
133
# Install Go, used for the tools in tools/go and for test/gounittest
127
- ENV GOPATH /opt/go
128
- ENV GOROOT /opt/go_dist/go
129
- ENV PATH $GOROOT/bin:$GOPATH/bin:$PATH
134
+ ENV PATH=/opt/go_dist/go/bin:/opt/go/bin:$PATH GOPATH=/opt/go GOROOT=/opt/go_dist/go
130
135
RUN mkdir -p /opt/go_dist && \
131
- curl https://dl.google.com/go/go1.19.3.linux-${TARGETARCH}.tar.gz | tar -xz -C /opt/go_dist
136
+ curl -sSL https://dl.google.com/go/go1.19.3.linux-${TARGETARCH}.tar.gz | tar -xz -C /opt/go_dist
132
137
133
138
# Install lcov from release (the one from the repos is too old).
134
- 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
135
- ENV PATH /opt/ lcov-1.14/bin:$PATH
139
+ ENV PATH= /opt/ lcov-1.14/bin:$PATH
140
+ RUN curl -sSL https://github.com/linux-test-project/ lcov/releases/download/v1.14/lcov -1.14.tar.gz | tar -xz -C /opt
136
141
137
142
# Install rust compiler
138
- ENV PATH /opt/cargo/bin:$PATH
139
- ENV RUSTUP_HOME=/opt/rustup
140
- COPY src/rust/rust-toolchain.toml /tmp/rust-toolchain.toml
141
- 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
142
- RUN rustup target add thumbv7em-none-eabi
143
- RUN rustup component add rustfmt
144
- RUN rustup component add clippy
145
- RUN rustup component add rust-src
146
- RUN CARGO_HOME=/opt/cargo cargo install cbindgen --version 0.26.0 --locked
147
- RUN CARGO_HOME=/opt/cargo cargo install bindgen-cli --version 0.69.4 --locked
143
+ # Since bindgen embeds information about its target directory, use a deterministic path for it.
144
+ ARG BINDGEN_VERSION=0.69.4
145
+ ARG CBINDGEN_VERSION=0.26.0
146
+ ENV PATH=/opt/cargo/bin:$PATH RUSTUP_HOME=/opt/rustup
147
+ RUN --mount=source=tools/prost-build-proto,target=/mnt/prost-build-proto,rw \
148
+ --mount=source=src/rust/rust-toolchain.toml,target=/mnt/rust-toolchain.toml \
149
+ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
150
+ CARGO_HOME=/opt/cargo sh -s -- --default-toolchain $(grep -oP '(?<=channel = ")[^"]+' /mnt/rust-toolchain.toml) -y && \
151
+ rustup target add thumbv7em-none-eabi && \
152
+ rustup component add rustfmt && \
153
+ rustup component add clippy && \
154
+ rustup component add rust-src && \
155
+ if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
156
+ CARGO_HOME=/opt/cargo cargo install cbindgen --version ${CBINDGEN_VERSION} --locked && \
157
+ CARGO_HOME=/opt/cargo cargo install bindgen-cli --version ${BINDGEN_VERSION} --locked --target-dir=/tmp/bindgen-target && rm -r /tmp/bindgen-target; \
158
+ else \
159
+ curl -sSL https://github.com/rust-lang/rust-bindgen/releases/download/v${BINDGEN_VERSION}/bindgen-cli-x86_64-unknown-linux-gnu.tar.xz | tar -xJ --strip-components=1 -C /opt/cargo/bin bindgen-cli-x86_64-unknown-linux-gnu/bindgen && \
160
+ curl -sSL https://github.com/mozilla/cbindgen/releases/download/${CBINDGEN_VERSION}/cbindgen -o /opt/cargo/bin/cbindgen && chmod +x /opt/cargo/bin/cbindgen; \
161
+ fi && \
162
+ CARGO_HOME=/opt/cargo cargo install --path /mnt/prost-build-proto --locked && \
163
+ rm -r /opt/cargo/registry/index /opt/cargo/.global-cache
148
164
149
165
# Until cargo vendor supports vendoring dependencies of the rust std libs we
150
166
# need a copy of this file next to the toml file. It also has to be world
151
167
# writable so that invocations of `cargo vendor` can update it. Below is the
152
168
# tracking issue for `cargo vendor` to support rust std libs.
153
169
# https://github.com/rust-lang/wg-cargo-std-aware/issues/23
154
- RUN cp "$(rustc --print=sysroot)/lib/rustlib/src/rust/Cargo.lock" "$(rustc --print=sysroot)/lib/rustlib/src/rust/library/test/"
155
- RUN chmod 777 $(rustc --print=sysroot)/lib/rustlib/src/rust/library/test/Cargo.lock
156
-
157
- COPY tools/prost-build-proto prost-build-proto
158
- RUN CARGO_HOME=/opt/cargo cargo install --path prost-build-proto --locked
159
-
160
- # Clean temporary files to reduce image size
161
- RUN rm -rf /var/lib/apt/lists/*
170
+ RUN cp "$(rustc --print=sysroot)/lib/rustlib/src/rust/Cargo.lock" "$(rustc --print=sysroot)/lib/rustlib/src/rust/library/test/" && \
171
+ chmod 777 $(rustc --print=sysroot)/lib/rustlib/src/rust/library/test/Cargo.lock
0 commit comments