add patch
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
repos
 | 
			
		||||
@@ -61,7 +61,7 @@ currently, bsky and bsync require patches to function properly. additionally, so
 | 
			
		||||
|name|service|patch|
 | 
			
		||||
|---|---|---|
 | 
			
		||||
|pds|https://github.com/bluesky-social/atproto/blob/main/services/pds/Dockerfile||
 | 
			
		||||
|bsky|https://github.com/bluesky-social/atproto/blob/main/services/bsky/Dockerfile|[itaru2622/bluesky-atproto-bsky](https://hub.docker.com/r/itaru2622/bluesky-atproto-bsky)|
 | 
			
		||||
|bsky|https://github.com/bluesky-social/atproto/blob/main/services/bsky/Dockerfile|[itaru2622/bluesky-atproto-bsky](https://github.com/itaru2622/bluesky-selfhost-env/blob/master/patching/105-atproto-services-for-docker.diff)|
 | 
			
		||||
|bsync|https://github.com/bluesky-social/atproto/blob/main/services/bsync/Dockerfile||
 | 
			
		||||
|ozone|https://github.com/bluesky-social/atproto/blob/main/services/ozone/Dockerfile||
 | 
			
		||||
|plc|https://github.com/did-method-plc/did-method-plc/tree/main/packages/server||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										16
									
								
								install.zsh
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								install.zsh
									
									
									
									
									
								
							@@ -115,14 +115,20 @@ function at-repos-bsky-patch() {
 | 
			
		||||
	f=$d/repos/atproto/services/bsky/api.js
 | 
			
		||||
	curl -sL https://raw.githubusercontent.com/bluesky-social/atproto/refs/heads/main/services/bsky/api.js -o $f
 | 
			
		||||
	d_=$d/repos/atproto
 | 
			
		||||
	p_=$d_/105-atproto-services-for-docker.diff
 | 
			
		||||
	cd $d_
 | 
			
		||||
	# https://github.com/itaru2622/bluesky-selfhost-env/blob/master/patching/105-atproto-services-for-docker.diff
 | 
			
		||||
	curl -sLO https://raw.githubusercontent.com/itaru2622/bluesky-selfhost-env/refs/heads/master/patching/105-atproto-services-for-docker.diff
 | 
			
		||||
	echo "applying patch: under ${d_} for ${p_}"
 | 
			
		||||
	p_=$d/patching/105-atproto-services-for-docker.diff
 | 
			
		||||
	cd ${d_}
 | 
			
		||||
	if [ ! -f ${p_} ];then
 | 
			
		||||
		# https://github.com/itaru2622/bluesky-selfhost-env/blob/master/patching/105-atproto-services-for-docker.diff
 | 
			
		||||
		echo download patch: https://github.com/itaru2622/bluesky-selfhost-env/blob/master/patching/105-atproto-services-for-docker.diff
 | 
			
		||||
		curl -sLO https://raw.githubusercontent.com/itaru2622/bluesky-selfhost-env/refs/heads/master/patching/105-atproto-services-for-docker.diff
 | 
			
		||||
	else
 | 
			
		||||
		echo local patch
 | 
			
		||||
	fi
 | 
			
		||||
	echo "applying patch: under ${f} for ${p_}"
 | 
			
		||||
	pushd ${d_}
 | 
			
		||||
	patch -p1 < ${p_}
 | 
			
		||||
	popd
 | 
			
		||||
	exit
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function at-repos-docker() {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										0
									
								
								patching/.keep
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								patching/.keep
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										85
									
								
								patching/105-atproto-services-for-docker.diff
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								patching/105-atproto-services-for-docker.diff
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,85 @@
 | 
			
		||||
diff --git a/services/bsky/api.js b/services/bsky/api.js
 | 
			
		||||
index 56c769b9d..5d14c0057 100644
 | 
			
		||||
--- a/services/bsky/api.js
 | 
			
		||||
+++ b/services/bsky/api.js
 | 
			
		||||
@@ -44,19 +44,62 @@ const assert = require('node:assert')
 | 
			
		||||
 const cluster = require('node:cluster')
 | 
			
		||||
 const path = require('node:path')
 | 
			
		||||
 | 
			
		||||
-const { BskyAppView, ServerConfig } = require('@atproto/bsky')
 | 
			
		||||
+const bsky = require('@atproto/bsky') // import all bsky features
 | 
			
		||||
 const { Secp256k1Keypair } = require('@atproto/crypto')
 | 
			
		||||
 
 | 
			
		||||
 const main = async () => {
 | 
			
		||||
   const env = getEnv()
 | 
			
		||||
-  const config = ServerConfig.readEnv()
 | 
			
		||||
+  const config = bsky.ServerConfig.readEnv()
 | 
			
		||||
   assert(env.serviceSigningKey, 'must set BSKY_SERVICE_SIGNING_KEY')
 | 
			
		||||
   const signingKey = await Secp256k1Keypair.import(env.serviceSigningKey)
 | 
			
		||||
-  const bsky = BskyAppView.create({ config, signingKey })
 | 
			
		||||
-  await bsky.start()
 | 
			
		||||
+
 | 
			
		||||
+// starts: involve logics in packages/dev-env/src/bsky.ts >>>>>>>>>>>>>
 | 
			
		||||
+// Separate migration db in case migration changes some connection state that we need in the tests, e.g. "alter database ... set ..."
 | 
			
		||||
+  const migrationDb = new bsky.Database({
 | 
			
		||||
+      url: env.dbPostgresUrl,
 | 
			
		||||
+      schema: env.dbPostgresSchema,
 | 
			
		||||
+    })
 | 
			
		||||
+  if (env.migration) {
 | 
			
		||||
+      await migrationDb.migrateToOrThrow(env.migration)
 | 
			
		||||
+  } else {
 | 
			
		||||
+      await migrationDb.migrateToLatestOrThrow()
 | 
			
		||||
+  }
 | 
			
		||||
+  await migrationDb.close()
 | 
			
		||||
+
 | 
			
		||||
+  const db = new bsky.Database({
 | 
			
		||||
+      url: env.dbPostgresUrl,
 | 
			
		||||
+      schema: env.dbPostgresSchema,
 | 
			
		||||
+      poolSize: 10,
 | 
			
		||||
+  })
 | 
			
		||||
+
 | 
			
		||||
+  const dataplane = await bsky.DataPlaneServer.create(
 | 
			
		||||
+      db,
 | 
			
		||||
+      env.dataplanePort,
 | 
			
		||||
+      config.didPlcUrl
 | 
			
		||||
+  )
 | 
			
		||||
+
 | 
			
		||||
+  const bsync = await bsky.MockBsync.create(db, env.bsyncPort)
 | 
			
		||||
+
 | 
			
		||||
+// ends: involve logics in packages/dev-env/src/bsky.ts   <<<<<<<<<<<<<
 | 
			
		||||
+
 | 
			
		||||
+  const server = bsky.BskyAppView.create({ config, signingKey })
 | 
			
		||||
+// starts: involve logics in packages/dev-env/src/bsky.ts >>>>>>>>>>>>>
 | 
			
		||||
+  const sub = new bsky.RepoSubscription({
 | 
			
		||||
+      service: env.repoProvider,
 | 
			
		||||
+      db,
 | 
			
		||||
+      idResolver: dataplane.idResolver,
 | 
			
		||||
+      background: new bsky.BackgroundQueue(db),
 | 
			
		||||
+    })
 | 
			
		||||
+// ends: involve logics in packages/dev-env/src/bsky.ts   <<<<<<<<<<<<<
 | 
			
		||||
+  await server.start()
 | 
			
		||||
+  sub.start() // involve logics in packages/dev-env/src/bsky.ts
 | 
			
		||||
   // Graceful shutdown (see also https://aws.amazon.com/blogs/containers/graceful-shutdowns-with-ecs/)
 | 
			
		||||
   const shutdown = async () => {
 | 
			
		||||
-    await bsky.destroy()
 | 
			
		||||
+    await server.destroy()
 | 
			
		||||
+    await bsync.destroy()
 | 
			
		||||
+    await dataplane.destroy()
 | 
			
		||||
+    await sub.destroy()
 | 
			
		||||
+    await db.close()
 | 
			
		||||
   }
 | 
			
		||||
   process.on('SIGTERM', shutdown)
 | 
			
		||||
   process.on('disconnect', shutdown) // when clustering
 | 
			
		||||
@@ -64,6 +107,12 @@ const main = async () => {
 | 
			
		||||
 
 | 
			
		||||
 const getEnv = () => ({
 | 
			
		||||
   serviceSigningKey: process.env.BSKY_SERVICE_SIGNING_KEY || undefined,
 | 
			
		||||
+  dbPostgresUrl:     process.env.BSKY_DB_POSTGRES_URL     || undefined,
 | 
			
		||||
+  dbPostgresSchema:  process.env.BSKY_DB_POSTGRES_SCHEMA  || undefined,
 | 
			
		||||
+  dataplanePort :    maybeParseInt(process.env.BSKY_DATAPLANE_PORT)     || undefined,
 | 
			
		||||
+  bsyncPort :        maybeParseInt(process.env.BSKY_BSYNC_PORT)         || undefined,
 | 
			
		||||
+  migration:         process.env.ENABLE_MIGRATIONS === 'true'           || undefined,
 | 
			
		||||
+  repoProvider:      process.env.BSKY_REPO_PROVIDER                     || undefined
 | 
			
		||||
 })
 | 
			
		||||
 
 | 
			
		||||
 const maybeParseInt = (str) => {
 | 
			
		||||
		Reference in New Issue
	
	Block a user