Skip to content

Commit b719931

Browse files
authored
Added stripe to yarn dev:forward (#25661)
no issue Currently to run Ghost locally with Stripe with the new `yarn dev:forward` setup, you need to install and run the Stripe CLI locally, and pass the webhook secret to Ghost via environment variable. This change makes it easier to run Ghost with Stripe with the `yarn dev:forward` command. --- To use: - Add `COMPOSE_PROFILES=stripe` to `.env` file at root of repo - Add `STRIPE_SECRET_KEY` to `.env` file at root of repo (or export it in your shell) - Run `yarn dev:forward` --- How it works - The stripe CLI runs in docker. The entrypoint file runs to fetch the WEBHOOK_SECRET required by Ghost to verify Stripe webhooks, and saves it to a shared volume - When `ghost-dev` starts, the entrypoint reads WEBHOOK_SECRET from the shared volume into its environment before booting Ghost
1 parent b05520f commit b719931

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Docker Compose profiles to enable
55
## Run `docker compose config --profiles` to see all available profiles
66
## See https://docs.docker.com/compose/how-tos/profiles/ for more information
7-
COMPOSE_PROFILES=ghost
7+
# COMPOSE_PROFILES=stripe
88

99
# Debug level to pass to Ghost
1010
# DEBUG=

compose.dev.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ services:
6666
- ghost-dev-media:/home/ghost/ghost/core/content/media
6767
- ghost-dev-files:/home/ghost/ghost/core/content/files
6868
- ghost-dev-logs:/home/ghost/ghost/core/content/logs
69+
- shared-config:/mnt/shared-config:ro
6970
environment:
7071
NODE_ENV: development
7172
NODE_TLS_REJECT_UNAUTHORIZED: "0"
@@ -98,6 +99,9 @@ services:
9899
condition: service_healthy
99100
mailpit:
100101
condition: service_healthy
102+
stripe:
103+
condition: service_healthy
104+
required: false
101105
healthcheck:
102106
test: ["CMD", "node", "-e", "fetch('http://localhost:2368',{redirect:'manual'}).then(r=>process.exit(r.status<500?0:1)).catch(()=>process.exit(1))"]
103107
timeout: 5s
@@ -123,10 +127,26 @@ services:
123127
ghost-dev:
124128
condition: service_healthy
125129

130+
stripe:
131+
image: stripe/stripe-cli:latest
132+
container_name: ghost-dev-stripe
133+
entrypoint: ["/entrypoint.sh"]
134+
profiles: ["stripe"]
135+
volumes:
136+
- ./docker/stripe/entrypoint.sh:/entrypoint.sh:ro
137+
- shared-config:/mnt/shared-config
138+
environment:
139+
- GHOST_URL=http://ghost-dev:2368
140+
- STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY:-}
141+
healthcheck:
142+
test: ["CMD", "test", "-f", "/mnt/shared-config/.env.stripe"]
143+
interval: 1s
144+
retries: 120
126145

127146
volumes:
128147
mysql-data:
129148
redis-data:
149+
shared-config:
130150
ghost-dev-data:
131151
ghost-dev-images:
132152
ghost-dev-media:

compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ services:
294294
- ./docker/stripe/entrypoint.sh:/entrypoint.sh:ro
295295
- shared-config:/mnt/shared-config
296296
environment:
297+
- GHOST_URL=http://server:2368
297298
- STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY:-}
298299
- STRIPE_PUBLISHABLE_KEY=${STRIPE_PUBLISHABLE_KEY:-}
299300
- STRIPE_ACCOUNT_ID=${STRIPE_ACCOUNT_ID:-}

docker/ghost-dev/entrypoint.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ else
1717
echo "WARNING: Tinybird not enabled: .env.tinybird file not found at /mnt/shared-config/.env.tinybird" >&2
1818
fi
1919

20+
21+
# Configure Stripe webhook secret
22+
if [ -f /mnt/shared-config/.env.stripe ]; then
23+
source /mnt/shared-config/.env.stripe
24+
if [ -n "${STRIPE_WEBHOOK_SECRET:-}" ]; then
25+
export WEBHOOK_SECRET="$STRIPE_WEBHOOK_SECRET"
26+
echo "Stripe webhook secret configured successfully"
27+
else
28+
echo "WARNING: Stripe webhook secret not found in shared config"
29+
fi
30+
fi
31+
2032
# Execute the CMD
2133
exec "$@"
2234

docker/stripe/entrypoint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ else
8787
fi
8888

8989
# Start stripe listen in the background
90-
echo "Starting Stripe webhook listener forwarding to http://server:2368/members/webhooks/stripe/"
91-
stripe listen --forward-to http://server:2368/members/webhooks/stripe/ --api-key "${STRIPE_SECRET_KEY}" &
90+
echo "Starting Stripe webhook listener forwarding to ${GHOST_URL}/members/webhooks/stripe/"
91+
stripe listen --forward-to ${GHOST_URL}/members/webhooks/stripe/ --api-key "${STRIPE_SECRET_KEY}" &
9292
child=$!
9393

9494
# Wait for the child process

0 commit comments

Comments
 (0)