Skip to content

Commit

Permalink
Add comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
alee-ntap authored and nanory committed Oct 31, 2023
1 parent 9c63dea commit 961c64a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions crossbuild.containerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Use build arguments to specify the base image and architecture
ARG image=debian:testing
ARG native_arch=amd64
ARG target_arch=arm64v8

# Stage 1: Build and install mini_sudo
FROM $native_arch/$image AS mini_sudo
WORKDIR /tmp
COPY mini_sudo.c ./
Expand All @@ -11,6 +13,7 @@ RUN apt-get update \
&& gcc -Wall -Werror -static -o sudo mini_sudo.c \
&& install -m 6755 sudo /usr/local/bin/sudo

# Stage 2: Build setup_native
FROM $native_arch/$image AS native
ARG gnu_arch=aarch64
WORKDIR /tmp
Expand All @@ -22,10 +25,15 @@ RUN apt-get update \
&& ./setup_native export $(sed 's/\$arch/'"$gnu_arch"'/' pkgs \
| awk '{ print $NF }')

# Stage 3: Final image
FROM $target_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/

# Install packages from pkgs list and mark them as held
COPY pkgs ./
RUN mkdir /pkgs \
&& touch /pkgs/Packages \
Expand All @@ -34,16 +42,28 @@ RUN mkdir /pkgs \
--no-install-recommends -y build-essential ca-certificates debhelper \
devscripts git yq $(awk '{ print $1 }' pkgs) \
&& apt-mark hold $(awk '{ print $1 }' pkgs)

# Copy the native build artifacts from the previous stage
COPY --from=native /native /native

# Copy setup_native script and execute it
COPY setup_native ./
RUN [ "/native/bash", "-c", "PATH=/native:$PATH ./setup_native import $(awk '{ print $1 }' pkgs)" ]

# Test gcc and cleanup
RUN gcc --print-search-dir \
&& echo 'int main() { return 0; }' > main.c \
&& 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_archdep 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
Expand Down

0 comments on commit 961c64a

Please sign in to comment.