Skip to content

Commit

Permalink
Deploy Script + README (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
qianl15 authored May 1, 2024
1 parent ffb011c commit bd25d4f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 27 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ jobs:
npm prune --omit=dev
npm install @dbos-inc/dbos-cloud@latest
- name: Deploy to prod
run: python3 scripts/dbos_deploy.py
run: bash scripts/dbos_deploy.sh
env:
DBOS_DOMAIN: cloud.dbos.dev
DBOS_APP_DB_NAME: dbos_subscription
STRIPE_SECRET_KEY: ${{secrets.STRIPE_PROD_SECRET_KEY}}
STRIPE_WEBHOOK_SECRET: ${{secrets.STRIPE_PROD_WEBHOOK_SECRET}}
STRIPE_DBOS_PRO_PRICE: ${{secrets.STRIPE_PROD_PRO_PRICE}}
DBOS_DEPLOY_REFRESH_TOKEN: ${{secrets.DBOS_PROD_DEPLOY_REFRESH_TOKEN}}
DBOS_TEST_REFRESH_TOKEN: ${{secrets.DBOS_PROD_TEST_REFRESH_TOKEN}}
DBOS_TEST_REFRESH_TOKEN: ${{secrets.DBOS_PROD_TEST_REFRESH_TOKEN}}
DBOS_DB_PASSWORD: ${{secrets.DBOS_PROD_DB_PASSWORD}}
3 changes: 2 additions & 1 deletion .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
npm prune --omit=dev
npm install @dbos-inc/dbos-cloud@latest
- name: Deploy to staging
run: python3 scripts/dbos_deploy.py
run: bash scripts/dbos_deploy.sh
env:
DBOS_DOMAIN: staging.dev.dbos.dev
DBOS_APP_DB_NAME: testsubscription
Expand All @@ -28,3 +28,4 @@ jobs:
STRIPE_DBOS_PRO_PRICE: ${{secrets.STRIPE_TEST_PRO_PRICE}}
DBOS_DEPLOY_REFRESH_TOKEN: ${{secrets.DBOS_TEST_DEPLOY_REFRESH_TOKEN}}
DBOS_TEST_REFRESH_TOKEN: ${{secrets.DBOS_TEST_TEST_REFRESH_TOKEN}}
DBOS_DB_PASSWORD: ${{secrets.DBOS_TEST_DB_PASSWORD}}
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# DBOS Cloud Subscription
# DBOS Cloud Account Management

This is an app backing DBOS subscription page.
This repo contains code for our cloud account subscription management app, which is built with DBOS Transact and Stripe, and deployed on DBOS Cloud.

## Overview
When a customer clicks "Upgrade to DBOS Pro" on our [website](https://www.dbos.dev/pricing), this app redirects them to a customized Stripe checkout page, where they enter payment information. After they pay, Stripe sends a notification to a webhook endpoint on this app. The webhook retrieves the customer's updated subscription status from Stripe, maps their Stripe customer ID to a DBOS Cloud account ID, and updates their subscription status in DBOS Cloud.

This repo demonstrates a complete production DBOS application, including cloud deployment and CI/CD, written in <500 lines of code. Specifically, it highlights:

- Use of DBOS workflows, transactions, and communicators for reliable, exactly-once execution
- Asynchronous and reliable event processing for [Stripe Webhook](https://docs.stripe.com/webhooks)
- Integration with [Stripe Billing](https://stripe.com/billing) and [Stripe Customer Portal](https://docs.stripe.com/customer-management)
- Integration with [Auth0](https://auth0.com/) for authentication and authorization
- Using [Knex.js](https://knexjs.org/) for schema management and queries
- Automated testing and deployment with DBOS CLI and [GitHub Actions](https://github.com/features/actions)
- Unit tests for individual functions and endpoints with [jest](https://jestjs.io/).

## Code Layout

The main source code files:
- `src/`
- `operations.ts` HTTP endpoints
- `utils.ts` Workflows, transactions, and communicators
- `operations.test.ts` Unit tests
- `dbos-config.yaml` DBOS configuration file
- `migrations/` Schema definition in Knex.js format

Files for CI/CD:
- `scripts/`
- `dbos_deploy.sh` Script that deploys this app to DBOS Cloud
- `staging_test.py` Automated testing scripts that runs against staging
- `.github/workflows/` Github Actions for deployment and testing
22 changes: 0 additions & 22 deletions scripts/dbos_deploy.py

This file was deleted.

12 changes: 12 additions & 0 deletions scripts/dbos_deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

npx dbos-cloud login --with-refresh-token ${DBOS_DEPLOY_REFRESH_TOKEN}
npx dbos-cloud db status ${DBOS_APP_DB_NAME} > /dev/null
if [[ $? -ne 0 ]]; then
npx dbos-cloud db provision ${DBOS_APP_DB_NAME} -U subscribe -W ${DBOS_DB_PASSWORD}
fi
npx dbos-cloud app status
if [[ $? -ne 0 ]]; then
npx dbos-cloud app register -d ${DBOS_APP_DB_NAME}
fi
npx dbos-cloud app deploy

0 comments on commit bd25d4f

Please sign in to comment.