Skip to content

Instantly share code, notes, and snippets.

@z4nr34l
Created May 20, 2024 07:19
Show Gist options
  • Save z4nr34l/33e20051f2af441949141d24aec2e231 to your computer and use it in GitHub Desktop.
Save z4nr34l/33e20051f2af441949141d24aec2e231 to your computer and use it in GitHub Desktop.
Tinybird github + vercel integration for nextjs projects.

As there is no officially supported integration that really works I've prepared a simple CI/CD pipelines to cover vercel's preview and production environments.

Instruction

1. Create 3 Tinybird workspaces:

  • <name>_dev,
  • <name>_stage,
  • <name>

To reflect vercel's environments. (They will also be separated on tinybird so in case of mistake you will not nuke production env)

2. Add github workflow piplelines

Below this readme you will find ready workflows taht you need to deploy inside .github/workflows/

3. Setup github actions

Learn more about Using secrets in github actions here.

GH secrets naming:

TB_STAGE_TOKEN - Tinybird stage (<name>_stage) workspace admin token

TB_ADMIN_TOKEN - Tinybird production (<name>) workspace admin token

IMPORTANT Replace <tb_project_dir> with your repo's tinybird directory path inside workflow files!

4. Development enviroment

Option 1

Use your Tinybird CLI to work with dev (<name>_dev) enviroment.

Option 2

When your are using UI to manage your tinybird instances you need to make tb pull using tinybird cli to pull config files to your repository code.

name: Tinybird - Production
on:
workflow_dispatch:
push:
branches:
- main
- master
paths:
- '<tb_project_dir>/**'
- '.github/workflows/tinybird*'
jobs:
deploy:
runs-on: ubuntu-latest
defaults:
run:
working-directory: <tb_project_dir>
steps:
- uses: actions/checkout@master
with:
fetch-depth: 300
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-python@v5
with:
python-version: '3.11'
architecture: 'x64'
cache: 'pip'
- name: Install Tinybird CLI
run: pip install tinybird-cli
- name: Authenticate with Tinybird
run: tb auth --token ${{ secrets.TB_ADMIN_TOKEN }}
- name: Check all the datafiles syntax
run: tb check
- name: Deploy to Tinybird
run: tb push --push-deps
name: Tinybird - Stage
on:
workflow_dispatch:
pull_request:
branches:
- main
- master
types: [opened, reopened, labeled, unlabeled, synchronize, closed]
paths:
- '<tb_project_dir>/**'
- '.github/workflows/tinybird*'
jobs:
deploy:
runs-on: ubuntu-latest
defaults:
run:
working-directory: <tb_project_dir>
steps:
- uses: actions/checkout@master
with:
fetch-depth: 300
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-python@v5
with:
python-version: '3.11'
architecture: 'x64'
cache: 'pip'
- name: Install Tinybird CLI
run: pip install tinybird-cli
- name: Authenticate with Tinybird
run: tb auth --token ${{ secrets.TB_STAGE_TOKEN }}
- name: Check all the datafiles syntax
run: tb check
- name: Deploy to Tinybird
run: tb push --push-deps --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment