# Use an official PHP runtime as a parent image
FROM php:7.4-fpm

# Set the working directory
WORKDIR /workspace

# Install dependencies
RUN apt-get update && apt-get install -y \
    git \
    openssh-client \
    unzip \
    procps \
    iputils-ping \
    default-mysql-client \
    libpng-dev \
    libjpeg-dev \
    libfreetype6-dev \
    libonig-dev \
    libzip-dev \
    libpq5 \
    libpq-dev \
    libicu-dev \
    zip \
    fish \
    cron \
    sudo \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install gd mbstring zip pdo pdo_mysql mysqli pdo_pgsql pgsql intl

# Install Redis PHP extension via PECL
RUN apt-get update && apt-get install -y --no-install-recommends $PHPIZE_DEPS libssl-dev \
    && pecl install redis \
    && docker-php-ext-enable redis \
    && apt-get purge -y --auto-remove $PHPIZE_DEPS libssl-dev \
    && rm -rf /var/lib/apt/lists/*

# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

RUN git clone https://gitea.bramkelchtermans.be/Bram/linux-presets.git && \
    cd linux-presets && \
    chmod +x setup.sh && \
    ./setup.sh --terminal-icon 󰎙 && \
    cd .. && \
    rm -rf linux-presets


RUN usermod -aG sudo root

# Install Node.js and npm
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - && \
    apt-get install -y nodejs

# Install PM2 globally
RUN npm install -g pm2

# # Switch to Fish shell
# SHELL [ "fish", "--command" ]
# RUN chsh -s /usr/bin/fish
# ENV SHELL /usr/bin/fish
# ENV LANG=C.UTF-8 LANGUAGE=C.UTF-8 LC_ALL=C.UTF-8


# Create a directory for the SSH keys
RUN mkdir -p /root/.ssh

# Copy the entrypoint script into the container
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

# Copy the crontab file into the container
COPY crontab /etc/cron.d/laravel-cron
RUN chmod 0644 /etc/cron.d/laravel-cron
RUN crontab /etc/cron.d/laravel-cron

# Expose ports
EXPOSE 8000

# Set the entrypoint
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
