
# Base image
FROM php:8.1-apache

# Install system packages
RUN apt-get update && apt-get install -y --no-install-recommends \
    # Nginx
    #redis-server 
    nginx \
    # Process supervisor
    supervisor \
    # Others
    net-tools  \
    # Clean up
    && rm -rf /var/lib/apt/lists/*

# Install Node.js LTS 18.x
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
    && apt-get update && apt-get install -y nodejs \
    && rm -rf /var/lib/apt/lists/*

# copy the config file
COPY cosmostat_settings.yaml /app/cosmostat_settings.yaml

# Node on 3000
WORKDIR /usr/src/app
COPY web/node_server/ .
#COPY cosmostat_settings.yaml /usr/src/app/cosmostat_settings.yaml
RUN npm install --only=production

# Apache on 8080
COPY apache_ports.conf /etc/apache2/ports.conf
COPY apache_vhost.conf /etc/apache2/sites-available/000-default.conf
COPY web/html/ /var/www/html/

# nginx on 80
RUN rm -rf /etc/nginx/sites-enabled/default 
COPY web/proxy/nginx.conf /etc/nginx/conf.d/default.conf

# Add supervisord configuration
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Expose ports
EXPOSE 80
#EXPOSE 6379

# healthcheck looks for apache
HEALTHCHECK CMD netstat -ltn | grep -c ":8080" > /dev/null; if [ 0 != $? ]; then exit 1; fi;

# Start supervisord
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]