|
| 1 | +# These aren't packages, just low-dependency binaries dropped in /usr/local/bin |
| 2 | +# so we can fetch them independently in a separate build. |
| 3 | +ARG base=docker.io/library/debian:sid |
| 4 | +FROM $base as base |
| 5 | +# Life is too short to care about dash |
| 6 | +RUN ln -sfr /bin/bash /bin/sh |
| 7 | +RUN <<EORUN |
| 8 | +set -xeuo pipefail |
| 9 | + |
| 10 | +# Initialize some basic packages |
| 11 | +apt -y update && apt -y install curl time bzip2 |
| 12 | + |
| 13 | +# Enable deb-src repositories for build-dep |
| 14 | +sed -i "s/^deb /deb [arch=$(dpkg --print-architecture)] /" /etc/apt/sources.list.d/debian.sources |
| 15 | +sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/debian.sources |
| 16 | + |
| 17 | +# Enable gh CLI repository |
| 18 | +mkdir -p -m 755 /etc/apt/keyrings |
| 19 | +curl -fLo /etc/apt/keyrings/githubcli-archive-keyring.gpg https://cli.github.com/packages/githubcli-archive-keyring.gpg |
| 20 | +chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg |
| 21 | +mkdir -p -m 755 /etc/apt/sources.list.d |
| 22 | +echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" > /etc/apt/sources.list.d/github-cli.list |
| 23 | + |
| 24 | +# And re-update after we've fetched repos |
| 25 | +apt -y update |
| 26 | +EORUN |
| 27 | + |
| 28 | +FROM base as tools |
| 29 | +# renovate: datasource=github-releases depName=block/goose |
| 30 | +ARG gooseversion=v1.11.1 |
| 31 | +# renovate: datasource=github-releases depName=bootc-dev/bcvk |
| 32 | +ARG bcvkversion=v0.5.3 |
| 33 | +RUN <<EORUN |
| 34 | +set -xeuo pipefail |
| 35 | +arch=$(arch) |
| 36 | + |
| 37 | +rm -vrf /usr/local/bin/* |
| 38 | + |
| 39 | +# goose for local AI |
| 40 | +target=goose-${arch}-unknown-linux-gnu.tar.bz2 |
| 41 | +/bin/time -f '%E %C' curl -fLO https://github.com/block/goose/releases/download/$gooseversion/$target |
| 42 | +tar xvjf $target |
| 43 | +mv goose /usr/local/bin/goose |
| 44 | + |
| 45 | +# bcvk |
| 46 | +if test "${arch}" = x86_64; then |
| 47 | + td=$(mktemp -d) |
| 48 | + ( |
| 49 | + cd $td |
| 50 | + target=bcvk-${arch}-unknown-linux-gnu |
| 51 | + /bin/time -f '%E %C' curl -fLO https://github.com/bootc-dev/bcvk/releases/download/$bcvkversion/${target}.tar.gz |
| 52 | + tar xvzf $target.tar.gz |
| 53 | + mv $target /usr/local/bin/bcvk |
| 54 | + ) |
| 55 | + rm -rf $td |
| 56 | +else |
| 57 | + echo bcvk unavailable for $arch |
| 58 | +fi |
| 59 | +EORUN |
| 60 | + |
| 61 | +FROM base as rust |
| 62 | +RUN <<EORUN |
| 63 | +set -xeuo pipefail |
| 64 | +# Setup rust; the idea here though is we install system-wide into /usr/local |
| 65 | +# as if it was packaged. |
| 66 | +export RUSTUP_HOME=/usr/local/rustup |
| 67 | +export CARGO_HOME=/usr/local/cargo |
| 68 | +# Install Rust system-wide |
| 69 | +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable --profile default |
| 70 | +# Move binaries to /usr/local/bin (system-managed, root-owned) |
| 71 | +mv /usr/local/cargo/bin/* /usr/local/bin/ |
| 72 | +# Nothing really left here |
| 73 | +rm -vrf /usr/local/cargo/bin |
| 74 | +EORUN |
| 75 | + |
| 76 | +# This builds the image. |
| 77 | +# Build this using `just devenv-build-debian` from the root of the repository. |
| 78 | +FROM base |
| 79 | +COPY packages-common.txt packages-debian.txt build-deps-debian.txt /run/src/ |
| 80 | +WORKDIR /run/src |
| 81 | +RUN <<EORUN |
| 82 | +set -xeuo pipefail |
| 83 | +grep -hEve '^#' packages-common.txt packages-debian.txt | /bin/time -f '%E %C' xargs apt -y install |
| 84 | +grep -vEe '^#' build-deps-debian.txt | /bin/time -f '%E %C' xargs apt -y build-dep |
| 85 | +apt clean && rm -rf /var/lib/apt/lists/* |
| 86 | +EORUN |
| 87 | + |
| 88 | +# Copy in the binaries from our tools container image |
| 89 | +COPY --from=tools /usr/local/bin/* /usr/local/bin/ |
| 90 | +COPY --from=rust /usr/local/bin/* /usr/local/bin/ |
| 91 | +COPY --from=rust /usr/local/rustup /usr/local/rustup |
| 92 | +# Point rustup at the system-wide installation, but let CARGO_HOME default to ~/.cargo |
| 93 | +ENV RUSTUP_HOME=/usr/local/rustup |
| 94 | +# Setup for codespaces |
| 95 | +COPY devenv-init.sh /usr/local/bin/ |
| 96 | + |
| 97 | +WORKDIR / |
| 98 | +# Create user before declaring volumes so home directory has correct ownership |
| 99 | +RUN <<EORUN |
| 100 | +set -xeuo pipefail |
| 101 | +useradd -m devenv -s /bin/bash |
| 102 | +# This needs to be precreated and owned by the devenv user |
| 103 | +mkdir -p ~devenv/.local/share/containers |
| 104 | +chown -R -h devenv: ~devenv/.local |
| 105 | +echo 'devenv ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/devenv && chmod 0440 /etc/sudoers.d/devenv |
| 106 | +EORUN |
| 107 | +# To avoid overlay-on-overlay with nested containers |
| 108 | +VOLUME [ "/var/lib/containers", "/home/devenv/.local/share/containers/" ] |
| 109 | +USER devenv |
0 commit comments