Part 2 on my conversion of my back-end django app to a Docker container.
In order to properly test my integration with Stripe, I need to use the Stripe CLI and setup a webhook forwarder (official documentation here).
This used to run on the server, but now that we're containerising the application, it will run in its own container and forward the webhooks through to the django container. Stripe publishes an official CLI container image (here), which I'll go about configuring and using in my local development environment.
This turned out to be once-again very easy to configure. I added the container to my docker-compose.yaml
file, shared the STRIPE_API_KEY
environment variable across the Django and Stripe containers, and forward the requests to the django container. Here's a little snippet of what I ended up doing:
---
version: '3'
services:
django:
container_name: django
build:
context: django
platform: linux/amd64
volumes:
- ./django:/app
ports:
- '8081:8081'
environment:
PORT: 8081
STRIPE_API_KEY: "${STRIPE_API_KEY}"
stripe:
container_name: stripe-cli
image: stripe/stripe-cli
command: listen --forward-to http://django:8081/stripe-webhooks
environment:
STRIPE_API_KEY: "${STRIPE_API_KEY}"