# =============================================================================
# DevOps Toolbox - Demonstração de eStargz
# =============================================================================
# Imagem grande (~650MB) com múltiplas ferramentas em camadas separadas.
# Ideal para demonstrar lazy pulling: você só usa UMA ferramenta por vez!
# =============================================================================

FROM alpine:3.21

LABEL maintainer="workshop"
LABEL description="DevOps toolbox for eStargz lazy pulling demonstration"

# -----------------------------------------------------------------------------
# Camada 1: Ferramentas básicas (~50MB)
# -----------------------------------------------------------------------------
RUN apk add --no-cache \
    bash \
    curl \
    wget \
    jq \
    git \
    openssh-client \
    ca-certificates \
    unzip

# -----------------------------------------------------------------------------
# Camada 2: Terraform (~100MB)
# -----------------------------------------------------------------------------
ARG TERRAFORM_VERSION=1.9.8
ARG TARGETARCH
RUN wget -q "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_${TARGETARCH}.zip" -O /tmp/terraform.zip && \
    unzip -q /tmp/terraform.zip -d /usr/local/bin/ && \
    rm /tmp/terraform.zip && \
    chmod +x /usr/local/bin/terraform

# -----------------------------------------------------------------------------
# Camada 3: OpenTofu (~100MB)
# -----------------------------------------------------------------------------
ARG TOFU_VERSION=1.8.8
RUN wget -q "https://github.com/opentofu/opentofu/releases/download/v${TOFU_VERSION}/tofu_${TOFU_VERSION}_linux_${TARGETARCH}.zip" -O /tmp/tofu.zip && \
    unzip -q /tmp/tofu.zip -d /usr/local/bin/ && \
    rm /tmp/tofu.zip && \
    chmod +x /usr/local/bin/tofu

# -----------------------------------------------------------------------------
# Camada 4: Kubectl (~50MB)
# -----------------------------------------------------------------------------
ARG KUBECTL_VERSION=1.31.4
RUN curl -sLO "https://dl.k8s.io/release/v${KUBECTL_VERSION}/bin/linux/${TARGETARCH}/kubectl" && \
    chmod +x kubectl && \
    mv kubectl /usr/local/bin/

# -----------------------------------------------------------------------------
# Camada 5: Helm (~50MB)
# -----------------------------------------------------------------------------
ARG HELM_VERSION=3.16.4
RUN wget -q "https://get.helm.sh/helm-v${HELM_VERSION}-linux-${TARGETARCH}.tar.gz" -O /tmp/helm.tar.gz && \
    tar -xzf /tmp/helm.tar.gz -C /tmp && \
    mv /tmp/linux-${TARGETARCH}/helm /usr/local/bin/ && \
    rm -rf /tmp/helm.tar.gz /tmp/linux-${TARGETARCH}

# -----------------------------------------------------------------------------
# Camada 6: AWS CLI (~200MB)
# -----------------------------------------------------------------------------
RUN apk add --no-cache aws-cli

# -----------------------------------------------------------------------------
# Camada 7: Python + Ansible (~150MB)
# -----------------------------------------------------------------------------
RUN apk add --no-cache python3 py3-pip && \
    pip3 install --no-cache-dir ansible --break-system-packages --quiet

# -----------------------------------------------------------------------------
# Camada 8: k9s (~50MB)
# -----------------------------------------------------------------------------
ARG K9S_VERSION=0.32.7
RUN wget -q "https://github.com/derailed/k9s/releases/download/v${K9S_VERSION}/k9s_Linux_${TARGETARCH}.tar.gz" -O /tmp/k9s.tar.gz && \
    tar -xzf /tmp/k9s.tar.gz -C /usr/local/bin/ k9s && \
    rm /tmp/k9s.tar.gz

# -----------------------------------------------------------------------------
# Entrypoint
# -----------------------------------------------------------------------------
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

WORKDIR /workspace

ENTRYPOINT ["/entrypoint.sh"]
CMD ["--help"]
