diff --git a/.env-sample b/.env-sample index 9a79ceba6f..22ebd4d026 100644 --- a/.env-sample +++ b/.env-sample @@ -15,6 +15,23 @@ # POSTGRES_PORT=5432 # POSTGRES_HOST=localhost +# ============================================================================= +# TRANSCRIBE CONFIG EXAMPLE +# ----------------------------------------------------------------------------- +# This service is not required, and it will be ignored by using --profile server +# when running docker-compose. If you want to use it, you need to set the +# following environment variables. +# ============================================================================= + +# TRANSCRIBE_API_KEY=secret_string_shared_between_server_and_transcribe +# TRANSCRIBE_ENABLED=true + +# QUEUE_DATABASE_NAME=transcribe +# QUEUE_DATABASE_USER=transcribe +# QUEUE_DATABASE_PASSWORD=transcribe +# QUEUE_DATABASE_PORT=5431 +# HTR_CLI_IMAGES_FOLDER=/home/user/images_storage + # ============================================================================= # DEV CONFIG EXAMPLE # ----------------------------------------------------------------------------- diff --git a/.env-transcribe-sample b/.env-transcribe-sample index a9a9948d1c..433508f0c5 100644 --- a/.env-transcribe-sample +++ b/.env-transcribe-sample @@ -27,4 +27,5 @@ QUEUE_DRIVER=pg QUEUE_DATABASE_NAME=transcribe QUEUE_DATABASE_USER=transcribe QUEUE_DATABASE_PASSWORD=transcribe -QUEUE_DATABASE_PORT=5432 \ No newline at end of file +QUEUE_DATABASE_PORT=5432 +QUEUE_DATABASE_HOST=localhost \ No newline at end of file diff --git a/docker-compose.server.yml b/docker-compose.server.yml index eaf5261160..a6ffc23831 100644 --- a/docker-compose.server.yml +++ b/docker-compose.server.yml @@ -17,11 +17,21 @@ version: '3' +networks: + app-network: + transcribe-network: + shared-network: + services: db: image: postgres:16 + profiles: + - full + - server volumes: - ./data/postgres:/var/lib/postgresql/data + networks: + - app-network ports: - "5432:5432" restart: unless-stopped @@ -31,10 +41,17 @@ services: - POSTGRES_DB=${POSTGRES_DATABASE} app: image: joplin/server:latest + profiles: + - full + - server depends_on: - db + - transcribe ports: - "22300:22300" + networks: + - app-network + - shared-network restart: unless-stopped environment: - APP_PORT=22300 @@ -45,3 +62,48 @@ services: - POSTGRES_USER=${POSTGRES_USER} - POSTGRES_PORT=${POSTGRES_PORT} - POSTGRES_HOST=db + - TRANSCRIBE_API_KEY=${TRANSCRIBE_API_KEY} + - TRANSCRIBE_BASE_URL=http://transcribe:4567 + - TRANSCRIBE_ENABLED=${TRANSCRIBE_ENABLED} + transcribe-db: + image: postgres:16 + profiles: + - full + volumes: + - ./data/transcribe-postgres:/var/lib/postgresql/data + networks: + - transcribe-network + ports: + - "${QUEUE_DATABASE_PORT}:5432" + restart: unless-stopped + environment: + - POSTGRES_PASSWORD=${QUEUE_DATABASE_PASSWORD} + - POSTGRES_USER=${QUEUE_DATABASE_USER} + - POSTGRES_DB=${QUEUE_DATABASE_NAME} + command: -p ${QUEUE_DATABASE_PORT} + transcribe: + image: joplin/transcribe:latest + profiles: + - full + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - ${HTR_CLI_IMAGES_FOLDER}:/app/packages/transcribe/images + depends_on: + - transcribe-db + ports: + - "4567:4567" + networks: + - transcribe-network + - shared-network + restart: unless-stopped + environment: + - APP_PORT=4567 + - DB_CLIENT=pg + - QUEUE_DATABASE_NAME=${QUEUE_DATABASE_NAME} + - QUEUE_DATABASE_USER=${QUEUE_DATABASE_USER} + - QUEUE_DATABASE_PASSWORD=${QUEUE_DATABASE_PASSWORD} + - QUEUE_DATABASE_PORT=${QUEUE_DATABASE_PORT} + - QUEUE_DATABASE_HOST=transcribe-db + - API_KEY=${TRANSCRIBE_API_KEY} + - HTR_CLI_IMAGES_FOLDER=${HTR_CLI_IMAGES_FOLDER} + diff --git a/packages/server/README.md b/packages/server/README.md index 12461c554c..a720b7abfa 100644 --- a/packages/server/README.md +++ b/packages/server/README.md @@ -60,7 +60,8 @@ Ensure that the provided database and user exist as Joplin Server will not creat 1. Using the [sample docker-compose file](https://raw.githubusercontent.com/laurent22/joplin/dev/docker-compose.server.yml), create a docker compose file in the location of your Docker configuration files. Example: /home/[user]/docker/docker-compose.yml 2. Update the fields in the docker-compose file as seen in the sample file. - +3. Note that there is two profiles - one is `full` which runs Joplin Server and the Transcribe server, and other is `server` which is only Joplin Server. +4. To choose the profile that you want, pass for example `--profile server` when using docker compose. ## Setup reverse proxy diff --git a/packages/transcribe/README.md b/packages/transcribe/README.md index 46c301dc26..431fc01fe1 100644 --- a/packages/transcribe/README.md +++ b/packages/transcribe/README.md @@ -1,10 +1,10 @@ # Installing -## Configure Docker for transcribe +## Configure Docker for Transcribe 1. Copy `.env-transcribe-sample` to the location of your Docker configuration files. 2. Rename the file `.env-transcribe-sample` to `.env-transcribe`. -3. `HTR_CLI_IMAGES_FOLDER` should be a fullpath to the folder that is going to store the images +3. `HTR_CLI_IMAGES_FOLDER` should be a full path to the folder that is going to store the images. It is an external folder, outside of the Docker container. 4. Run the following command to test starting the server using the default configuration: ```shell @@ -15,6 +15,16 @@ docker run --env-file .env-transcribe -p 4567:4567 \ transcribe ``` +## Using `docker compose` + +For running with docker compose the minimal required configuration is available on `.env-sample` and `docker-compose.server.yml`. + +1. Run `cp .env-sample .env` +2. Modify the options that make sense to you in the new `.env` file +3. Run `docker compose -f docker-compose.server.yml --profile full up --detached` + +For further customization look at `.env-sample-transcribe` + # Setup for development ## Testing diff --git a/packages/transcribe/src/env.ts b/packages/transcribe/src/env.ts index a5cbb03a87..c8034b13bd 100644 --- a/packages/transcribe/src/env.ts +++ b/packages/transcribe/src/env.ts @@ -12,6 +12,7 @@ export const defaultEnvValues: EnvVariables = { QUEUE_DATABASE_NAME: '', QUEUE_DATABASE_USER: '', QUEUE_DATABASE_PORT: 5432, + QUEUE_DATABASE_HOST: 'localhost', }; export interface EnvVariables { @@ -27,6 +28,7 @@ export interface EnvVariables { QUEUE_DATABASE_NAME: string; QUEUE_DATABASE_USER: string; QUEUE_DATABASE_PORT: number; + QUEUE_DATABASE_HOST: string; } export function parseEnv(rawEnv: Record): EnvVariables { diff --git a/packages/transcribe/src/services/createQueue.ts b/packages/transcribe/src/services/createQueue.ts index 0d06a42ad5..545966cf5a 100644 --- a/packages/transcribe/src/services/createQueue.ts +++ b/packages/transcribe/src/services/createQueue.ts @@ -15,6 +15,7 @@ const createQueue = async (envVariables: EnvVariables, isPrimary: boolean) => { user: envVariables.QUEUE_DATABASE_USER, password: envVariables.QUEUE_DATABASE_PASSWORD, port: envVariables.QUEUE_DATABASE_PORT, + host: envVariables.QUEUE_DATABASE_HOST, }, ttl: envVariables.QUEUE_TTL, maintenanceInterval: envVariables.QUEUE_MAINTENANCE_INTERVAL, diff --git a/packages/transcribe/src/services/queue/PgBossQueue.ts b/packages/transcribe/src/services/queue/PgBossQueue.ts index 0854cac5fc..98b1db17ef 100644 --- a/packages/transcribe/src/services/queue/PgBossQueue.ts +++ b/packages/transcribe/src/services/queue/PgBossQueue.ts @@ -33,6 +33,7 @@ export default class PgBossQueue implements BaseQueue { user: this.options.database.user, password: this.options.database.password, port: this.options.database.port, + host: this.options.database.host, }); } diff --git a/packages/transcribe/src/types.ts b/packages/transcribe/src/types.ts index 7e12a4445f..fbb3fa06ed 100644 --- a/packages/transcribe/src/types.ts +++ b/packages/transcribe/src/types.ts @@ -115,6 +115,7 @@ export type QueueConfiguration = { user?: string; password?: string; port?: number; + host?: string; }; ttl: number; retryCount: number;