FROM ubuntu:24.04 AS builder

ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8

# Install build dependencies
RUN apt-get update \
    && apt-get install -y --no-install-recommends build-essential \
    && rm -rf /var/lib/apt/lists/*

# Build readflag
WORKDIR /build
COPY readflag.c .
RUN gcc -o readflag -static readflag.c

FROM ubuntu:24.04 AS runtime

# Install runtime dependencies
RUN apt-get update \
    && apt-get install -y sudo socat \
    && rm -rf /var/lib/apt/lists/*

# Challenge & flag files
COPY --from=builder --chown=root:root /build/readflag /readflag
COPY --chown=root:root flag.txt /flag.txt
RUN chmod +s /readflag \
    && chmod 400 /flag.txt
COPY --chown=root:root run.sh challenge libc.so.6 /app/

WORKDIR /app
CMD ["/app/run.sh"]
