FROM ubuntu:24.04

LABEL maintainer="homelab"
LABEL description="Ansible Act Runner - Custom Image"

ENV DEBIAN_FRONTEND=noninteractive
ENV NODE_VERSION=20
ENV ANSIBLE_FORCE_COLOR=1
ENV PIP_NO_CACHE_DIR=1

ARG ACT_RUNNER_VERSION=0.2.11

RUN apt-get update && apt-get install -y --no-install-recommends \
    -o Dpkg::Options::="--force-confnew" \
    curl \
    wget \
    git \
    ca-certificates \
    gnupg \
    unzip \
    jq \
    rsync \
    openssh-client \
    sshpass \
    python3 \
    python3-pip \
    python3-venv \
    python3-dev \
    smbclient \
    krb5-user \
    libkrb5-dev \
    python3-kerberos \
    dnsutils \
    build-essential \
    libssl-dev \
    libffi-dev \
    && rm -rf /var/lib/apt/lists/*

# Node.js 20 LTS
RUN curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash - \
    && apt-get install -y --no-install-recommends nodejs \
    && rm -rf /var/lib/apt/lists/*

# act_runner binary
RUN curl -fsSL \
    https://gitea.com/gitea/act_runner/releases/download/v${ACT_RUNNER_VERSION}/act_runner-${ACT_RUNNER_VERSION}-linux-amd64 \
    -o /usr/local/bin/act_runner \
    && chmod +x /usr/local/bin/act_runner

# Ansible + pip packages
RUN python3 -m pip install --break-system-packages \
    ansible-core \
    ansible \
    jmespath \
    netaddr \
    passlib \
    cryptography \
    pywinrm \
    requests \
    boto3

# Ansible Collections
RUN ansible-galaxy collection install \
    community.general \
    community.crypto \
    ansible.posix \
    kubernetes.core \
    community.windows \
    microsoft.ad

RUN useradd -m -s /bin/bash runner

WORKDIR /data

# Smoke tests
RUN node --version \
    && python3 --version \
    && ansible --version \
    && act_runner --version
