@@ -26,13 +26,12 @@ ARG CARGO_DENY_VERSION=0.7.3
26
26
ARG ZLIB_VERSION=1.2.11
27
27
ARG POSTGRESQL_VERSION=11.9
28
28
29
- # Make sure we have basic dev tools for building C libraries. Our goal
30
- # here is to support the musl-libc builds and Cargo builds needed for a
31
- # large selection of the most popular crates.
29
+ # Make sure we have basic dev tools for building C libraries. Our goal here is
30
+ # to support the musl-libc builds and Cargo builds needed for a large selection
31
+ # of the most popular crates.
32
32
#
33
- # We also set up a `rust` user by default, in whose account we'll install
34
- # the Rust toolchain. This user has sudo privileges if you need to install
35
- # any more software.
33
+ # We also set up a `rust` user by default. This user has sudo privileges if you
34
+ # need to install any more software.
36
35
#
37
36
# `mdbook` is the standard Rust tool for making searchable HTML manuals.
38
37
RUN apt-get update && \
@@ -52,7 +51,6 @@ RUN apt-get update && \
52
51
pkgconf \
53
52
sudo \
54
53
xutils-dev \
55
- gcc-multilib-arm-linux-gnueabihf \
56
54
&& \
57
55
apt-get clean && rm -rf /var/lib/apt/lists/* && \
58
56
useradd rust --user-group --create-home --shell /bin/bash --groups sudo && \
@@ -70,35 +68,7 @@ RUN apt-get update && \
70
68
rm -rf cargo-deny-$CARGO_DENY_VERSION-x86_64-unknown-linux-musl cargo-deny-$CARGO_DENY_VERSION-x86_64-unknown-linux-musl.tar.gz
71
69
72
70
# Static linking for C++ code
73
- RUN sudo ln -s "/usr/bin/g++" "/usr/bin/musl-g++"
74
-
75
- # Allow sudo without a password.
76
- ADD sudoers /etc/sudoers.d/nopasswd
77
-
78
- # Run all further code as user `rust`, and create our working directories
79
- # as the appropriate user.
80
- USER rust
81
- RUN mkdir -p /home/rust/libs /home/rust/src
82
-
83
- # Set up our path with all our binary directories, including those for the
84
- # musl-gcc toolchain and for our Rust toolchain.
85
- ENV PATH=/home/rust/.cargo/bin:/usr/local/musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
86
-
87
- # Install our Rust toolchain and the `musl` target. We patch the
88
- # command-line we pass to the installer so that it won't attempt to
89
- # interact with the user or fool around with TTYs. We also set the default
90
- # `--target` to musl so that our users don't need to keep overriding it
91
- # manually.
92
- RUN curl https://sh.rustup.rs -sSf | \
93
- sh -s -- -y --default-toolchain $TOOLCHAIN && \
94
- rustup target add x86_64-unknown-linux-musl && \
95
- rustup target add armv7-unknown-linux-musleabihf
96
- ADD cargo-config.toml /home/rust/.cargo/config
97
-
98
- # Set up a `git credentials` helper for using GH_USER and GH_TOKEN to access
99
- # private repositories if desired.
100
- ADD git-credential-ghtoken /usr/local/bin/ghtoken
101
- RUN git config --global credential.https://github.com.helper ghtoken
71
+ RUN ln -s "/usr/bin/g++" "/usr/bin/musl-g++"
102
72
103
73
# Build a static library version of OpenSSL using musl-libc. This is needed by
104
74
# the popular Rust `hyper` crate.
@@ -109,10 +79,10 @@ RUN git config --global credential.https://github.com.helper ghtoken
109
79
# happen. There may be "sanitized" header
110
80
RUN echo "Building OpenSSL" && \
111
81
ls /usr/include/linux && \
112
- sudo mkdir -p /usr/local/musl/include && \
113
- sudo ln -s /usr/include/linux /usr/local/musl/include/linux && \
114
- sudo ln -s /usr/include/x86_64-linux-gnu/asm /usr/local/musl/include/asm && \
115
- sudo ln -s /usr/include/asm-generic /usr/local/musl/include/asm-generic && \
82
+ mkdir -p /usr/local/musl/include && \
83
+ ln -s /usr/include/linux /usr/local/musl/include/linux && \
84
+ ln -s /usr/include/x86_64-linux-gnu/asm /usr/local/musl/include/asm && \
85
+ ln -s /usr/include/asm-generic /usr/local/musl/include/asm-generic && \
116
86
cd /tmp && \
117
87
short_version="$(echo " $OPENSSL_VERSION" | sed s'/[a-z]$//' )" && \
118
88
curl -fLO "https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz" || \
@@ -121,27 +91,63 @@ RUN echo "Building OpenSSL" && \
121
91
env CC=musl-gcc ./Configure no-shared no-zlib -fPIC --prefix=/usr/local/musl -DOPENSSL_NO_SECURE_MEMORY linux-x86_64 && \
122
92
env C_INCLUDE_PATH=/usr/local/musl/include/ make depend && \
123
93
env C_INCLUDE_PATH=/usr/local/musl/include/ make && \
124
- sudo make install && \
125
- sudo rm /usr/local/musl/include/linux /usr/local/musl/include/asm /usr/local/musl/include/asm-generic && \
94
+ make install && \
95
+ rm /usr/local/musl/include/linux /usr/local/musl/include/asm /usr/local/musl/include/asm-generic && \
126
96
rm -r /tmp/*
127
97
128
98
RUN echo "Building zlib" && \
129
99
cd /tmp && \
130
100
curl -fLO "http://zlib.net/zlib-$ZLIB_VERSION.tar.gz" && \
131
101
tar xzf "zlib-$ZLIB_VERSION.tar.gz" && cd "zlib-$ZLIB_VERSION" && \
132
102
CC=musl-gcc ./configure --static --prefix=/usr/local/musl && \
133
- make && sudo make install && \
103
+ make && make install && \
134
104
rm -r /tmp/*
135
105
136
106
RUN echo "Building libpq" && \
137
107
cd /tmp && \
138
108
curl -fLO "https://ftp.postgresql.org/pub/source/v$POSTGRESQL_VERSION/postgresql-$POSTGRESQL_VERSION.tar.gz" && \
139
109
tar xzf "postgresql-$POSTGRESQL_VERSION.tar.gz" && cd "postgresql-$POSTGRESQL_VERSION" && \
140
110
CC=musl-gcc CPPFLAGS=-I/usr/local/musl/include LDFLAGS=-L/usr/local/musl/lib ./configure --with-openssl --without-readline --prefix=/usr/local/musl && \
141
- cd src/interfaces/libpq && make all-static-lib && sudo make install-lib-static && \
142
- cd ../../bin/pg_config && make && sudo make install && \
111
+ cd src/interfaces/libpq && make all-static-lib && make install-lib-static && \
112
+ cd ../../bin/pg_config && make && make install && \
143
113
rm -r /tmp/*
144
114
115
+ # (Please feel free to submit pull requests for musl-libc builds of other C
116
+ # libraries needed by the most popular and common Rust crates, to avoid
117
+ # everybody needing to build them manually.)
118
+
119
+ # Install a `git credentials` helper for using GH_USER and GH_TOKEN to access
120
+ # private repositories if desired. We make sure this is configured for root,
121
+ # here, and for the `rust` user below.
122
+ ADD git-credential-ghtoken /usr/local/bin/ghtoken
123
+ RUN git config --global credential.https://github.com.helper ghtoken
124
+
125
+ # Set up our path with all our binary directories, including those for the
126
+ # musl-gcc toolchain and for our Rust toolchain.
127
+ #
128
+ # We use the instructions at https://github.com/rust-lang/rustup/issues/2383
129
+ # to install the rustup toolchain as root.
130
+ ENV RUSTUP_HOME=/opt/rust/rustup \
131
+ PATH=/home/rust/.cargo/bin:/opt/rust/cargo/bin:/usr/local/musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
132
+
133
+ # Install our Rust toolchain and the `musl` target. We patch the
134
+ # command-line we pass to the installer so that it won't attempt to
135
+ # interact with the user or fool around with TTYs. We also set the default
136
+ # `--target` to musl so that our users don't need to keep overriding it
137
+ # manually.
138
+ RUN curl https://sh.rustup.rs -sSf | \
139
+ env CARGO_HOME=/opt/rust/cargo \
140
+ sh -s -- -y --default-toolchain $TOOLCHAIN --profile minimal --no-modify-path && \
141
+ env CARGO_HOME=/opt/rust/cargo \
142
+ rustup component add rustfmt && \
143
+ env CARGO_HOME=/opt/rust/cargo \
144
+ rustup component add clippy && \
145
+ env CARGO_HOME=/opt/rust/cargo \
146
+ rustup target add x86_64-unknown-linux-musl
147
+ ADD cargo-config.toml /opt/rust/cargo/config
148
+
149
+ # Set up our environment variables so that we cross-compile using musl-libc by
150
+ # default.
145
151
ENV X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_DIR=/usr/local/musl/ \
146
152
X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_STATIC=1 \
147
153
PQ_LIB_STATIC_X86_64_UNKNOWN_LINUX_MUSL=1 \
@@ -151,19 +157,28 @@ ENV X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_DIR=/usr/local/musl/ \
151
157
LIBZ_SYS_STATIC=1 \
152
158
TARGET=musl
153
159
154
- # (Please feel free to submit pull requests for musl-libc builds of other C
155
- # libraries needed by the most popular and common Rust crates, to avoid
156
- # everybody needing to build them manually.)
157
-
158
160
# Install some useful Rust tools from source. This will use the static linking
159
161
# toolchain, but that should be OK.
160
162
#
161
163
# We include cargo-audit for compatibility with earlier versions of this image,
162
- # but cargo-deny provides a super-set of cargo-audit's features.
163
- RUN cargo install -f cargo-audit && \
164
- cargo install -f cargo-deb && \
165
- cargo install -f mdbook-graphviz && \
166
- rm -rf /home/rust/.cargo/registry/
164
+ # but cargo-deny provides a superset of cargo-audit's features.
165
+ RUN env CARGO_HOME=/opt/rust/cargo cargo install -f cargo-audit && \
166
+ env CARGO_HOME=/opt/rust/cargo cargo install -f cargo-deb && \
167
+ env CARGO_HOME=/opt/rust/cargo cargo install -f mdbook-graphviz && \
168
+ rm -rf /opt/rust/cargo/registry/
169
+
170
+ # Allow sudo without a password.
171
+ ADD sudoers /etc/sudoers.d/nopasswd
172
+
173
+ # Run all further code as user `rust`, create our working directories, install
174
+ # our config file, and set up our credential helper.
175
+ #
176
+ # You should be able to switch back to `USER root` from another `Dockerfile`
177
+ # using this image if you need to do so.
178
+ USER rust
179
+ RUN mkdir -p /home/rust/libs /home/rust/src /home/rust/.cargo && \
180
+ ln -s /opt/rust/cargo/config /home/rust/.cargo/config && \
181
+ git config --global credential.https://github.com.helper ghtoken
167
182
168
183
# Expect our source code to live in /home/rust/src. We'll run the build as
169
184
# user `rust`, which will be uid 1000, gid 1000 outside the container.
0 commit comments