# syntax = docker/dockerfile:1.11-labs

FROM input AS smoke-version
COPY --link --from=input . .
RUN <<EOF
    set -eux
    tuwunel -V
    version=$(tuwunel -V)
    /bin/test -n "$version"
EOF


FROM input AS smoke-startup
COPY --link --from=input . .
ENV TUWUNEL_LOG="info"
ENV TUWUNEL_DATABASE_PATH="/tmp/smoketest.db"
RUN <<EOF
    set -eux
    tuwunel \
        -Otest='["smoke"]' \
        -Oserver_name=\"localhost\" \
        -Odatabase_path=\"${TUWUNEL_DATABASE_PATH}\"

    rm -rf "${TUWUNEL_DATABASE_PATH}"
EOF


FROM input AS smoke-valgrind
ARG leak_check="no"
ARG undef_value_errors="no"
ARG db_pool_max_workers=128
COPY --link --from=input . .
ENV TUWUNEL_LOG="info"
ENV TUWUNEL_DATABASE_PATH="/tmp/smoketest.db"
RUN <<EOF
    set -eux
    ulimit -n 65535
    valgrind \
        --leak-check=${leak_check} \
        --undef-value-errors=${undef_value_errors} \
        --exit-on-first-error=yes \
        --error-exitcode=1 \
        tuwunel \
            -Otest='["smoke"]' \
            -Oserver_name=\"localhost\" \
            -Odatabase_path=\"${TUWUNEL_DATABASE_PATH}\" \
            -Odb_pool_max_workers=${db_pool_max_workers}

    rm -rf "${TUWUNEL_DATABASE_PATH}"
EOF


FROM input AS smoke-perf
COPY --link --from=input . .
ENV TUWUNEL_LOG="error"
ENV TUWUNEL_DATABASE_PATH="/tmp/smoketest.db"
RUN <<EOF
    set -eux
    perf stat \
        -j \
        -ddd \
        tuwunel \
            -Otest='["smoke"]' \
            -Oserver_name=\"localhost\" \
            -Odatabase_path=\"${TUWUNEL_DATABASE_PATH}\"

    rm -rf "${TUWUNEL_DATABASE_PATH}"
EOF
