@@ -83,8 +83,6 @@ FROM vaultwarden/web-vault@{{ vault_image_digest }} as vault
83
83
########################## BUILD IMAGE ##########################
84
84
FROM {{ build_stage_base_image }} as build
85
85
86
-
87
-
88
86
# Build time options to avoid dpkg warnings and help with reproducible builds.
89
87
ENV DEBIAN_FRONTEND=noninteractive \
90
88
LANG=C.UTF-8 \
@@ -93,31 +91,33 @@ ENV DEBIAN_FRONTEND=noninteractive \
93
91
CARGO_HOME="/root/.cargo" \
94
92
USER="root"
95
93
96
-
97
94
# Create CARGO_HOME folder and don't download rust docs
98
95
RUN {{ mount_rust_cache -}} mkdir -pv "${CARGO_HOME}" \
99
96
&& rustup set profile minimal
100
97
101
98
{% if "alpine" in target_file %}
99
+ # Install build dependencies
100
+ RUN apt-get update && apt-get install -y --no-install-recommends libcap2-bin
102
101
{% if "armv6" in target_file %}
102
+
103
103
# To be able to build the armv6 image with mimalloc we need to specifically specify the libatomic.a file location
104
104
ENV RUSTFLAGS='-Clink-arg=/usr/local/musl/{{ package_arch_target }}/lib/libatomic.a'
105
105
{% endif %}
106
106
{% elif "arm" in target_file %}
107
- #
108
- # Install required build libs for {{ package_arch_name }} architecture.
107
+ # Install build dependencies for the {{ package_arch_name }} architecture
109
108
RUN dpkg --add-architecture {{ package_arch_name }} \
110
109
&& apt-get update \
111
110
&& apt-get install -y \
112
111
--no-install-recommends \
113
- libssl-dev {{ package_arch_prefix }} \
112
+ gcc- {{ package_cross_compiler }} \
114
113
libc6-dev{{ package_arch_prefix }} \
115
- libpq5{{ package_arch_prefix }} \
116
- libpq-dev{{ package_arch_prefix }} \
117
- libmariadb3{{ package_arch_prefix }} \
114
+ libcap2-bin \
118
115
libmariadb-dev{{ package_arch_prefix }} \
119
116
libmariadb-dev-compat{{ package_arch_prefix }} \
120
- gcc-{{ package_cross_compiler }} \
117
+ libmariadb3{{ package_arch_prefix }} \
118
+ libpq-dev{{ package_arch_prefix }} \
119
+ libpq5{{ package_arch_prefix }} \
120
+ libssl-dev{{ package_arch_prefix }} \
121
121
#
122
122
# Make sure cargo has the right target config
123
123
&& echo '[target.{{ package_arch_target }}]' >> "${CARGO_HOME}/config" \
@@ -129,16 +129,14 @@ ENV CC_{{ package_arch_target | replace("-", "_") }}="/usr/bin/{{ package_cross_
129
129
CROSS_COMPILE="1" \
130
130
OPENSSL_INCLUDE_DIR="/usr/include/{{ package_cross_compiler }}" \
131
131
OPENSSL_LIB_DIR="/usr/lib/{{ package_cross_compiler }}"
132
-
133
132
{% elif "amd64" in target_file %}
134
- # Install DB packages
133
+ # Install build dependencies
135
134
RUN apt-get update \
136
135
&& apt-get install -y \
137
136
--no-install-recommends \
138
- libmariadb-dev{{ package_arch_prefix }} \
139
- libpq-dev{{ package_arch_prefix }} \
140
- && apt-get clean \
141
- && rm -rf /var/lib/apt/lists/*
137
+ libcap2-bin \
138
+ libmariadb-dev \
139
+ libpq-dev
142
140
{% endif %}
143
141
144
142
# Creates a dummy project used to grab dependencies
@@ -179,6 +177,18 @@ RUN touch src/main.rs
179
177
# your actual source files being built
180
178
RUN {{ mount_rust_cache -}} cargo build --features ${DB} --release{{ package_arch_target_param }}
181
179
180
+ {% if "buildkit" in target_file %}
181
+ # Add the `cap_net_bind_service` capability to allow listening on
182
+ # privileged (< 1024) ports even when running as a non-root user.
183
+ # This is only done if building with BuildKit; with the legacy
184
+ # builder, the `COPY` instruction doesn't carry over capabilities.
185
+ {% if package_arch_target is defined %}
186
+ RUN setcap cap_net_bind_service=+ep target/{{ package_arch_target }}/release/vaultwarden
187
+ {% else %}
188
+ RUN setcap cap_net_bind_service=+ep target/release/vaultwarden
189
+ {% endif %}
190
+ {% endif %}
191
+
182
192
######################## RUNTIME IMAGE ########################
183
193
# Create a new stage with a minimal image
184
194
# because we already have a binary built
@@ -200,18 +210,18 @@ RUN [ "cross-build-start" ]
200
210
RUN mkdir /data \
201
211
{% if "alpine" in runtime_stage_base_image %}
202
212
&& apk add --no-cache \
203
- openssl \
204
- tzdata \
213
+ ca-certificates \
205
214
curl \
206
- ca-certificates
215
+ openssl \
216
+ tzdata
207
217
{% else %}
208
218
&& apt-get update && apt-get install -y \
209
219
--no-install-recommends \
210
- openssl \
211
220
ca-certificates \
212
221
curl \
213
222
libmariadb-dev-compat \
214
223
libpq5 \
224
+ openssl \
215
225
&& apt-get clean \
216
226
&& rm -rf /var/lib/apt/lists/*
217
227
{% endif %}
0 commit comments