# Builder stage FROM public.ecr.aws/amazonlinux/amazonlinux:2023 as builder # Install necessary build tools RUN dnf install -y wget tar gzip git cmake3 make autoconf automake which \ libtool xz which perl-core perl-FindBin && \ dnf clean all # Install Zig RUN wget https://ziglang.org/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz && \ tar -xf zig-linux-x86_64-0.13.0.tar.xz && \ mv zig-linux-x86_64-0.13.0 /usr/local/zig && \ rm zig-linux-x86_64-0.13.0.tar.xz ENV PATH="/usr/local/zig:${PATH}" # Set up the workspace WORKDIR /app ADD . /app RUN mkdir /app/dependencies # Set Zig as the compiler with correct flags for musl ENV CC="zig cc -target x86_64-linux-musl" ENV CXX="zig c++ -target x86_64-linux-musl" ENV CFLAGS="-fPIC -static" ENV CXXFLAGS="-fPIC -static" ENV LDFLAGS="-static" # Build zlib RUN cd /app/dependencies && \ wget https://github.com/madler/zlib/archive/v1.2.13.tar.gz -O /tmp/zlib-1.2.13.tar.gz && \ tar xzvf /tmp/zlib-1.2.13.tar.gz && \ cd zlib-1.2.13 && \ CFLAGS="-fPIC" ./configure --static --prefix=/usr && \ make -j$(nproc) && \ make install # Build Boost RUN cd /app/dependencies && \ wget https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.tar.gz && \ tar xzvf boost_1_81_0.tar.gz && \ cd boost_1_81_0 && \ ./bootstrap.sh && \ ./b2 install link=static cxxflags=-fPIC cflags=-fPIC # Build Protocol Buffers RUN cd /app/dependencies && \ wget https://github.com/protocolbuffers/protobuf/releases/download/v3.17.3/protobuf-cpp-3.17.3.tar.gz && \ tar xzvf protobuf-cpp-3.17.3.tar.gz && \ cd protobuf-3.17.3 && \ ./configure --disable-shared --enable-static --prefix=/usr --with-pic && \ make -j$(nproc) && \ make install # Build OpenSSL RUN cd /app/dependencies && \ wget https://www.openssl.org/source/openssl-1.1.1l.tar.gz && \ tar -xzf openssl-1.1.1l.tar.gz && \ cd openssl-1.1.1l && \ ./config no-shared --prefix=/usr --openssldir=/usr/lib -fPIC && \ make -j$(nproc) && \ make install # Build localproxy RUN cd /app && \ mkdir -p build && \ cd build && \ cmake -DBOOST_ROOT=/usr \ -DCMAKE_CXX_FLAGS="-target x86_64-linux-musl -static -fPIC -std=c++17" \ -DCMAKE_EXE_LINKER_FLAGS="${LDFLAGS}" \ -DCMAKE_STATIC_LINKER_FLAGS="${LDFLAGS}" \ -DCMAKE_CXX_STANDARD=17 \ -DCMAKE_CXX_STANDARD_REQUIRED=ON \ -DCMAKE_BUILD_TYPE=Release \ -DOPENSSL_ROOT_DIR=/usr \ -DOPENSSL_USE_STATIC_LIBS=TRUE \ -DCMAKE_CXX_FLAGS_INIT="-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST" \ .. && \ make -j$(nproc) VERBOSE=1 && \ strip bin/localproxy # Deploy stage FROM public.ecr.aws/amazonlinux/amazonlinux:2023-minimal COPY --from=builder /app/build/bin/localproxy /usr/bin/localproxy ENTRYPOINT ["/usr/bin/localproxy"]