# syntax=docker/dockerfile:1
# OpenWrt 23.05.6 x86_64 testbed image.
#
# Built from the official OpenWrt 23.05.6 rootfs tarball (downloads.openwrt.org)
# + a small set of .ipk packages from the 23.05.6 feeds:
#   - lua + liblua5.1.5 (Lua 5.1.5 — OpenWrt's base lua package is
#     still 5.1, NOT 5.4)
#   - openssl-util + libopenssl3 + ca-bundle (sha256.lua uses `openssl dgst`)
#
# .ipk files are ar archives (busybox tar can't read them), so they are
# pre-extracted on the host into ipk-extract/ (see download-2305.sh) and
# simply COPYed into the image.
#
# Build (from balancer-lite-lua/testbed):
#   docker build -f Dockerfile-2305 -t openwrt-testbed-2305:latest .
#
# Run with the standard openwrt-testbed skill scripts via env override:
#   OPENWRT_TESTBED_NAME=openwrt-testbed-2305 \
#   OPENWRT_TESTBED_IMAGE=openwrt-testbed-2305:latest \
#   skills/openwrt-testbed/scripts/start.sh
#
# Note: this image is NOT the skill's default image. The skill's 19.07
# Dockerfile (shellspec/openwrt + luasocket) is left untouched.

FROM scratch

# Official 23.05.6 x86_64 rootfs (pre-extracted on the host; see
# download-2305.sh). Extracted as ./ into the image root.
COPY rootfs/ /

# Pre-extracted package payloads (lua, liblua5.1.5, openssl-util,
# libopenssl3, ca-bundle) from the 23.05.6 feeds.
COPY ipk-extract/ /

# Lua paths + workspace for test fixtures. OpenWrt's Lua binary
# doesn't include versioned paths in its compiled-in package.path,
# so export them via profile.d (the test driver also sets them
# inline in every docker exec).
RUN mkdir -p /var/lock /var/run /tmp /etc/profile.d /testbed \
    && rm -rf /var/opkg-lists/* \
    && echo 'export LUA_PATH="/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua;;"' > /etc/profile.d/lua-paths.sh \
    && echo 'export LUA_CPATH="/usr/lib/lua/5.1/?.so;/usr/lib/lua/?.so;;"' >> /etc/profile.d/lua-paths.sh

# NB: busybox's `sleep` doesn't understand "infinity" — use 1 year.
CMD ["sleep", "31536000"]
