# ============================================
# Echo Server 扩展镜像
# 基于 sandbox-all-in-one 镜像进行扩展
# ============================================

FROM serverless-registry.cn-hangzhou.cr.aliyuncs.com/functionai/sandbox-all-in-one:v0.9.29

LABEL layer="echoserver-extension"
LABEL description="Echo Server extension based on All-in-One"
LABEL maintainer="Your Team"

USER root

# 复制 Echo Server Python 脚本
COPY echo_server.py /usr/local/bin/echo_server.py
RUN chmod +x /usr/local/bin/echo_server.py

# Process Compose 配置：放入配置目录后，必须显式登记到静态加载列表
COPY config/process-compose.echoserver.yaml /etc/sandbox/config/process-compose.echoserver.yaml
RUN grep -qxF '/etc/sandbox/config/process-compose.echoserver.yaml' /etc/sandbox/process-compose-files.txt || \
    printf '%s\n' '/etc/sandbox/config/process-compose.echoserver.yaml' >> /etc/sandbox/process-compose-files.txt

# Nginx 配置：复制到 OpenResty 实际加载目录
RUN mkdir -p /usr/local/openresty/nginx/conf/http.d /usr/local/openresty/nginx/conf/conf.d
COPY config/nginx-echoserver-upstream.conf /usr/local/openresty/nginx/conf/http.d/echoserver-upstream.conf
COPY config/nginx-echoserver-routes.conf /usr/local/openresty/nginx/conf/conf.d/echoserver-routes.conf

# 环境变量
ENV ECHO_SERVER_HOST=0.0.0.0 \
    ECHO_SERVER_PORT=9000

# 主端口 5000 已经在 all-in-one 中暴露

# 使用入口脚本启动
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["process-compose", "up", "--tui=false", "--no-server"]
