FROM alpine AS mirror

RUN mkdir -p /out/etc/apk/ && \
    cp /etc/apk/repositories /out/etc/apk/ && \
    cp -r /etc/apk/keys /out/etc/apk/keys

RUN apk add --no-cache \
    gcc \
    linux-headers \
    mdocml-apropos \
    musl-dev

RUN apk add --no-cache --initdb -p /out \
    alpine-baselayout \
    beep \
    bind-doc \
    bind-tools \
    busybox \
    ca-certificates \
    curl \
    curl-doc \
    e2fsprogs \
    ethtool \
    ethtool-doc \
    fbida-fbi \
    fbida-doc \
    htop \
    htop-doc \
    iproute2 \
    iproute2-doc \
    jq \
    kbd \
    kbd-bkeymaps \
    kbd-doc \
    kbd-vlock \
    man \
    man-pages \
    musl \
    nano \
    openntpd \
    openntpd-doc \
    openssh-client \
    openssh-doc \
    openssh-keygen \
    pciutils \
    pciutils-doc \
    ssmtp \
    ssmtp-doc \
    tcpdump \
    tcpdump-doc \
    testdisk \
    testdisk-doc \
    tini \
    ttf-inconsolata \
    util-linux \
    util-linux-doc \
    wireguard-tools-wg \
    wireguard-tools-doc

RUN makewhatis /out/usr/share/man

RUN rm -rf /out/etc/inittab

COPY kp.c /root/kp.c
RUN gcc -o /out/usr/bin/init-crypto /root/kp.c


FROM scratch

COPY --from=mirror /out/ /

COPY ssl/ec_cert.pem /usr/share/ca-certificates/nemunai.re/cert.pem
RUN echo "nemunai.re/cert.pem" >> /etc/ca-certificates.conf && update-ca-certificates

COPY lib/ /lib/
