FROM node:lts-bookworm-slim



# Update everything and install needed dependencies
RUN apt-get update -y && \
    apt-get upgrade -y && \
    apt-get install -y -q \
        graphicsmagick \
        tzdata \
        curl \ 
        zip \
        unzip \
        jq \
        sed \
        python3 \
        ca-certificates \
        build-essential    

# Install n8n and the also temporary all the packages
# it needs to build it correctly.
#RUN N8N_VERSION=$(curl -s https://api.github.com/repos/n8n-io/n8n/releases/latest | jq -r '.tag_name' | sed 's/^v//') && \
RUN N8N_VERSION=n8n@2.11.3 && \
    echo "Latest n8n version: ${N8N_VERSION}" && \
    npm_config_user=root npm install -g \
        ${N8N_VERSION} && \   
    apt-get remove -y build-essential && \
    apt-get autoremove -y && \
    apt-get clean all

# Set a custom user to not have n8n run as root
USER node

WORKDIR /data

CMD ["n8n"]
