aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Dockerfile11
-rw-r--r--README.md2
-rw-r--r--scripts/migrate.js22
3 files changed, 33 insertions, 2 deletions
diff --git a/Dockerfile b/Dockerfile
index 8f2c00b..d7811ed 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -11,7 +11,14 @@ WORKDIR /app
COPY --from=builder /app/build build/
COPY --from=builder /app/node_modules node_modules/
COPY --from=builder /app/package.json ./
+COPY --from=builder /app/drizzle drizzle/
+COPY --from=builder /app/scripts/migrate.js scripts/migrate.js
+RUN mkdir -p /app/data && chown -R node:node /app
+VOLUME /app/data
EXPOSE 3000
ENV NODE_ENV=production
-ENV DATABASE_URL=file:./data.db
-CMD ["node", "build"]
+ENV DATABASE_URL=file:./data/data.db
+HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
+ CMD node -e "require('http').get('http://localhost:3000/', r => {process.exit(r.statusCode === 200 ? 0 : 1)})"
+USER node
+CMD ["sh", "-c", "node scripts/migrate.js && node build"]
diff --git a/README.md b/README.md
index 498a708..bfc2ebe 100644
--- a/README.md
+++ b/README.md
@@ -57,3 +57,5 @@ efficient shopping walk.
- [ ] Full FR
- [ ] Find a design identity
+- [ ] Deploy
+- [ ] Auth
diff --git a/scripts/migrate.js b/scripts/migrate.js
new file mode 100644
index 0000000..dee9411
--- /dev/null
+++ b/scripts/migrate.js
@@ -0,0 +1,22 @@
+import { createClient } from '@libsql/client';
+import { readdirSync, readFileSync } from 'node:fs';
+import { join } from 'node:path';
+
+const dbUrl = process.env.DATABASE_URL ?? 'file:./data/data.db';
+const client = createClient({ url: dbUrl });
+
+const dir = '/app/drizzle';
+const files = readdirSync(dir)
+ .filter((f) => f.endsWith('.sql'))
+ .sort();
+
+for (const file of files) {
+ const sql = readFileSync(join(dir, file), 'utf8');
+ const stmts = sql.split('--> statement-breakpoint').filter(Boolean);
+ for (const stmt of stmts) {
+ await client.execute(stmt);
+ }
+}
+
+console.log(`${files.length} migration(s) applied.`);
+client.close();