|
|
|
FROM python:3.10-slim AS builder
|
|
|
|
|
|
ARG requirements
|
|
ARG NODEJS_VER=20
|
|
ARG PACKAGES=n8n
|
|
ARG WORKDIR=/app
|
|
ARG DUMP_URL
|
|
ARG DUMP_PASSWORD
|
|
|
|
|
|
RUN apt-get update && apt-get install -y curl gnupg build-essential && \
|
|
curl -fsSL https://deb.nodesource.com/setup_${NODEJS_VER}.x | bash - && \
|
|
apt-get install -y nodejs && \
|
|
npm install -g ${PACKAGES} && \
|
|
apt-get clean && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
ENV VIRTUAL_ENV=/opt/venv
|
|
RUN python3 -m venv $VIRTUAL_ENV && \
|
|
$VIRTUAL_ENV/bin/pip install --upgrade pip && \
|
|
$VIRTUAL_ENV/bin/pip install ${requirements:-requests}
|
|
|
|
|
|
FROM postgres:latest
|
|
|
|
|
|
ARG POSTGRES_USER=n8n
|
|
ARG POSTGRES_PASSWORD=n8n
|
|
ARG POSTGRES_DB=n8n
|
|
ARG WEBHOOK_URL=https://aigenai-db.hf.space/
|
|
ARG WORKDIR=/app
|
|
ARG DB_IMPORT=no
|
|
|
|
|
|
ENV N8N_HOST=0.0.0.0 \
|
|
N8N_PORT=7860 \
|
|
N8N_PROTOCOL=https \
|
|
WEBHOOK_URL=${WEBHOOK_URL} \
|
|
GENERIC_TIMEZONE=Asia/Shanghai \
|
|
N8N_METRICS=true \
|
|
QUEUE_HEALTH_CHECK_ACTIVE=true \
|
|
N8N_PAYLOAD_SIZE_MAX=256
|
|
|
|
|
|
ENV DB_TYPE=postgresdb \
|
|
DB_POSTGRESDB_HOST=localhost \
|
|
DB_POSTGRESDB_PORT=5432 \
|
|
DB_POSTGRESDB_USER=${POSTGRES_USER} \
|
|
DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD} \
|
|
DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
|
|
|
|
|
|
ENV VIRTUAL_ENV=/opt/venv \
|
|
PATH="$VIRTUAL_ENV/bin:$PATH"
|
|
|
|
|
|
COPY --from=builder /usr/local/bin/node /usr/local/bin/node
|
|
COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules
|
|
COPY --from=builder $VIRTUAL_ENV $VIRTUAL_ENV
|
|
|
|
|
|
RUN apt-get update && apt-get install -y \
|
|
curl unzip gnupg build-essential sudo vim git procps lsof net-tools \
|
|
ca-certificates openssl tzdata python3-venv gosu \
|
|
htop jq wget && \
|
|
ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
|
|
dpkg-reconfigure --frontend noninteractive tzdata
|
|
|
|
|
|
WORKDIR ${WORKDIR}
|
|
COPY run.sh ${WORKDIR}/run.sh
|
|
RUN chmod +x ${WORKDIR}/run.sh
|
|
|
|
|
|
USER root
|
|
RUN usermod -u 1000 postgres && groupmod -g 1000 postgres && \
|
|
chown -R postgres:postgres /var/lib/postgresql && \
|
|
chown -R postgres:postgres /var/run/postgresql
|
|
|
|
|
|
USER postgres
|
|
RUN initdb -D /var/lib/postgresql/data && \
|
|
pg_ctl start -D /var/lib/postgresql/data && \
|
|
psql --command "CREATE ROLE $POSTGRES_USER WITH LOGIN SUPERUSER PASSWORD '$POSTGRES_PASSWORD';" && \
|
|
createdb -O $POSTGRES_USER $POSTGRES_DB && \
|
|
pg_ctl stop -D /var/lib/postgresql/data
|
|
|
|
|
|
COPY dump.sql /docker-entrypoint-initdb.d/
|
|
|
|
|
|
COPY import-db.sh /docker-entrypoint-initdb.d/
|
|
RUN chmod +x /docker-entrypoint-initdb.d/import-db.sh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HEALTHCHECK --interval=120s --timeout=10s --start-period=10s --retries=3 \
|
|
CMD curl -f http://localhost:7860/HEALTHZ || exit 1
|
|
|
|
|
|
CMD ["./run.sh"]
|
|
|