New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re-add GitHubBridge to support self-hosting with separate content repos #4384
base: main
Are you sure you want to change the base?
Conversation
- One important caveat is that this approach could lead to GitHub rate limiting errors on certain projects, particularly larger sites with lots of pages/files - The ability to pass `systemFiles` to the `GithubBridge` is intended to allow multi-tenant projects where the content repos do not need to contain any Tina folders or files at all. The code repository can pass the necessary Tina system files to the GitHub bridge at built time, and no Tina files need to be committed or tracked in the content repositories. This is particularly useful when multiple content repositories/sites are built from a central code repository
🦋 Changeset detectedLatest commit: 2ddccfa The changes in this PR will be included in the next version bump. This PR includes changesets to release 19 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This updates the GitHubBridge to extend the FilesystemBridge and optionally fallback to the latter when fetching Tina files. This provides a path to support self-hosting with separate content repos without needing those separate content repos to track all the Tina files from the code repository. We can instead specifically opt to use the Tina files from the local filesystem in the code repository.
FWIW I've pulled the GithubBridge into my own project because I'm trying to self host with a separate content repo. Here are some notes:
|
Yeah, all good points. I'll add my 2 cents on each one but definitely don't have all the right answers myself either! Incidentally I'm not sure whether the Tina team are likely to consider including this PR in the core repo (and definitely fine either way). I partly opened it simply to share the code and continue the discussion - happily it's easy to just copy the
I hope that brain dump is helpful. Let us know how you go and any issues or creative solutions you stumble on! 👍 PS: Tina team - let us know if you would consider merging this PR (no worries if not), or whether you think there's a section within the documentation at https://tina.io/docs where notes on this should be added. It'd be great to have a version of the API route to re-index all Tina system files and content filesNote this is written for an API route using the new Next.js app router, in a file path of // app/api/reindex/route.ts
import { NextResponse, type NextRequest } from 'next/server'
import database from '@tina/database'
import schema from '@tina/__generated__/_schema.json'
import graphql from '@tina/__generated__/_graphql.json'
import lookup from '@tina/__generated__/_lookup.json'
const INDEX_KEY_FIELD_SEPARATOR = '\x1D'
const CONTENT_ROOT_PREFIX = '~'
const SUBLEVEL_OPTIONS = {
separator: INDEX_KEY_FIELD_SEPARATOR,
valueEncoding: 'json',
}
// export const revalidate = 0
// Example usage
// fetch('http://localhost:3000/api/reindex', {
// method: 'POST',
// body: JSON.stringify({
// token: process.env.API_ROUTE_SECRET,
// }),
// }).then(console.log)
export async function POST(request: NextRequest) {
const resBody = await request.json()
const isAuthorized = resBody.token === process.env.API_ROUTE_SECRET
if (isAuthorized) {
try {
// NOTE: 'tinacms' is used below as it's the default contentNamespace,
// unless you pass a custom namespace when initialising your database.
const contentLevel =
database.contentLevel ??
database.rootLevel
.sublevel('_content', SUBLEVEL_OPTIONS)
.sublevel('tinacms', SUBLEVEL_OPTIONS)
const contentRootLevel = contentLevel.sublevel(
CONTENT_ROOT_PREFIX,
SUBLEVEL_OPTIONS
)
// Upload all Tina system files to the data layer
await contentRootLevel.put(
'tina/__generated__/_graphql.json',
graphql as any
)
await contentRootLevel.put(
'tina/__generated__/_schema.json',
schema as any
)
await contentRootLevel.put(
'tina/__generated__/_lookup.json',
lookup as any
)
// Or index all the content
// (this might not re-index the Tina files, hence the code above)
await database._indexAllContent(contentLevel as any, schema as any)
return NextResponse.json({ success: true }, { status: 200 })
} catch (error) {
return NextResponse.json({ error: error }, { status: 500 })
}
} else {
return NextResponse.json({ error: 'Not found' }, { status: 401 })
}
} |
TinaCMS GitHub Bridge
The
GitHubBridge
is intended to support self-hosting with separate content repositories (e.g. one central code repository that is able to build multiple sitesThis will also help provide a path to better support reindexing for self-hosted projects (i.e. keeping the data layer updated when changes are pushed directly via git, rather than made through the Tina UI)
Background
Additional notes
tinaFilesConfig
is intended to support multi-tenant projects where the Tina folder lives in the code repository so the content repositories do not need to contain any Tina folders or files at all. In this case theGitHubBridge
will defer to theFilesystemBridge
to retrieve the auto-generated Tina files, so those files do not need to be committed or tracked in the content repositories. This is particularly useful when multiple content repositories/sites are built from a central code repository.GitHubBridge
to thetinacms-gitprovider-github
package given it already has@octokit/rest
installed, and to avoid a proliferation of separate GitHub-related packages in thetinacms
monorepo. Let me know if you'd prefer a separate package just for the GitHubBridge and I can restructure these updates.Documentation
See the new sections added to the latest version of the
README
for thetinacms-gitprovider-github
package here: https://github.com/tinacms/tinacms/blob/2ddccfa4969c183c15a2647bff3d4dd57aa7b141/packages/tinacms-gitprovider-github/README.md