-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Draft] Cross-compilation MVP #36066
base: master
Are you sure you want to change the base?
Changes from 15 commits
0abcc75
de0e34c
ea8f7bf
86d8fef
cc4de2f
bc47563
56cd062
b98d2db
cc794b7
f53f677
1c574ad
fe311cd
4f9200e
691e0a6
4aa3cab
7b78274
2c793b4
6250d29
b41db8b
1468a97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
FROM ubuntu:22.04 | ||
|
||
# Install dependencies | ||
RUN apt-get update && apt-get install -y \ | ||
Check warning on line 4 in build.assets/Dockerfile-build Orca Security (US) / Orca Security - Infrastructure as Code[INFO] APT-GET Not Avoiding Additional Packages
|
||
autoconf \ | ||
automake \ | ||
autopoint \ | ||
bison \ | ||
flex \ | ||
libtool \ | ||
sed \ | ||
w3m \ | ||
xsltproc \ | ||
xz-utils \ | ||
cmake \ | ||
gettext \ | ||
git \ | ||
make \ | ||
pkg-config \ | ||
wget \ | ||
curl \ | ||
clang-12 \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install Go | ||
ARG GOLANG_VERSION | ||
RUN mkdir -p /opt && cd /opt && curl -fsSL https://storage.googleapis.com/golang/${GOLANG_VERSION}.linux-amd64.tar.gz | tar xz && \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Version is pinned, but we could use a checksum here to validate the tarball is what we expect. This isn't super important as we have a higher level of trust for Google and golang distribution. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is PoC, and this code has a lot of bad practices. Versions are not pinned, the repositories are GH mirrors instead of the official. Code is built from |
||
/opt/go/bin/go version | ||
ENV GOPATH="/home/ubuntu/go" \ | ||
GOROOT="/opt/go" \ | ||
PATH="/opt/go/bin:$PATH" | ||
|
||
# Create a non-root user with id 1000 - ubuntu | ||
RUN useradd -m -u 1000 ubuntu | ||
USER ubuntu | ||
WORKDIR /home/ubuntu | ||
|
||
# Install Rust | ||
ARG RUST_VERSION | ||
ENV PATH=/home/ubuntu/.cargo/bin:$PATH | ||
RUN curl --proto '=https' --tlsv1.2 -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain $RUST_VERSION && \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd recommend we vendor the shell script and checksum the resulting binary that it fetches. This is probably the worst offender IMO. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I copied this from our "production" code 🙈 |
||
rustup --version && \ | ||
cargo --version && \ | ||
rustc --version && \ | ||
rustup target add x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu i686-unknown-linux-gnu armv7-unknown-linux-gnueabi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Base on https://github.com/crosstool-ng/crosstool-ng/blob/8825cfc2abf696395bd27bd0e7cea3653004280b/testing/docker/ubuntu22.04/Dockerfile | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably need to check with the open source group, but if this dockerfile is based on that link then we may need to include a GPL license header with copyright listed as crosstool-ng |
||
FROM ubuntu:22.04 as ct-ng | ||
|
||
ARG CTNG_UID=1000 | ||
ARG CTNG_GID=1000 | ||
|
||
RUN groupadd -g $CTNG_GID ctng | ||
Check warning on line 7 in build.assets/Dockerfile-ct-ng Orca Security (US) / Orca Security - Infrastructure as Code[LOW] Multiple RUN, ADD, COPY, Instructions Listed
|
||
RUN useradd -d /home/ctng -m -g $CTNG_GID -u $CTNG_UID -s /bin/bash ctng | ||
|
||
# Non-interactive configuration of tzdata | ||
ENV DEBIAN_FRONTEND noninteractive | ||
ENV DEBCONF_NONINTERACTIVE_SEEN true | ||
RUN { echo 'tzdata tzdata/Areas select Etc'; echo 'tzdata tzdata/Zones/Etc select UTC'; } | debconf-set-selections | ||
|
||
RUN apt-get update | ||
Check warning on line 15 in build.assets/Dockerfile-ct-ng Orca Security (US) / Orca Security - Infrastructure as Code[INFO] Update Instruction Alone
|
||
RUN apt-get install -y gcc g++ gperf bison flex texinfo help2man make libncurses5-dev \ | ||
Check warning on line 16 in build.assets/Dockerfile-ct-ng Orca Security (US) / Orca Security - Infrastructure as Code[INFO] APT-GET Not Avoiding Additional Packages
Check warning on line 16 in build.assets/Dockerfile-ct-ng Orca Security (US) / Orca Security - Infrastructure as Code[INFO] Apt Get Install Lists Were Not Deleted
|
||
python3-dev autoconf automake libtool libtool-bin gawk wget bzip2 xz-utils unzip \ | ||
patch libstdc++6 rsync git meson ninja-build | ||
|
||
USER ctng | ||
WORKDIR /home/ctng | ||
|
||
RUN wget https://github.com/crosstool-ng/crosstool-ng/releases/download/crosstool-ng-1.26.0/crosstool-ng-1.26.0.tar.bz2 && \ | ||
Check warning on line 23 in build.assets/Dockerfile-ct-ng Orca Security (US) / Orca Security - Infrastructure as Code[MEDIUM] RUN Instruction Using 'cd' Instead of WORKDIR
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd recommend we verify the checksum of this tarball. This isn't as important because we have a pinned release (can be overwritten afaik) and can probably trust GitHub/Microsoft to not get hacked. We're more protecting against the crosstools-ng org/user being compromised. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
tar xf crosstool-ng-1.26.0.tar.bz2 && \ | ||
cd crosstool-ng-1.26.0 && \ | ||
./bootstrap && \ | ||
./configure --prefix=/home/ctng/.local/ct-ng && \ | ||
make -j$(nproc) && \ | ||
make install && \ | ||
cd .. && \ | ||
rm -rf crosstool-ng-1.26.0 crosstool-ng-1.26.0.tar.bz2 | ||
|
||
ENV PATH="/home/ctng/.local/ct-ng/bin:$PATH" | ||
|
||
RUN mkdir -p /home/ctng/build/amd64 && \ | ||
mkdir -p /home/ctng/build/i686 && \ | ||
mkdir -p /home/ctng/build/arm64 && \ | ||
mkdir -p /home/ctng/build/arm && \ | ||
mkdir -p /home/ctng/src | ||
COPY ./ct-ng-configs/amd64.config /home/ctng/build/amd64/.config | ||
COPY ./ct-ng-configs/i686.config /home/ctng/build/i686/.config | ||
COPY ./ct-ng-configs/arm64.config /home/ctng/build/arm64/.config | ||
COPY ./ct-ng-configs/arm.config /home/ctng/build/arm/.config | ||
|
||
WORKDIR /home/ctng/build | ||
|
||
# | ||
#FROM ubuntu:22.04 | ||
# | ||
## Create a non-root user with id 1000 - ubuntu | ||
#RUN useradd -m -u 1000 ubuntu | ||
#USER ubuntu | ||
#WORKDIR /home/ubuntu | ||
# | ||
#COPY --from=ct-ng /home/ctng/x-tools /home/ubuntu/x-tools | ||
Comment on lines
+47
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a nice 2-phase build. I'm curious as to why you've commented it out? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forgot to remove. The idea is simple:
For some reason, when I tried to build the cross-compiler as a part of |
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
mkdir -p toolchains | ||
DOCKER_BUILDKIT=0 BUILDKIT_PROGRESS=plain docker build -t teleport-builder-base -f Dockerfile-ct-ng . | ||
|
||
docker volume create toolchain | ||
|
||
docker run --rm -v toolchain:/toolchain busybox \ | ||
/bin/sh -c 'touch /toolchain/.initialized && chown -R 1000:1000 /toolchain' | ||
|
||
docker volume create 3rdparty | ||
|
||
docker run --rm -v 3rdparty:/3rdparty busybox \ | ||
/bin/sh -c 'chown -R 1000:1000 /3rdparty' | ||
|
||
docker run -v toolchain:/home/ctng/x-tools --rm docker.io/library/teleport-builder-base bash -c "cd amd64 && ct-ng build" | ||
docker run -v toolchain:/home/ctng/x-tools --rm docker.io/library/teleport-builder-base bash -c "cd i686 && ct-ng build" | ||
docker run -v toolchain:/home/ctng/x-tools --rm docker.io/library/teleport-builder-base bash -c "cd arm64 && ct-ng build" | ||
docker run -v toolchain:/home/ctng/x-tools --rm docker.io/library/teleport-builder-base bash -c "cd arm && ct-ng build" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some docs/comments on what this dockerfile and the other do? We have so many under
build.assets/**
that I don't even know what they all do anymore.