0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

Fixed browser tests running in docker compose (#21974)

ref
https://linear.app/ghost/issue/ENG-1968/get-browser-tests-working-in-docker

- When running browser tests in docker compose, the `stripe listen`
command was not outputting the API key from the environment, because
it's expecting that you've already run `stripe login` to authenticate
with stripe. It only outputs the API key in the command line in CI.
- This isn't convenient/practical to do in docker, and it's much easier
to supply the API key as an environment variable, so this changes the
logic to use the API key from the command line when running in docker
_or_ CI.
This commit is contained in:
Chris Raible 2025-01-07 20:03:39 -08:00 committed by GitHub
parent c1f9740665
commit 0c56c9bb8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View file

@ -13,6 +13,8 @@ services:
volumes:
- .:/home/ghost
tty: true
env_file:
- .env
depends_on:
- mysql
- redis

View file

@ -11,7 +11,10 @@ const Stripe = require('stripe').Stripe;
const configUtils = require('../../utils/configUtils');
const startWebhookServer = (port) => {
const command = `stripe listen --forward-connect-to http://127.0.0.1:${port}/members/webhooks/stripe/ ${process.env.CI ? `--api-key ${process.env.STRIPE_SECRET_KEY}` : ''}`.trim();
const isCI = process.env.CI;
const isDocker = process.env.COMPOSE_PROFILES === 'full';
const stripeSecretKey = process.env.STRIPE_SECRET_KEY;
const command = `stripe listen --forward-connect-to http://127.0.0.1:${port}/members/webhooks/stripe/ ${isDocker || isCI ? `--api-key ${stripeSecretKey}` : ''}`.trim();
const webhookServer = spawn(command.split(' ')[0], command.split(' ').slice(1));
// Adding event listeners here seems to prevent heisenbug where webhooks aren't received
@ -22,7 +25,10 @@ const startWebhookServer = (port) => {
};
const getWebhookSecret = async () => {
const command = `stripe listen --print-secret ${process.env.CI ? `--api-key ${process.env.STRIPE_SECRET_KEY}` : ''}`.trim();
const isCI = process.env.CI;
const isDocker = process.env.COMPOSE_PROFILES === 'full';
const stripeSecretKey = process.env.STRIPE_SECRET_KEY;
const command = `stripe listen --print-secret ${isDocker || isCI ? `--api-key ${stripeSecretKey}` : ''}`.trim();
const webhookSecret = (await promisify(exec)(command)).stdout;
return webhookSecret.toString().trim();
};