昨天有大佬发过来一个教程链接,是他自己部署 AFFiNE 的笔记,虽然放在了 Notion
我就整理(Copy)一下发在这里了:
Docker - AFFiNE 部署步骤
1. 准备安装
# create folders
mkdir -p ~/docker/affine/data/{postgres,config,storage,redis}
cd ~/docker/affine/
# create docker network (optional), network "proxy" is used in docker-compose.yml
docker network create --subnet="172.19.0.0/16" --gateway="172.19.0.1" proxy
2. 修改预设环境 .env (Environment)
nano .env
确保设置了以下参数
要生成随机字符串,请使用此命令 `openssl rand -base64 32
# 按需修改
[email protected]
AFFINE_ADMIN_PASSWORD=A_very_strong_paSsw0rd
AFFINE_SERVER_HOST=affine.mydomain.com
3. 准备文件 docker-compose.yml
nano docker-compose.yml
以下是使用 traefik 反向代理的示例
如果你使用 Nginx,去掉这部分即可。
services:
affine:
image: ghcr.io/toeverything/affine-graphql:stable
container_name: affine
env_file:
- .env
command:
['sh', '-c', 'node ./scripts/self-host-predeploy && node ./dist/index.js']
ports:
- '3010:3010'
- '5555:5555'
depends_on:
redis:
condition: service_healthy
postgres:
condition: service_healthy
volumes:
# custom configurations
- ~/docker/affine/data/config:/root/.affine/config
# blob storage
- ~/docker/affine/data/storage:/root/.affine/storage
logging:
driver: 'json-file'
options:
max-size: '1000m'
restart: unless-stopped
environment:
- NODE_OPTIONS="--import=./scripts/register.js"
- AFFINE_CONFIG_PATH=/root/.affine/config
- REDIS_SERVER_HOST=redis
- DATABASE_URL=postgres://affine:affine@postgres:5432/affine
- NODE_ENV=production
- AFFINE_ADMIN_EMAIL=${AFFINE_ADMIN_EMAIL}
- AFFINE_ADMIN_PASSWORD=${AFFINE_ADMIN_PASSWORD}
- AFFINE_SERVER_HOST=${AFFINE_SERVER_HOST}
labels:
- "traefik.enable=true"
- "traefik.http.routers.affine.entrypoints=http"
- "traefik.http.routers.affine.rule=Host(`affine.mydomain.com`)"
- "traefik.http.middlewares.affine-https-redirect.redirectscheme.scheme=https"
- "traefik.http.routers.affine.middlewares=affine-https-redirect"
- "traefik.http.routers.affine-secure.entrypoints=https"
- "traefik.http.routers.affine-secure.rule=Host(`affine.mydomain.com`)"
- "traefik.http.routers.affine-secure.tls=true"
- "traefik.http.routers.affine-secure.service=affine"
- "traefik.http.services.affine.loadbalancer.server.port=3010"
- "traefik.docker.network=proxy"
networks:
- proxy
redis:
image: redis
container_name: affine_redis
restart: unless-stopped
volumes:
- ~/docker/affine/data/redis:/data
healthcheck:
test: ['CMD', 'redis-cli', '--raw', 'incr', 'ping']
interval: 10s
timeout: 5s
retries: 5
networks:
- proxy
postgres:
image: postgres
container_name: affine_postgres
restart: unless-stopped
volumes:
- ~/docker/affine/data/postgres:/var/lib/postgresql/data
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U affine']
interval: 10s
timeout: 5s
retries: 5
environment:
POSTGRES_USER: affine
POSTGRES_PASSWORD: affine
POSTGRES_DB: affine
PGDATA: /var/lib/postgresql/data/pgdata
networks:
- proxy
networks:
proxy:
external: true
4. 开启 docker 容器
docker compose up -d
5. 访问站点并设置
使用 .env
文件中的用户名、密码登录
暂不支持使用 AFFiNE 客户端连接到自托管 AFFiNE(开发中)。可以使用网页版。
附录: 官方网站和参考资料
https://docs.affine.pro/docs/self-host-affine
https://docs.affine.pro/docs/self-host-affine/run-affine-with-custom-options