Files
Infra-Management/app/Http/Controllers/Container/StackController.php
I-Fun c649f055d8 feat: initialize Infra Manager with React, Tailwind CSS, and Inertia.js
- Added main application entry point (app.jsx) and bootstrap file for React setup.
- Created Wiki index page (Index.jsx) for documentation and file management.
- Implemented utility functions for formatting and status handling in utils.js.
- Set up Blade template (app.blade.php) for Inertia.js integration.
- Defined API routes for metrics and terminal access in api.php.
- Established console commands for scheduled tasks in console.php.
- Created web routes for various application features including authentication, hypervisors, containers, cloud accounts, security, backups, and wiki management in web.php.
- Developed setup scripts for Windows (setup.ps1) and Linux (setup.sh) environments.
- Configured Tailwind CSS for styling with custom themes and animations in tailwind.config.js.
- Set up Vite for asset bundling and development server in vite.config.js.
2026-04-07 20:29:32 +07:00

69 lines
2.1 KiB
PHP

<?php
namespace App\Http\Controllers\Container;
use App\Http\Controllers\Controller;
use App\Models\DockerEndpoint;
use App\Models\Stack;
use App\Services\Container\DockerManager;
use Illuminate\Http\Request;
use Inertia\Inertia;
class StackController extends Controller
{
public function __construct(private DockerManager $docker) {}
public function index()
{
return Inertia::render('Container/Stacks', [
'stacks' => Stack::with('endpoint')->orderBy('name')->paginate(20),
'endpoints' => DockerEndpoint::all(),
]);
}
public function create()
{
return Inertia::render('Container/StackCreate', ['endpoints' => DockerEndpoint::all()]);
}
public function store(Request $request)
{
$validated = $request->validate([
'name' => 'required|string|max:100',
'endpoint_id' => 'required|exists:docker_endpoints,id',
'compose_content' => 'required|string',
'env_vars' => 'nullable|array',
]);
Stack::create([...$validated, 'created_by' => auth()->id()]);
return redirect()->route('stacks.index')->with('success', 'Stack created.');
}
public function show(Stack $stack)
{
return Inertia::render('Container/StackShow', ['stack' => $stack->load('endpoint')]);
}
public function edit(Stack $stack)
{
return Inertia::render('Container/StackEdit', ['stack' => $stack, 'endpoints' => DockerEndpoint::all()]);
}
public function update(Request $request, Stack $stack)
{
$stack->update($request->only('name', 'compose_content', 'env_vars'));
return redirect()->route('stacks.show', $stack)->with('success', 'Stack updated.');
}
public function destroy(Stack $stack)
{
$stack->delete();
return redirect()->route('stacks.index')->with('success', 'Stack deleted.');
}
public function deploy(Stack $stack)
{
$this->docker->deployStack($stack->endpoint, $stack->name, $stack->compose_content, $stack->env_vars ?? []);
return back()->with('success', 'Stack deployed.');
}
}