Dockerfile

 avatar
unknown
dockerfile
18 hours ago
7.2 kB
7
No Index
# Dev Workspace - Full development environment
# Ubuntu 24.04 + Python 3.12 + PHP 8.4 + Node.js 24 + Code-Server + Nginx

FROM ubuntu:24.04

LABEL maintainer="your-name"
LABEL description="Full Development Environment with Code-Server, PHP-FPM, Nginx"

# Environment variables
ENV DEBIAN_FRONTEND=noninteractive \
    TZ=Europe/Paris \
    LANG=en_US.UTF-8 \
    LANGUAGE=en_US:en \
    LC_ALL=en_US.UTF-8 \
    PIP_BREAK_SYSTEM_PACKAGES=1

# =============================================================================
# Base packages installation
# =============================================================================
RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends \
    # Essential tools
    software-properties-common \
    curl \
    wget \
    git \
    nano \
    vim \
    htop \
    tmux \
    tree \
    unzip \
    zip \
    jq \
    # Certificates and security
    ca-certificates \
    gnupg \
    lsb-release \
    apt-transport-https \
    # System
    sudo \
    cron \
    supervisor \
    locales \
    tzdata \
    openssh-client \
    # Web server
    nginx \
    # Build tools
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# Timezone and locales
RUN ln -fs /usr/share/zoneinfo/Europe/Paris /etc/localtime \
    && dpkg-reconfigure -f noninteractive tzdata \
    && locale-gen en_US.UTF-8 fr_FR.UTF-8 \
    && update-locale LANG=en_US.UTF-8

# =============================================================================
# Python 3.12+
# =============================================================================
RUN add-apt-repository ppa:deadsnakes/ppa -y \
    && apt-get update \
    && apt-get install -y --no-install-recommends \
        python3.12 \
        python3.12-venv \
        python3.12-dev \
        python3-pip \
    && update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 \
    && update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1 \
    && rm -rf /var/lib/apt/lists/*

# Pip and Python tools (PIP_BREAK_SYSTEM_PACKAGES=1 defined in ENV)
# --ignore-installed avoids conflicts with Debian-installed packages (e.g. pyparsing)
RUN pip3 install --no-cache-dir --ignore-installed \
        aider-chat \
        openai \
        python-telegram-bot \
        requests

# =============================================================================
# PHP 8.4+ with FPM
# =============================================================================
RUN add-apt-repository ppa:ondrej/php -y \
    && apt-get update \
    && apt-get install -y --no-install-recommends \
        php8.4-cli \
        php8.4-fpm \
        php8.4-common \
        php8.4-curl \
        php8.4-mbstring \
        php8.4-xml \
        php8.4-zip \
        php8.4-mysql \
        php8.4-pgsql \
        php8.4-sqlite3 \
        php8.4-redis \
        php8.4-gd \
        php8.4-intl \
        php8.4-bcmath \
        php8.4-imagick \
    && rm -rf /var/lib/apt/lists/*

# Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# =============================================================================
# Node.js 24+
# =============================================================================
RUN curl -fsSL https://deb.nodesource.com/setup_24.x | bash - \
    && apt-get install -y nodejs \
    && npm install -g npm@latest pnpm yarn \
    && rm -rf /var/lib/apt/lists/*

# =============================================================================
# GitHub CLI
# =============================================================================
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \
        -o /usr/share/keyrings/githubcli-archive-keyring.gpg \
    && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
        > /etc/apt/sources.list.d/github-cli.list \
    && apt-get update \
    && apt-get install -y gh \
    && rm -rf /var/lib/apt/lists/*

# =============================================================================
# Code-Server (VS Code in the browser)
# =============================================================================
RUN curl -fsSL https://code-server.dev/install.sh | sh

# =============================================================================
# Nginx configuration for previews
# =============================================================================
RUN echo 'server { \
    listen 80; \
    root /home/devuser/projects/public; \
    index index.php index.html; \
    location / { \
        try_files $uri $uri/ /index.php?$query_string; \
    } \
    location ~ \.php$ { \
        fastcgi_pass unix:/run/php/php8.4-fpm.sock; \
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; \
        include fastcgi_params; \
    } \
}' > /etc/nginx/sites-available/default

# =============================================================================
# Create devuser with sudo
# =============================================================================
RUN useradd -m -s /bin/bash -G sudo devuser \
    && echo "devuser ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/devuser \
    && chmod 0440 /etc/sudoers.d/devuser

# Global git configuration for the development user
RUN su - devuser -c "git config --global init.defaultBranch main" \
    && su - devuser -c "git config --global pull.rebase false"

# =============================================================================
# Create folders and set permissions
# =============================================================================
RUN mkdir -p /home/devuser/projects /bot-data \
    /var/log/supervisor \
    /var/log/nginx \
    /run/php \
    && chmod -R 777 /bot-data /var/log \
    && chown -R devuser:devuser /home/devuser/projects

# =============================================================================
# Supervisor configuration
# =============================================================================
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# =============================================================================
# Entrypoint (environment initialization)
# =============================================================================
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# =============================================================================
# Exposed ports
# =============================================================================
# 8080 = Code-Server (IDE)
# 80   = Nginx (Laravel preview)
# 8000 = php artisan serve
# 3000 = Node.js apps
# 5173 = Vite dev server
EXPOSE 8080 80 8000 3000 5173

# Volumes (user home persisted to keep gh auth, git config, ssh keys, projects, etc.)
VOLUME ["/bot-data", "/home/devuser"]

# Workdir
WORKDIR /home/devuser/projects

# Healthcheck
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
    CMD curl -f http://localhost:8080/healthz || exit 1

# Start via entrypoint (which launches supervisord)
ENTRYPOINT ["/entrypoint.sh"]
Editor is loading...
Leave a Comment