| 1 | # Self-hosted Ghost. Run ./setup.sh (or setup.ps1 on Windows) once: it writes |
| 2 | # .env next to this file and starts everything. Afterwards plain |
| 3 | # `docker compose up -d --build` from this directory works too. |
| 4 | # |
| 5 | # Profiles, chosen by COMPOSE_PROFILES in .env: |
| 6 | # rustfs bundled S3 storage; leave it out to use an external bucket |
| 7 | # https Caddy with HTTPS on 80/443 for a domain |
| 8 | # http Caddy with plain HTTP on 3000 (web), 3001 (api), 3003 (docs) |
| 9 | # importer apps/importer, for importing repositories from GitHub |
| 10 | # One of https or http is always on: Caddy is what sets X-Forwarded-For, and |
| 11 | # without it every visitor shares one sign-in rate limit. |
| 12 | # Not `ghost`: that is the development compose project at the repository root, and the two would share volumes. |
| 13 | name: ghost-server |
| 14 | |
| 15 | x-app-env: &app-env |
| 16 | env_file: .env |
| 17 | |
| 18 | x-caddy: &caddy |
| 19 | image: caddy:2 |
| 20 | restart: unless-stopped |
| 21 | depends_on: [web, api, |
| 22 | volumes: |
| 23 | - ./Caddyfile:/etc/caddy/Caddyfile:ro |
| 24 | - caddy:/data |
| 25 | |
| 26 | services: |
| 27 | postgres: |
| 28 | image: postgres:18-alpine |
| 29 | restart: unless-stopped |
| 30 | environment: |
| 31 | POSTGRES_USER: ghost |
| 32 | POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?run setup.sh first} |
| 33 | POSTGRES_DB: ghost |
| 34 | volumes: |
| 35 | - postgres:/var/lib/postgresql |
| 36 | healthcheck: |
| 37 | test: ["CMD-SHELL", |
| 38 | interval: 5s |
| 39 | timeout: 5s |
| 40 | retries: 20 |
| 41 | |
| 42 | rustfs: |
| 43 | image: rustfs/rustfs:latest |
| 44 | profiles: [rustfs] |
| 45 | restart: unless-stopped |
| 46 | environment: |
| 47 | RUSTFS_VOLUMES: /data |
| 48 | RUSTFS_ADDRESS: 0.0.0.0:9000 |
| 49 | RUSTFS_ACCESS_KEY: ${S3_ACCESS_KEY_ID} |
| 50 | RUSTFS_SECRET_KEY: ${S3_SECRET_ACCESS_KEY} |
| 51 | volumes: |
| 52 | - rustfs:/data |
| 53 | healthcheck: |
| 54 | test: ["CMD-SHELL", |
| 55 | interval: 5s |
| 56 | timeout: 5s |
| 57 | retries: 20 |
| 58 | start_period: 20s |
| 59 | |
| 60 | # Creates the bucket, or confirms it exists. Runs against an external bucket too. |
| 61 | bucket: |
| 62 | image: amazon/aws-cli:latest |
| 63 | depends_on: |
| 64 | rustfs: |
| 65 | condition: service_healthy |
| 66 | required: false |
| 67 | environment: |
| 68 | AWS_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID} |
| 69 | AWS_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY} |
| 70 | AWS_DEFAULT_REGION: auto |
| 71 | entrypoint: ["/bin/sh", |
| 72 | command: |
| 73 | - 'aws --endpoint-url "$$S3_ENDPOINT" s3api head-bucket --bucket "$$S3_BUCKET" || aws --endpoint-url "$$S3_ENDPOINT" s3api create-bucket --bucket "$$S3_BUCKET"' |
| 74 | env_file: .env |
| 75 | restart: "no" |
| 76 | |
| 77 | migrate: |
| 78 | <<: *app-env |
| 79 | image: ghost-api |
| 80 | build: |
| 81 | context: .. |
| 82 | dockerfile: apps/api/Dockerfile |
| 83 | depends_on: |
| 84 | postgres: |
| 85 | condition: service_healthy |
| 86 | command: ["node", |
| 87 | restart: "no" |
| 88 | |
| 89 | api: |
| 90 | <<: *app-env |
| 91 | image: ghost-api |
| 92 | build: |
| 93 | context: .. |
| 94 | dockerfile: apps/api/Dockerfile |
| 95 | restart: unless-stopped |
| 96 | depends_on: |
| 97 | migrate: |
| 98 | condition: service_completed_successfully |
| 99 | bucket: |
| 100 | condition: service_completed_successfully |
| 101 | environment: |
| 102 | PORT: 3001 |
| 103 | ports: |
| 104 | # SSH does not go through Caddy. |
| 105 | - "${GIT_SSH_PORT:-1031}:${GIT_SSH_PORT:-1031}" |
| 106 | |
| 107 | delivery: |
| 108 | <<: *app-env |
| 109 | build: |
| 110 | context: .. |
| 111 | dockerfile: apps/delivery/Dockerfile |
| 112 | restart: unless-stopped |
| 113 | depends_on: |
| 114 | migrate: |
| 115 | condition: service_completed_successfully |
| 116 | |
| 117 | # No published port: only the api hands it jobs, and it pushes back to the api over the compose network. |
| 118 | importer: |
| 119 | <<: *app-env |
| 120 | profiles: [importer] |
| 121 | build: |
| 122 | context: .. |
| 123 | dockerfile: apps/importer/Dockerfile |
| 124 | restart: unless-stopped |
| 125 | environment: |
| 126 | GHOST_API_URL: http://api:3001 |
| 127 | |
| 128 | # No published port: zoekt answers for every repository, private ones included, so only the api, which checks access, may reach it. |
| 129 | zoekt: |
| 130 | <<: *app-env |
| 131 | build: |
| 132 | context: .. |
| 133 | dockerfile: apps/zoekt/Dockerfile |
| 134 | restart: unless-stopped |
| 135 | depends_on: |
| 136 | bucket: |
| 137 | condition: service_completed_successfully |
| 138 | |
| 139 | web: |
| 140 | build: |
| 141 | context: .. |
| 142 | dockerfile: apps/web/Dockerfile |
| 143 | args: |
| 144 | # Baked into the browser bundle: changing them needs a rebuild. |
| 145 | NEXT_PUBLIC_API_URL: ${API_URL} |
| 146 | NEXT_PUBLIC_SITE_URL: ${WEB_APP_URL} |
| 147 | NEXT_PUBLIC_DOCS_URL: ${DOCS_URL} |
| 148 | NEXT_PUBLIC_SSH_CLONE_HOST: ${SSH_CLONE_HOST} |
| 149 | restart: unless-stopped |
| 150 | environment: |
| 151 | PORT: 3000 |
| 152 | INTERNAL_API_URL: http://api:3001 |
| 153 | |
| 154 | docs: |
| 155 | build: |
| 156 | context: .. |
| 157 | dockerfile: apps/docs/Dockerfile |
| 158 | args: |
| 159 | NEXT_PUBLIC_DOCS_URL: ${DOCS_URL} |
| 160 | NEXT_PUBLIC_WEB_APP_URL: ${WEB_APP_URL} |
| 161 | restart: unless-stopped |
| 162 | environment: |
| 163 | PORT: 3003 |
| 164 | |
| 165 | caddy: |
| 166 | <<: *caddy |
| 167 | profiles: [https] |
| 168 | environment: |
| 169 | DOMAIN: ${DOMAIN:-} |
| 170 | ports: |
| 171 | - "80:80" |
| 172 | - "443:443" |
| 173 | - "443:443/udp" |
| 174 | |
| 175 | caddy-http: |
| 176 | <<: *caddy |
| 177 | profiles: [http] |
| 178 | volumes: |
| 179 | - ./Caddyfile.http:/etc/caddy/Caddyfile:ro |
| 180 | - caddy:/data |
| 181 | ports: |
| 182 | - "3000:3000" |
| 183 | - "3001:3001" |
| 184 | - "3003:3003" |
| 185 | |
| 186 | volumes: |
| 187 | postgres: |
| 188 | rustfs: |
| 189 | caddy: |