| 1 |
# SPDX-License-Identifier: MPL-2.0 OR LGPL-3.0-or-later |
| 2 |
# |
| 3 |
# libpathrs: safe path resolution on Linux |
| 4 |
# Copyright (C) 2026 Aleksa Sarai <[email protected]> |
| 5 |
# |
| 6 |
# == MPL-2.0 == |
| 7 |
# |
| 8 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 9 |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 10 |
# file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 11 |
# |
| 12 |
# Alternatively, this Source Code Form may also (at your option) be used |
| 13 |
# under the terms of the GNU Lesser General Public License Version 3, as |
| 14 |
# described below: |
| 15 |
# |
| 16 |
# == LGPL-3.0-or-later == |
| 17 |
# |
| 18 |
# This program is free software: you can redistribute it and/or modify it |
| 19 |
# under the terms of the GNU Lesser General Public License as published by |
| 20 |
# the Free Software Foundation, either version 3 of the License, or (at |
| 21 |
# your option) any later version. |
| 22 |
# |
| 23 |
# This program is distributed in the hope that it will be useful, but |
| 24 |
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 25 |
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 26 |
# for more details. |
| 27 |
# |
| 28 |
# You should have received a copy of the GNU Lesser General Public License |
| 29 |
# along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 30 |
|
| 31 |
ARG DEBIAN_RELEASE=trixie |
| 32 |
ARG RUST_VERSION=1.96 |
| 33 |
|
| 34 |
# --------------------------------------------------------------------------- # |
| 35 |
# build: builds libpathrs for use by CI and the "install" image. |
| 36 |
# --------------------------------------------------------------------------- # |
| 37 |
FROM rust:${RUST_VERSION}-${DEBIAN_RELEASE} AS build |
| 38 |
|
| 39 |
RUN apt-get update -y && \ |
| 40 |
apt-get upgrade -y && \ |
| 41 |
apt-get install -y --no-install-recommends \ |
| 42 |
clang \ |
| 43 |
lld \ |
| 44 |
make \ |
| 45 |
pkg-config && \ |
| 46 |
apt-get clean -y && \ |
| 47 |
rm -rf /var/lib/apt/lists/* |
| 48 |
|
| 49 |
WORKDIR /usr/src/libpathrs |
| 50 |
COPY . /usr/src/libpathrs |
| 51 |
RUN make release && \ |
| 52 |
DESTDIR=/opt/libpathrs ./install.sh --prefix=/usr --libdir=/usr/lib |
| 53 |
|
| 54 |
# ---------------------------------------------------------------------------- |
| 55 |
# install: minimal runtime image with libpathrs installed system-wide. |
| 56 |
# Intended to be used as a base image by downstream projects on distros that do |
| 57 |
# not ship a libpathrs package yet. |
| 58 |
# ---------------------------------------------------------------------------- |
| 59 |
FROM debian:${DEBIAN_RELEASE} AS install |
| 60 |
|
| 61 |
ENV DEBIAN_FRONTEND=noninteractive |
| 62 |
|
| 63 |
RUN apt-get update -y && \ |
| 64 |
apt-get upgrade -y && \ |
| 65 |
apt-get install -y --no-install-recommends \ |
| 66 |
pkg-config && \ |
| 67 |
apt-get clean -y && \ |
| 68 |
rm -rf /var/lib/apt/lists/* |
| 69 |
|
| 70 |
COPY --from=build /opt/libpathrs/ / |
| 71 |
# debian doesn't use /usr/lib for the native architecture so we need to make |
| 72 |
# sure it gets searched by the link loader with ldconfig. |
| 73 |
RUN ldconfig |
| 74 |
|
| 75 |
# ---------------------------------------------------------------------------- |
| 76 |
# ci: full test runner for CI and local test runs. |
| 77 |
# This can run the Rust unit/integration tests and the e2e tests. |
| 78 |
# ---------------------------------------------------------------------------- |
| 79 |
ARG RUST_VERSION=1.96 |
| 80 |
FROM rust:${RUST_VERSION}-${DEBIAN_RELEASE} AS ci |
| 81 |
|
| 82 |
ENV DEBIAN_FRONTEND=noninteractive |
| 83 |
|
| 84 |
RUN apt-get update -y && \ |
| 85 |
apt-get install -y --no-install-recommends \ |
| 86 |
bats \ |
| 87 |
curl \ |
| 88 |
clang \ |
| 89 |
git \ |
| 90 |
golang-go \ |
| 91 |
jq \ |
| 92 |
lld \ |
| 93 |
llvm \ |
| 94 |
moreutils \ |
| 95 |
python3 \ |
| 96 |
python3-build \ |
| 97 |
python3-dev \ |
| 98 |
python3-pip \ |
| 99 |
python3-setuptools \ |
| 100 |
python3-venv \ |
| 101 |
sudo && \ |
| 102 |
apt-get clean -y && \ |
| 103 |
rm -rf /var/lib/apt/lists/* |
| 104 |
|
| 105 |
# Use a globally-writable place for Go caches. |
| 106 |
ENV GOCACHE=/tmp/go-cache/build |
| 107 |
ENV GOMODCACHE=/tmp/go-cache/mod |
| 108 |
|
| 109 |
ARG CARGO_BINSTALL_VERSION=1.19.1 |
| 110 |
RUN CARGO_BINSTALL_VERSION="$CARGO_BINSTALL_VERSION" \ |
| 111 |
curl -L --proto '=https' --tlsv1.2 -sSf \ |
| 112 |
"https://raw.githubusercontent.com/cargo-bins/cargo-binstall/v$CARGO_BINSTALL_VERSION/install-from-binstall-release.sh" | bash |
| 113 |
|
| 114 |
ARG CARGO_LLVM_COV_VERSION=0.8.7 |
| 115 |
ARG CARGO_HACK_VERSION=0.6.45 |
| 116 |
ARG CARGO_NEXTEST_VERSION=0.9.137 |
| 117 |
RUN cargo binstall --no-confirm \ |
| 118 |
"cargo-llvm-cov@$CARGO_LLVM_COV_VERSION" \ |
| 119 |
"cargo-hack@$CARGO_HACK_VERSION" \ |
| 120 |
"cargo-nextest@$CARGO_NEXTEST_VERSION" |
| 121 |
|
| 122 |
ARG RUST_NIGHTLY=nightly-2026-06-03 |
| 123 |
RUN rustup toolchain install "$RUST_NIGHTLY" && \ |
| 124 |
rustup component add llvm-tools llvm-tools-preview && \ |
| 125 |
rustup component add --toolchain "$RUST_NIGHTLY" llvm-tools llvm-tools-preview |
| 126 |
ENV CARGO_NIGHTLY="cargo +$RUST_NIGHTLY" |
| 127 |
|
| 128 |
# We want the installed libpathrs library for the Python and Go tests. |
| 129 |
COPY --from=build /opt/libpathrs/ / |
| 130 |
# Debian doesn't use /usr/lib for the native architecture so we need to make |
| 131 |
# sure it gets searched by the link loader with ldconfig. |
| 132 |
RUN ldconfig |
| 133 |
|
| 134 |
WORKDIR /usr/src/libpathrs |
| 135 |
COPY . /usr/src/libpathrs |
| 136 |
|
| 137 |
# Populate the cache for test runs and make sure the ownership is friendly for |
| 138 |
# non-root. |
| 139 |
FROM ci AS ci-with-cache |
| 140 |
RUN cargo test --workspace --all-features --no-run && \ |
| 141 |
$CARGO_NIGHTLY llvm-cov --workspace --doc --all-features --no-report && \ |
| 142 |
find "$CARGO_HOME" /usr/src/libpathrs -type d -print0 | xargs -0 -P$(nproc) chmod a+rwx && \ |
| 143 |
find "$CARGO_HOME" /usr/src/libpathrs -type f -print0 | xargs -0 -P$(nproc) chmod a+rw |