Remove ecosystem configuration file, add Docker entrypoint script, and update deployment workflow to build and push Docker images. Enhance AdminPage with Docker export functionality and improve post management API to use dynamic posts directory path.

This commit is contained in:
2025-06-20 17:13:52 +02:00
parent 803b9899df
commit fb8f7f43ee
24 changed files with 529 additions and 174 deletions

View File

@@ -0,0 +1,69 @@
import tar from 'tar';
import { NextResponse } from 'next/server';
import { statSync, createReadStream, existsSync } from 'fs';
import path from 'path';
export async function GET() {
try {
const rootDir = process.cwd();
const dockerDir = path.join(rootDir, 'docker');
const postsDir = path.join(rootDir, 'posts');
let tarballName: string;
let tarballPath: string;
let tarCwd: string;
let tarItems: string[];
let tarOptions: any = {
gzip: true,
portable: true,
noMtime: true,
};
if (existsSync(dockerDir)) {
// Docker is in use: export the entire root directory (excluding node_modules, .next, etc)
tarballName = 'root-export.tar.gz';
tarballPath = path.join('/tmp', tarballName);
tarCwd = rootDir;
tarItems = ['.'];
tarOptions.file = tarballPath;
tarOptions.cwd = tarCwd;
tarOptions.filter = (filepath: string) => {
// Exclude node_modules, .next, .git, /tmp, and tarball itself
const excludes = [
'node_modules', '.next', '.git', 'tmp', 'docker.sock', tarballName
];
// Only check top-level folders/files
const rel = filepath.split(path.sep)[0];
return !excludes.includes(rel);
};
} else {
// Not docker: export only the posts directory
tarballName = 'posts-export.tar.gz';
tarballPath = path.join('/tmp', tarballName);
tarCwd = rootDir;
tarItems = ['posts'];
tarOptions.file = tarballPath;
tarOptions.cwd = tarCwd;
}
// Create tarball
await tar.c(
tarOptions,
tarItems
);
// Stream the tarball as a response
const stat = statSync(tarballPath);
const stream = createReadStream(tarballPath);
return new Response(stream as any, {
status: 200,
headers: {
'Content-Type': 'application/gzip',
'Content-Disposition': `attachment; filename="${tarballName}"`,
'Content-Length': stat.size.toString(),
},
});
} catch (error) {
console.error('Error exporting tarball:', error);
return NextResponse.json({ error: 'Error exporting tarball' }, { status: 500 });
}
}