FROM node:20-alpine

# Install system deps
RUN apk add --no-cache \
    nginx \
    git \
    bash \
    curl \
    openssl

# Install PM2 globally
RUN npm install -g pm2

# Create directories
RUN mkdir -p /home/deploy/projects \
             /home/deploy/scripts \
             /etc/nginx/sites-dynamic \
             /var/log/nginx \
             /run/nginx

# Copy scripts
COPY scripts/ /home/deploy/scripts/
RUN chmod +x /home/deploy/scripts/*.sh

# Copy nginx base config
COPY nginx/nginx.conf /etc/nginx/nginx.conf

WORKDIR /home/deploy

EXPOSE 80

CMD ["/home/deploy/scripts/start.sh"]
