File size: 2,855 Bytes
8b62d8e
c1e6772
 
8b62d8e
 
b5152f1
 
 
 
8b62d8e
c1e6772
 
 
 
9546862
c1e6772
 
8b62d8e
c1e6772
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2b8a16d
c1e6772
 
1aae828
c1e6772
 
8b62d8e
7f298d5
ffb1970
7f298d5
8b62d8e
c1e6772
 
 
7eb48da
c1e6772
 
 
 
 
 
 
ea99330
e030ef8
c1e6772
8b62d8e
c1e6772
8b62d8e
 
c1e6772
 
 
 
8b62d8e
c1e6772
 
8b62d8e
c1e6772
 
 
7eb48da
c1e6772
8b62d8e
c1e6772
 
8b62d8e
c1e6772
 
8b62d8e
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Use PostgreSQL as the base image
FROM postgres:15

# Main variables, ensure they match your actual values, which can be set in HF settings
ARG WEBHOOK_URL=https://azlabs-aiflow.hf.space/
ARG WEBDAV_URL="https://cfr2.n8n.us.kg/"
ARG WEBDAV_USER="your_username"
ARG WEBDAV_PASSWORD="your_password"

# General variables, use default values, which can be set in HF settings
ARG POSTGRES_USER=n8n
ARG POSTGRES_PASSWORD=n8n
ARG POSTGRES_DB=n8n
ARG WORKDIR=/app
ARG DB_IMPORT=yes
ARG NODEJS_VER=20

# Set environment variables, use default values
ENV POSTGRES_USER=${POSTGRES_USER} \
    POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \
    POSTGRES_DB=${POSTGRES_DB} \
    WEBHOOK_URL=${WEBHOOK_URL} \
    DB_IMPORT=${DB_IMPORT} \
    N8N_HOST=0.0.0.0 \
    N8N_PORT=7860 \
    N8N_PROTOCOL=https \
    GENERIC_TIMEZONE=Asia/Shanghai \
    N8N_METRICS=true \
    QUEUE_HEALTH_CHECK_ACTIVE=true \
    N8N_PAYLOAD_SIZE_MAX=256 \
    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} \
    VIRTUAL_ENV=$WORKDIR/venv \
    WEBDAV_URL=${WEBDAV_URL} \
    WEBDAV_USER=${WEBDAV_USER} \
    WEBDAV_PASSWORD=${WEBDAV_PASSWORD} \
    WORKDIR=${WORKDIR} \
    PATH="$WORKDIR/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH"

# Copy files
COPY requirements.txt ${WORKDIR}/requirements.txt
COPY package.txt ${WORKDIR}/package.txt

# Install dependencies
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 python3-venv python3-pip gosu \
    htop jq && \
    curl -fsSL https://deb.nodesource.com/setup_${NODEJS_VER}.x | bash - && \
    apt-get install -y nodejs && \
    ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    dpkg-reconfigure --frontend noninteractive tzdata && \
    apt-get clean && rm -rf /var/lib/apt/lists/* && \
    python3 -m venv $VIRTUAL_ENV && \
    $VIRTUAL_ENV/bin/pip install --upgrade pip && \
    $VIRTUAL_ENV/bin/pip install -r ${WORKDIR}/requirements.txt && \
    npm install -g $(cat ${WORKDIR}/package.txt)

# Set working directory
WORKDIR ${WORKDIR}

# Copy scripts
COPY run.sh ${WORKDIR}/run.sh
COPY import-db.sh ${WORKDIR}/import-db.sh
COPY backup.sh ${WORKDIR}/backup.sh

# Make scripts executable
RUN chmod +x ${WORKDIR}/run.sh ${WORKDIR}/import-db.sh ${WORKDIR}/backup.sh

# Set user and permissions
USER root
RUN usermod -u 1000 postgres && groupmod -g 1000 postgres && \
    chown -R postgres:postgres /var/lib/postgresql /var/run/postgresql ${WORKDIR} && \
    mkdir -p ${WORKDIR}/backups && chmod -R 775 ${WORKDIR}/backups

# Switch to postgres user
USER postgres

# Expose port
EXPOSE 7860

# Run command
CMD./run.sh