Skip to content

Commit

Permalink
Add a new docker-compose.stripe.yaml that also launches the worker co…
Browse files Browse the repository at this point in the history
…ntainer
  • Loading branch information
micahflee committed Sep 20, 2024
1 parent 010a2c4 commit af9c4a7
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .env.stripe-sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
STRIPE_SECRET_KEY=sk_test_changeme
STRIPE_WEBHOOK_SECRET=whsec_changeme
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ hushline/static/data/users_directory.json
/node_modules
.coverage
htmlcov
.env.stripe
52 changes: 52 additions & 0 deletions docker-compose.stripe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
services:
app: &app_env
build:
context: .
dockerfile: Dockerfile.dev
ports:
- 127.0.0.1:8080:8080
environment:
FLASK_APP: hushline
FLASK_ENV: development
ENCRYPTION_KEY: bi5FDwhZGKfc4urLJ_ChGtIAaOPgxd3RDOhnvct10mw=
SECRET_KEY: cb3f4afde364bfb3956b97ca22ef4d2b593d9d980a4330686267cabcd2c0befd
SQLALCHEMY_DATABASE_URI: postgresql://hushline:hushline@postgres:5432/hushline
REGISTRATION_CODES_REQUIRED: False
SESSION_COOKIE_NAME: session
NOTIFICATIONS_ADDRESS: notifications@hushline.app
env_file:
- .env.stripe
volumes:
- ./:/app
depends_on:
- postgres
restart: always
command: poetry run flask run --debug --host=0.0.0.0 --port=8080 --with-threads

worker:
<<: *app_env
ports: []
restart: always
command: poetry run flask stripe start-worker
depends_on:
- stripe_data

stripe_data:
<<: *app_env
ports: []
restart: on-failure
command: poetry run flask stripe create-products-and-prices

dev_data:
<<: *app_env
ports: []
restart: on-failure
command: make migrate-dev && ./scripts/dev_data.py

postgres:
image: postgres:16.4-alpine3.20
environment:
POSTGRES_USER: hushline
POSTGRES_PASSWORD: hushline
POSTGRES_DB: hushline
1 change: 1 addition & 0 deletions hushline/premium.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def handle_invoice_payment_succeeded(invoice: stripe.Invoice) -> None:


async def worker(app: Flask) -> None:
current_app.logger.error("Starting worker")
with app.app_context():
while True:
stripe_event = (
Expand Down
21 changes: 20 additions & 1 deletion scripts/dev_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from hushline import create_app
from hushline.db import db
from hushline.model import User, Username
from hushline.model import Tier, User, Username


def main() -> None:
Expand Down Expand Up @@ -47,6 +47,25 @@ def main() -> None:

print(f"Test user:\n username = {data['username']}\n password = {data['password']}")

tiers = [
{
"name": "Free",
"monthly_amount": 0,
},
{
"name": "Business",
"monthly_amount": 2000,
},
]
for data in tiers:
tier = Tier.query.filter_by(name=data["name"]).first()
if not tier:
tier = Tier(name=data["name"], monthly_amount=data["monthly_amount"])
db.session.add(tier)
db.session.commit()

print(f"Tier:\n name = {data['name']}\n monthly_amount = {data['monthly_amount']}")


if __name__ == "__main__":
main()
9 changes: 0 additions & 9 deletions scripts/dev_migrations.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
#!/usr/bin/env python
from hushline import create_app
from hushline.db import db
from hushline.model import Tier


def main() -> None:
with create_app().app_context():
db.create_all()

# Add tiers
tiers = [
Tier(name="Free", monthly_amount=0),
Tier(name="Business", monthly_amount=2000),
]
db.session.bulk_save_objects(tiers)
db.session.commit()


if __name__ == "__main__":
main()

0 comments on commit af9c4a7

Please sign in to comment.