Docs

Self-host AFFiNE

Install the self-host version of AFFiNE

Deploy with Sealos



Prerequisites

1 / Docker

We provide a quick way to start Docker, so you need to install Docker first. For installation instructions on different versions of Docker, you can try visiting the Docker installation documentation.

You must have docker as well as docker compose installed and available on your machine.

2 / Download the latest compose file

wget -O compose.yml https://github.com/toeverything/affine/releases/latest/download/docker-compose.yml

You can also download just the compose.yml file directly from the AFFiNE repository at this path: ./.docker/selfhost/compose.yml.

3 / Prepare the env file

The compose.yml require few environment to run properly, and they are:

# select a revision to deploy, available values: stable, beta, canary
AFFINE_REVISION=stable
 
# set the port for the server container it will expose the server on
PORT=3010
 
# set the host for the server for outgoing links
# AFFINE_SERVER_HTTPS=true
# AFFINE_SERVER_HOST=affine.yourdomain.com
# or 
# AFFINE_SERVER_EXTERNAL_URL=https://affine.yourdomain.com
 
# position of the database data to persist
DB_DATA_LOCATION=~/.affine/self-host/postgres/pgdata
# position of the upload data(images, files, etc.) to persist
UPLOAD_LOCATION=~/.affine/self-host/storage
# position of the configuration files to persist
CONFIG_LOCATION=~/.affine/self-host/config
 
# database credentials
DB_USERNAME=affine
DB_PASSWORD=
DB_DATABASE=affine

There are many more configurable options for AFFiNE server. Please refer to Run AFFiNE with Custom Options

Quick start

After all the preparation, you can simply start your own AFFiNE instance by:

docker compose -f ./compose.yml up -d

Sign in and Sync with self-host AFFiNE

To access your AFFiNE on the web, open Chrome and enter the URL: http://localhost:3010. To ensure data security, sign in to your self-hosted AFFiNE Cloud account by following these steps:

  1. Open the workspace list view, and click Sign up / Sign in Button.

edn4NevLZgrSyjRoGND9ZZX6TIVEl3V-shoD85ZyuVQ=

  1. Type the email and password, and click the Sign in button

pqk4qcyYl49vWvDjriZq17Zrp4xT21xZyQQE5DjJjGc=

  1. Switch to the Cloud sync Workspace

BhLmxdhVsMGrV211k6DA9mwyZSO3z8HTnLx_fVoBIEw=

Data Persistance

When everything is up and running, you should be able to see three instance related to AFFiNE:

  • Postgre

  • Redis

  • AFFiNE self-host

As you can see, the self-host version of AFFiNE contains everything it takes to self-host the AFFiNE Cloud. Keep in mind that, you must login to your self-hosted AFFiNE Cloud to store your data into the database. Otherwise, your data in the default local-workspace will be stored as cache in the browser and is risky of losing. Make sure that you have turned them into cloud workspaces to enable syncing to postgres.

Connect AFFiNE Client to self-host AFFiNE Cloud isn’t available yet. You can use the web version while we are working on it.


More custom options

For more information about configuring custom domains, email servers, databases, etc. please refer to Run AFFiNE with Custom Options.

Storage

Setting up your databases

By default, a redis as well as postgre instance will be download and composed ready out of the box. If you prefer to use your own redis or postgre instance, you can make sure AFFiNE is properly pointed by the section given below:

environment:
  - REDIS_SERVER_HOST=redis
  - DATABASE_URL=postgres://affine:affine@postgres:5432/affine

Redis and Postgres is used for your database. Your data will be kept in the path given in the volumn section within the YML file. Please keep these directory safe to prevent from losing your data.

volumes:
  - ${UPLOAD_LOCATION}:/root/.affine/storage
  - ${CONFIG_LOCATION}:/root/.affine/config

Upgrade Your Self-Hosted AFFiNE

Upgrading your self-hosted Affine system is a straightforward process that can be accomplished in a few steps. Follow this guide to ensure a smooth and error-free upgrade process.

Before starting, back up your compose.yml file and all important data to prevent any loss in case the upgrade encounters issues.

Download the New compose.yml File

Download the latest compose.yml file from here, replacing the existing file on your server.

Important Note: If you have previously modified configurations in the compose.yml file, remember to migrate those changes to the new file. This may include, but is not limited to, environment variables, port numbers, volume configurations, etc.

Pull the New Docker Image

Execute the following command to pull the new Docker image:

docker compose -f compose.yml pull

This step will download the latest version of the AFFiNE image based on the updated compose.yml file.

Restart the Service

use the following command to stop the currently running service (if any) and start the service with the new version:

docker compose -f compose.yml up

This command stops all related containers based on the compose.yml file configuration and restarts them with the latest version.

Upgrade Complete

You have successfully upgraded your self-hosted Affine system.

Q&A

Why my selfhosted version does not support copy & paste?

Unfortunately, due to the restriction of browsers, many features like Clipboard only work under Secure Contexts (i.e. HTTPS or localhost). I would recommend you either setup your own CA, or proxy the server to the localhost.You can set the flag in Chrome to disable the Secure Contexts in the trusted sources. Input the chrome://flags/#unsafely-treat-insecure-origin-as-secure in URL to set.

End

Want more self-hosting options? You can contribute code to the AFFiNE repository.