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 wget 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
+ wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \
37
+ rm /root/.wget-hsts
34
38
35
- # Install gcc8-arm-none-eabi
36
39
RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
37
40
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
41
GNU_TOOLCHAIN_HASH=c8824bffd057afce2259f7618254e840715f33523a3d4e4294f471208f976764 \
@@ -42,13 +45,13 @@ RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
42
45
GNU_TOOLCHAIN_HASH=fb31fbdfe08406ece43eef5df623c0b2deb8b53e405e2c878300f7a1f303ee52 \
43
46
GNU_TOOLCHAIN_FORMAT=bz2; \
44
47
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
49
52
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 \
52
55
make \
53
56
llvm-18 \
54
57
gcc-10 \
@@ -64,48 +67,38 @@ 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
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 \
79
71
python3 \
80
72
python3-pip \
73
+ doxygen \
74
+ graphviz \
81
75
clang-format-18 \
82
- clang-tidy-18
76
+ clang-tidy-18 \
77
+ bash-completion \
78
+ && rm -rf /var/lib/apt/lists/*
83
79
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
85
84
86
85
# 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 \
96
90
pylint==2.13.9 \
97
91
pylint-protobuf==0.20.2 \
98
92
black==22.3.0 \
99
93
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 \
104
95
setuptools==41.2.0 \
105
96
wheel==0.33.6 \
106
- twine==1.15.0
97
+ twine==1.15.0 \
98
+ gcovr==7.2
107
99
108
100
# Install protoc from release, because the version available on the repo is too old
101
+ ENV PATH /opt/protoc/bin:$PATH
109
102
RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
110
103
PROTOC_URL=https://github.com/protocolbuffers/protobuf/releases/download/v21.2/protoc-21.2-linux-aarch_64.zip; \
111
104
else \
@@ -115,50 +108,36 @@ RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
115
108
curl -L0 ${PROTOC_URL} -o /tmp/protoc-21.2.zip && \
116
109
unzip /tmp/protoc-21.2.zip -d /opt/protoc && \
117
110
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
128
111
129
112
# 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
133
114
RUN mkdir -p /opt/go_dist && \
134
115
curl https://dl.google.com/go/go1.19.3.linux-${TARGETARCH}.tar.gz | tar -xz -C /opt/go_dist
135
116
136
117
# 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
139
120
140
121
# 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
151
136
152
137
# Until cargo vendor supports vendoring dependencies of the rust std libs we
153
138
# need a copy of this file next to the toml file. It also has to be world
154
139
# writable so that invocations of `cargo vendor` can update it. Below is the
155
140
# tracking issue for `cargo vendor` to support rust std libs.
156
141
# 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
0 commit comments