Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.
TypeScript albumsexif-extractiongeocodinglive-photomotion-photophoto-galleryphoto-sharingwebgl-viewer
fix(deploy): redesign dockerfile and migration processing
Timothy Yin05c1d96cd034
diff --git a/Dockerfile b/Dockerfileindex 1ca05b31..9ebafd5b 100644--- a/Dockerfile+++ b/Dockerfile@@ -16,14 +16,21 @@ COPY --from=deps /usr/src/app/packages/webgl-image/node_modules ./packages/webglCOPY . .RUN NODE_OPTIONS="--max-old-space-size=4096" pnpm run build:depsRUN NODE_OPTIONS="--max-old-space-size=8192" pnpm run build+RUN find ./.output -type f -name '*.map' -delete-FROM node:22.22.2-alpine AS runtime-RUN apk update && apk add --no-cache perl exiftool+FROM alpine:3.22 AS runtime_deps+RUN apk add --no-cache nodejs libstdc++ ca-certificates++FROM scratch AS runtimeWORKDIR /app+COPY --from=runtime_deps /usr/bin/node /usr/bin/node+COPY --from=runtime_deps /usr/lib /usr/lib+COPY --from=runtime_deps /usr/share /usr/share+COPY --from=runtime_deps /lib /lib+COPY --from=runtime_deps /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt+COPY --from=build /usr/src/app/.output ./.output-COPY --from=build /usr/src/app/packages/webgl-image/dist ./packages/webgl-image/dist-COPY --from=build /usr/src/app/scripts ./scriptsCOPY --from=build /usr/src/app/server/database/migrations ./server/database/migrationsEXPOSE 3000@@ -32,6 +39,6 @@ VOLUME ["/app/data"]ENV NODE_ENV=productionENV NITRO_PORT=3000ENV NITRO_HOST=0.0.0.0+ENV DATABASE_URL=./data/app.sqlite3-# node scripts/migrate.mjs first-CMD ["sh", "-c", "node scripts/migrate.mjs && node .output/server/index.mjs"]+CMD ["/usr/bin/node", ".output/server/index.mjs"]diff --git a/server/plugins/0.db-migrate.ts b/server/plugins/0.db-migrate.tsnew file mode 100644index 00000000..0ea15552--- /dev/null+++ b/server/plugins/0.db-migrate.ts@@ -0,0 +1,38 @@+import { mkdirSync } from 'node:fs'+import { dirname, resolve } from 'node:path'++import Database from 'better-sqlite3'+import { drizzle } from 'drizzle-orm/better-sqlite3'+import { migrate } from 'drizzle-orm/better-sqlite3/migrator'++let migrationPromise: Promise<void> | null = null+const migrationLogger = logger.dynamic('db-migrate')++async function runMigrations() {+ const dbPath = resolve(process.env.DATABASE_URL || './data/app.sqlite3')++ mkdirSync(dirname(dbPath), { recursive: true })++ const sqlite = new Database(dbPath)++ try {+ const db = drizzle(sqlite)+ await migrate(db, {+ migrationsFolder: resolve('./server/database/migrations'),+ })+ migrationLogger.info('Database migration finished successfully')+ } finally {+ sqlite.close()+ }+}++export default defineNitroPlugin(async () => {+ if (!migrationPromise) {+ migrationPromise = runMigrations().catch((error) => {+ migrationLogger.error('Database migration failed', error)+ throw error+ })+ }++ await migrationPromise+})