exporting for docker works now!
Some checks failed
Deploy / build-and-deploy (push) Failing after 1s

This commit is contained in:
2025-06-21 14:15:51 +02:00
parent e17b15ab28
commit 1054820ce7
2 changed files with 22 additions and 49 deletions

View File

@@ -586,9 +586,11 @@ export default function AdminPage() {
<button <button
onClick={() => { onClick={() => {
if (isDocker) { if (isDocker) {
// Custom popup for Docker support message handleExportTarball();
} else {
// Custom popup for local server message
const dockerSupportPopup = document.createElement('div'); const dockerSupportPopup = document.createElement('div');
dockerSupportPopup.innerHTML = 'Exporting from Docker is not supported yet.'; dockerSupportPopup.innerHTML = ' Exporting from local server isn\'t supported, please pull from the server\'s Filesystem';
dockerSupportPopup.style.position = 'fixed'; dockerSupportPopup.style.position = 'fixed';
dockerSupportPopup.style.top = '50%'; dockerSupportPopup.style.top = '50%';
dockerSupportPopup.style.left = '50%'; dockerSupportPopup.style.left = '50%';
@@ -602,13 +604,11 @@ export default function AdminPage() {
setTimeout(() => { setTimeout(() => {
document.body.removeChild(dockerSupportPopup); document.body.removeChild(dockerSupportPopup);
}, 3000); }, 3000);
} else {
handleExportTarball();
} }
}} }}
className="px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700" className="px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700"
> >
Export Posts Export Docker Posts
</button> </button>
</div> </div>
</div> </div>

View File

@@ -5,55 +5,28 @@ import path from 'path';
export async function GET() { export async function GET() {
try { try {
const rootDir = process.cwd(); const dockerDir = '/app/docker'; // update this to your actual path
const dockerDir = path.join(rootDir, 'docker'); const tarballName = 'docker-export.tar.gz';
const postsDir = path.join(rootDir, 'posts'); const tarballPath = path.join('/tmp', tarballName);
let tarballName: string;
let tarballPath: string;
let tarCwd: string;
let tarItems: string[];
let tarOptions: any = {
gzip: true,
portable: true,
noMtime: true,
};
if (existsSync(dockerDir)) { if (!existsSync(dockerDir)) {
// Docker is in use: export the entire root directory (excluding node_modules, .next, etc) return NextResponse.json({ error: `${dockerDir} directory does not exist` }, { status: 400 });
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( await tar.c(
tarOptions, {
tarItems gzip: true,
file: tarballPath,
cwd: path.dirname(dockerDir),
portable: true,
noMtime: true,
},
[path.basename(dockerDir)]
); );
// Stream the tarball as a response
const stat = statSync(tarballPath); const stat = statSync(tarballPath);
const stream = createReadStream(tarballPath); const stream = createReadStream(tarballPath);
return new Response(stream as any, { return new Response(stream as any, {
status: 200, status: 200,
headers: { headers: {
@@ -63,7 +36,7 @@ export async function GET() {
}, },
}); });
} catch (error) { } catch (error) {
console.error('Error exporting tarball:', error); console.error('Error exporting docker:', error);
return NextResponse.json({ error: 'Error exporting tarball' }, { status: 500 }); return NextResponse.json({ error: 'Error exporting docker' }, { status: 500 });
} }
} }