docs: update README with Cloudflare deployment information #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to Cloudflare | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
name: Deploy | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
cache: 'npm' | |
- name: Install Dependencies | |
run: | | |
npm ci | |
cd dropship-frontend && npm ci | |
cd ../dropship-backend && npm ci | |
npm install -g wrangler | |
- name: Build Frontend | |
run: | | |
cd dropship-frontend | |
npm run build | |
env: | |
VITE_API_URL: ${{ secrets.CLOUDFLARE_API_URL }} | |
VITE_WS_URL: ${{ secrets.CLOUDFLARE_WS_URL }} | |
- name: Deploy Frontend to Cloudflare Pages | |
uses: cloudflare/wrangler-action@v3 | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
command: pages publish dropship-frontend/build --project-name=dropship-platform | |
- name: Deploy Worker | |
uses: cloudflare/wrangler-action@v3 | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
command: publish cloudflare/worker.js | |
env: | |
API_ENDPOINT: ${{ secrets.API_ENDPOINT }} | |
WS_ENDPOINT: ${{ secrets.WS_ENDPOINT }} | |
CF_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
- name: Create KV Namespace (if not exists) | |
uses: cloudflare/wrangler-action@v3 | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
command: kv:namespace create DROPSHIP_KV || true | |
- name: Configure DNS | |
uses: cloudflare/wrangler-action@v3 | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
command: | | |
dns record create \ | |
--type CNAME \ | |
--name ${{ secrets.DOMAIN }} \ | |
--content ${{ secrets.CLOUDFLARE_PAGES_URL }} \ | |
--proxied true | |
- name: Configure Workers Routes | |
uses: cloudflare/wrangler-action@v3 | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
command: | | |
route add ${{ secrets.DOMAIN }}/* dropship-platform | |
route add ${{ secrets.DOMAIN }}/api/* dropship-platform-api | |
route add ${{ secrets.DOMAIN }}/ws dropship-platform-ws | |
- name: Deploy D1 Database | |
uses: cloudflare/wrangler-action@v3 | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
command: d1 create dropship-platform-db --location=WEUR | |
- name: Configure Cron Triggers | |
uses: cloudflare/wrangler-action@v3 | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
command: | | |
cron create "*/5 * * * *" dropship-platform-cron | |
cron enable dropship-platform-cron | |
- name: Deploy R2 Storage | |
uses: cloudflare/wrangler-action@v3 | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
command: r2 bucket create dropship-platform-storage | |
- name: Configure Analytics | |
uses: cloudflare/wrangler-action@v3 | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
command: analytics enable | |
- name: Notify Deployment Status | |
if: always() | |
uses: 8398a7/action-slack@v3 | |
with: | |
status: ${{ job.status }} | |
fields: repo,message,commit,author,action,eventName,ref,workflow | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
env: | |
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |