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
onClick={() => {
if (isDocker) {
// Custom popup for Docker support message
handleExportTarball();
} else {
// Custom popup for local server message
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.top = '50%';
dockerSupportPopup.style.left = '50%';
@@ -602,13 +604,11 @@ export default function AdminPage() {
setTimeout(() => {
document.body.removeChild(dockerSupportPopup);
}, 3000);
} else {
handleExportTarball();
}
}}
className="px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700"
>
Export Posts
Export Docker Posts
</button>
</div>
</div>

View File

@@ -5,55 +5,28 @@ 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,
};
const dockerDir = '/app/docker'; // update this to your actual path
const tarballName = 'docker-export.tar.gz';
const tarballPath = path.join('/tmp', tarballName);
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;
if (!existsSync(dockerDir)) {
return NextResponse.json({ error: `${dockerDir} directory does not exist` }, { status: 400 });
}
// Create tarball
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 stream = createReadStream(tarballPath);
return new Response(stream as any, {
status: 200,
headers: {
@@ -63,7 +36,7 @@ export async function GET() {
},
});
} catch (error) {
console.error('Error exporting tarball:', error);
return NextResponse.json({ error: 'Error exporting tarball' }, { status: 500 });
console.error('Error exporting docker:', error);
return NextResponse.json({ error: 'Error exporting docker' }, { status: 500 });
}
}