Skip to content

Commit 73812c8

Browse files
authored
Added devcontainer config for VS Code and Codespaces (TryGhost#27544)
ref https://linear.app/ghost/issue/PLA-33/ First of a planned series of PRs adding VS Code Dev Containers + Codespaces support to Ghost. This PR is the minimum viable spike: with the Dev Containers extension installed, contributors can **Reopen in Container** locally, or open the repo in a **Codespace**, and get a working Ghost dev environment without touching host Node/pnpm/MySQL. **Baseline behaviour is unchanged.** The existing `pnpm dev` host-hybrid workflow is not affected — the devcontainer is purely additive.
1 parent c56d3ff commit 73812c8

3 files changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
services:
2+
ghost-dev:
3+
# Mount the full repo so VS Code can edit apps/, e2e/, and root config files.
4+
# The original ./ghost:/home/ghost/ghost mount from compose.dev.yaml is
5+
# preserved via merge semantics so nodemon hot-reload still works for anyone
6+
# running the backend the original way.
7+
volumes:
8+
- ./:/workspaces/Ghost:cached
9+
# Override the default `pnpm dev` command. VS Code controls startup and the
10+
# user runs backend/frontend dev servers as tasks (see .vscode/tasks.json).
11+
command: ["sleep", "infinity"]
12+
working_dir: /workspaces/Ghost
13+
# The baseline healthcheck in compose.dev.yaml hits Ghost on :2368, but in
14+
# the devcontainer Ghost isn't running until the user starts the dev task.
15+
# Replace with a trivial check so the gateway's depends_on doesn't time out.
16+
healthcheck:
17+
test: ["CMD", "true"]
18+
interval: 5s
19+
timeout: 2s
20+
retries: 1
21+
start_period: 0s
22+
23+
ghost-dev-gateway:
24+
# Point Caddy at the dev servers running inside the ghost-dev container
25+
# instead of host.docker.internal (which is the default for the hybrid
26+
# host/container dev setup).
27+
environment:
28+
GHOST_BACKEND: ghost-dev:2368
29+
ADMIN_DEV_SERVER: ghost-dev:5174
30+
ADMIN_LIVE_RELOAD_SERVER: ghost-dev:4200
31+
PORTAL_DEV_SERVER: ghost-dev:4175
32+
COMMENTS_DEV_SERVER: ghost-dev:7173
33+
SIGNUP_DEV_SERVER: ghost-dev:6174
34+
SEARCH_DEV_SERVER: ghost-dev:4178
35+
ANNOUNCEMENT_DEV_SERVER: ghost-dev:4177
36+
LEXICAL_DEV_SERVER: ghost-dev:4173

.devcontainer/devcontainer.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"name": "Ghost",
3+
"dockerComposeFile": [
4+
"../compose.dev.yaml",
5+
"compose.devcontainer.yaml"
6+
],
7+
"service": "ghost-dev",
8+
"workspaceFolder": "/workspaces/Ghost",
9+
"shutdownAction": "stopCompose",
10+
"remoteUser": "root",
11+
12+
// Codespaces prebuild step — runs once when the image is built.
13+
// Primes the pnpm store so first-open is fast.
14+
"onCreateCommand": "corepack enable && corepack prepare --activate && cd /workspaces/Ghost && pnpm install --prefer-offline || true",
15+
16+
// Runs after the workspace mount is ready on every container create.
17+
"postCreateCommand": ".devcontainer/postCreate.sh",
18+
19+
"forwardPorts": [
20+
2368,
21+
3306,
22+
6379,
23+
1025,
24+
8025,
25+
5174,
26+
4200,
27+
4175,
28+
7173,
29+
6174,
30+
4178,
31+
4177,
32+
4173
33+
],
34+
"portsAttributes": {
35+
"2368": {"label": "Ghost (via gateway)", "onAutoForward": "notify"},
36+
"3306": {"label": "MySQL"},
37+
"6379": {"label": "Redis"},
38+
"1025": {"label": "Mailpit SMTP"},
39+
"8025": {"label": "Mailpit Web"},
40+
"5174": {"label": "Admin (Vite)"},
41+
"4200": {"label": "Ember live-reload"},
42+
"4175": {"label": "Portal"},
43+
"7173": {"label": "Comments UI"},
44+
"6174": {"label": "Signup Form"},
45+
"4178": {"label": "Sodo Search"},
46+
"4177": {"label": "Announcement Bar"},
47+
"4173": {"label": "Koenig Lexical"}
48+
},
49+
50+
"customizations": {
51+
"vscode": {
52+
"extensions": [
53+
"dbaeumer.vscode-eslint",
54+
"bradlc.vscode-tailwindcss",
55+
"ms-playwright.playwright",
56+
"editorconfig.editorconfig"
57+
]
58+
}
59+
}
60+
}

.devcontainer/postCreate.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
cd /workspaces/Ghost
5+
6+
corepack enable
7+
corepack prepare --activate
8+
9+
git submodule update --init --recursive
10+
11+
pnpm install --prefer-offline

0 commit comments

Comments
 (0)