diff --git a/build.containerfile b/build.containerfile index bdf2b78..3e3a830 100755 --- a/build.containerfile +++ b/build.containerfile @@ -1,6 +1,8 @@ +# Use build arguments to specify the base image and architecture ARG image=debian:testing ARG arch=amd64 +# Stage 1: Build and install mini_sudo FROM $arch/$image AS mini_sudo WORKDIR /tmp COPY mini_sudo.c ./ @@ -10,12 +12,21 @@ RUN apt-get update \ && gcc -Wall -Werror -static -o sudo mini_sudo.c \ && install -m 6755 sudo /usr/local/bin/sudo +# Stage 2: Final image FROM $arch/$image WORKDIR /tmp + +# Copy repository configration files for apt COPY debian-src.sources local-pkgs.list /etc/apt/sources.list.d/ COPY local-pkgs /etc/apt/preferences.d/ + +# Create a directory for local packages and touch the Packages file RUN mkdir /pkgs && touch /pkgs/Packages + +# Copy the package list file COPY pkgs ./ + +# Install packages from pkgs list and mark them as held, test gcc and cleanup RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install \ --no-install-recommends -y build-essential ca-certificates \ @@ -25,8 +36,14 @@ RUN apt-get update \ && gcc -o main main.c && ./main \ && find /tmp -mindepth 1 -delete + +# Copy the build scripts to /usr/local/bin COPY build_source build_indep build_archde build /usr/local/bin/ + +# Copy mini_sudo from stage 1 COPY --from=mini_sudo /usr/local/bin/sudo /usr/local/bin/sudo + +# Create user dev and set the working directory for the user RUN groupadd dev && useradd -m -g dev dev USER dev RUN mkdir /home/dev/work