service.html

262 lines
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
{{template "main.html" .}}

{{define "title"}}{{if services.Service}}{{services.Service.Name}} —{{end}} Congo Dev{{end}}

{{define "content"}}
{{with services.Service}}
<div class="fade-up">
<!-- Header -->
<div class="flex items-center gap-3 mb-4">
    <a href="/" class="w-9 h-9 inline-flex items-center justify-center rounded-xl text-slate-400 hover:text-slate-600 hover:bg-white/60 transition-all btn-press">
        <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M15 19l-7-7 7-7" /></svg>
    </a>
    <div class="flex-1 min-w-0">
        <div class="flex items-center gap-2.5">
            <h1 class="text-lg font-bold text-slate-800 truncate">{{.Name}}</h1>
            {{if eq .Status "running"}}
            <span class="inline-flex items-center gap-1.5 text-[10px] font-medium text-emerald-600 bg-emerald-50 px-2.5 py-0.5 rounded-full shadow-sm shadow-emerald-100"><span class="w-1.5 h-1.5 rounded-full bg-emerald-500 glow-emerald"></span> Running</span>
            {{else if eq .Status "stopped"}}
            <span class="inline-flex items-center gap-1.5 text-[10px] font-medium text-slate-400 bg-slate-100 px-2.5 py-0.5 rounded-full"><span class="w-1.5 h-1.5 rounded-full bg-slate-300"></span> Stopped</span>
            {{else}}
            <span class="inline-flex items-center gap-1.5 text-[10px] font-medium text-slate-400 bg-slate-100 px-2.5 py-0.5 rounded-full"><span class="w-1.5 h-1.5 rounded-full bg-slate-200"></span> Not Deployed</span>
            {{end}}
        </div>
        <p class="text-[11px] text-slate-400 font-mono mt-0.5">{{if .Mode}}{{.Mode}} · {{end}}port {{if .ContainerPort}}{{.ContainerPort}}{{else}}5000{{end}}{{if .Domain}} · <span class="text-indigo-400">{{.Domain}}</span>{{end}}</p>
    </div>
    <!-- Action buttons -->
    <div class="hidden sm:flex items-center gap-1.5 shrink-0">
        {{if eq .Status "running"}}
        {{if eq .Mode "binary"}}
        <button class="inline-flex items-center gap-1.5 px-3 h-8 rounded-xl text-[11px] font-medium text-slate-500 bg-white/80 border border-slate-200/60 hover:border-slate-300 hover:text-slate-700 transition-all hover:shadow-sm btn-press" hx-post="/services/{{.RepoName}}/{{.Name}}/run-binary" hx-target="body" title="Rebuild and restart binary">
            <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" /></svg>
            Rebuild
        </button>
        <button class="inline-flex items-center gap-1.5 px-3 h-8 rounded-xl text-[11px] font-medium text-red-400 bg-white/80 border border-slate-200/60 hover:border-red-200 hover:text-red-500 hover:bg-red-50 transition-all btn-press" hx-post="/services/{{.RepoName}}/{{.Name}}/stop-binary" hx-target="body" title="Stop binary">
            Stop
        </button>
        {{else}}
        <button class="inline-flex items-center gap-1.5 px-3 h-8 rounded-xl text-[11px] font-medium text-slate-500 bg-white/80 border border-slate-200/60 hover:border-slate-300 hover:text-slate-700 transition-all hover:shadow-sm btn-press" hx-post="/services/{{.RepoName}}/{{.Name}}/restart" hx-target="body" title="Restart container">
            <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" /></svg>
            Restart
        </button>
        <button class="inline-flex items-center gap-1.5 px-3 h-8 rounded-xl text-[11px] font-medium text-red-400 bg-white/80 border border-slate-200/60 hover:border-red-200 hover:text-red-500 hover:bg-red-50 transition-all btn-press" hx-post="/services/{{.RepoName}}/{{.Name}}/stop" hx-target="body" title="Stop container">
            Stop
        </button>
        {{end}}
        {{else if eq .Status "stopped"}}
        <button class="inline-flex items-center gap-1.5 px-3 h-8 rounded-xl text-[11px] font-medium text-white bg-gradient-to-r from-indigo-500 to-indigo-600 hover:from-indigo-600 hover:to-indigo-700 transition-all shadow-sm shadow-indigo-500/20 btn-press" hx-post="/services/{{.RepoName}}/{{.Name}}/start" hx-target="body" title="Start container">
            Start
        </button>
        {{end}}
        <button class="inline-flex items-center gap-1.5 px-3 h-8 rounded-xl text-[11px] font-medium text-teal-600 bg-white/80 border border-slate-200/60 hover:border-teal-200 hover:text-teal-700 hover:bg-teal-50 transition-all hover:shadow-sm btn-press" hx-post="/services/{{.RepoName}}/{{.Name}}/run-binary" hx-target="body" title="Build and run as Go binary">
            <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3" /></svg>
            Binary
        </button>
        <button class="inline-flex items-center gap-1.5 px-3 h-8 rounded-xl text-[11px] font-medium text-slate-500 bg-white/80 border border-slate-200/60 hover:border-slate-300 hover:text-slate-700 transition-all hover:shadow-sm btn-press" hx-post="/services/{{.RepoName}}/{{.Name}}/redeploy" hx-target="body" hx-confirm="Rebuild and redeploy {{.Name}} in Docker?" title="Redeploy in Docker">
            <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2" /></svg>
            Docker
        </button>
        <button class="inline-flex items-center justify-center w-8 h-8 rounded-xl text-slate-300 bg-white/80 border border-slate-200/60 hover:border-red-200 hover:text-red-400 hover:bg-red-50 transition-all btn-press" hx-post="/services/{{.RepoName}}/{{.Name}}/delete" hx-target="body" hx-confirm="Delete service {{.Name}}? This will stop and remove the container." title="Delete">
            <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" /></svg>
        </button>
    </div>
</div>

<!-- Content: Two-column on desktop -->
<div class="grid grid-cols-1 lg:grid-cols-5 gap-4">
    <!-- Left: Logs -->
    <div class="lg:col-span-3">
        <div class="panel-card">
            <div class="flex items-center justify-between px-4 pt-3 pb-2">
                <h3 class="text-[11px] font-semibold uppercase tracking-wider text-slate-400">Logs</h3>
                <div class="flex items-center gap-1">
                    <button class="text-[10px] text-slate-300 hover:text-slate-500 transition-colors" onclick="var el = document.getElementById('service-logs'); if (el) { var pre = el.querySelector('pre'); if (pre) pre.scrollTop = pre.scrollHeight; }" title="Scroll to bottom">
                        <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M19 14l-7 7m0 0l-7-7m7 7V3" /></svg>
                    </button>
                </div>
            </div>
            <div class="px-4 pb-4">
                <div id="service-logs" hx-get="/services/{{.RepoName}}/{{.Name}}/logs" hx-trigger="load, every 3s" hx-swap="innerHTML">
                    <div class="h-40 bg-slate-900 rounded-xl flex items-center justify-center">
                        <span class="loading loading-dots loading-sm text-slate-600"></span>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Right: Config -->
    <div class="lg:col-span-2 space-y-4">
        <!-- Environment -->
        <div class="panel-card">
            <div class="px-4 pt-3 pb-2">
                <h3 class="text-[11px] font-semibold uppercase tracking-wider text-slate-400">Environment</h3>
            </div>
            <div class="px-4 pb-4">
                {{render "EnvEditor" (dict "env" services.EnvJSON "actionUrl" (printf "/services/%s/%s/env" .RepoName .Name))}}
            </div>
        </div>

        <!-- Domain -->
        <div class="panel-card">
            <div class="px-4 pt-3 pb-2">
                <h3 class="text-[11px] font-semibold uppercase tracking-wider text-slate-400">Domain</h3>
            </div>
            <div class="px-4 pb-4">
                <form hx-post="/services/{{.RepoName}}/{{.Name}}/domain" hx-target="body" class="space-y-2">
                    <div class="flex items-center gap-2">
                        <input type="text" name="domain" value="{{.Domain}}" placeholder="app.example.com"
                            class="flex-1 font-mono text-[12px] text-slate-600 bg-slate-50/80 border border-slate-200/60 rounded-xl px-3 py-2 focus:outline-none focus:border-indigo-300 focus:ring-2 focus:ring-indigo-100 transition-all" />
                        <button type="submit" class="inline-flex items-center px-3 py-2 rounded-xl text-[11px] font-medium text-white bg-gradient-to-r from-indigo-500 to-indigo-600 hover:from-indigo-600 hover:to-indigo-700 transition-all shadow-sm shadow-indigo-500/20 shrink-0 btn-press">Update</button>
                    </div>
                    {{if .Domain}}
                    <div class="flex items-center gap-2 mt-1">
                        <p class="text-[10px] text-slate-400 ml-0.5 flex-1">Point <code class="font-mono text-indigo-500">{{.Domain}}</code> to this server's IP. TLS auto-provisions via Caddy.</p>
                        {{with services.ServiceDomainID}}
                        <span id="dns-status" hx-get="/routes/{{.}}/check" hx-trigger="load" hx-swap="innerHTML" hx-target="this" class="shrink-0"></span>
                        {{end}}
                    </div>
                    {{else}}
                    <p class="text-[10px] text-slate-400 ml-0.5">Assign a custom domain. TLS auto-provisions via Caddy.</p>
                    {{end}}
                </form>
            </div>
        </div>

        <!-- Source -->
        {{if .RepoID}}
        <div class="panel-card">
            <div class="px-4 pt-3 pb-2">
                <h3 class="text-[11px] font-semibold uppercase tracking-wider text-slate-400">Source</h3>
            </div>
            <div class="px-4 pb-3">
                <a href="/repos/{{.RepoID}}" class="flex items-center gap-2.5 px-3 py-2.5 rounded-lg hover:bg-slate-50 transition-colors group">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 text-slate-300 group-hover:text-indigo-400 transition-colors" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5"><path stroke-linecap="round" stroke-linejoin="round" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"/></svg>
                    <span class="text-[12px] text-indigo-600 font-medium group-hover:text-indigo-700 transition-colors">{{.RepoName}}</span>
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-3 h-3 text-slate-300 ml-auto" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M9 5l7 7-7 7" /></svg>
                </a>
            </div>
        </div>
        {{end}}

        <!-- Deploy History -->
        {{with services.ServiceHistory}}
        <div class="panel-card">
            <div class="px-4 pt-3 pb-2">
                <h3 class="text-[11px] font-semibold uppercase tracking-wider text-slate-400">Deploy History</h3>
            </div>
            <div class="px-4 pb-3 space-y-0.5">
                {{range .}}
                <div class="flex items-start gap-2 py-1">
                    {{if eq .Type "deploy"}}
                    <span class="w-1.5 h-1.5 rounded-full mt-1.5 shrink-0 {{if contains .Summary "failed"}}bg-red-400{{else}}bg-violet-400{{end}}"></span>
                    {{else if eq .Type "restart"}}
                    <span class="w-1.5 h-1.5 rounded-full mt-1.5 shrink-0 bg-amber-400"></span>
                    {{else if eq .Type "stop"}}
                    <span class="w-1.5 h-1.5 rounded-full mt-1.5 shrink-0 bg-slate-300"></span>
                    {{else if eq .Type "start"}}
                    <span class="w-1.5 h-1.5 rounded-full mt-1.5 shrink-0 bg-emerald-400"></span>
                    {{else}}
                    <span class="w-1.5 h-1.5 rounded-full mt-1.5 shrink-0 bg-slate-300"></span>
                    {{end}}
                    <span class="text-[11px] {{if contains .Summary "failed"}}text-red-500{{else}}text-slate-500{{end}} flex-1 break-words">{{.Summary}}</span>
                    <span class="text-[10px] text-slate-300 shrink-0 font-mono">{{.Ago}}</span>
                </div>
                {{end}}
            </div>
        </div>
        {{end}}

        <!-- Build & Runtime Settings -->
        <div class="panel-card">
            <div class="px-4 pt-3 pb-2">
                <h3 class="text-[11px] font-semibold uppercase tracking-wider text-slate-400">Settings</h3>
            </div>
            <form hx-post="/services/{{.RepoName}}/{{.Name}}/settings" hx-target="body" class="px-4 pb-4 space-y-3">
                <div>
                    <label class="text-[10px] font-medium text-slate-500 block mb-1">Source Path</label>
                    <input type="text" name="build_path" value="{{.Spec.Source}}" placeholder=". (repo root)"
                        class="w-full font-mono text-[12px] text-slate-600 bg-slate-50/80 border border-slate-200/60 rounded-lg px-3 py-1.5 focus:outline-none focus:border-indigo-300 focus:ring-1 focus:ring-indigo-100 transition-all" />
                    <p class="text-[10px] text-slate-400 mt-0.5">Path to Dockerfile directory within the repo</p>
                </div>
                <div>
                    <label class="text-[10px] font-medium text-slate-500 block mb-1">Listen Port</label>
                    <input type="number" name="container_port" value="{{if .ContainerPort}}{{.ContainerPort}}{{else}}5000{{end}}" min="1" max="65535"
                        class="w-24 font-mono text-[12px] text-slate-600 bg-slate-50/80 border border-slate-200/60 rounded-lg px-3 py-1.5 focus:outline-none focus:border-indigo-300 focus:ring-1 focus:ring-indigo-100 transition-all" />
                    <p class="text-[10px] text-slate-400 mt-0.5">Port the app serves on inside the container. Caddy routes to this.</p>
                </div>
                <div>
                    <label class="text-[10px] font-medium text-slate-500 block mb-1">Expose Ports</label>
                    <input type="text" name="expose_ports" value="{{range $i, $p := .ExposedPorts}}{{if $i}},{{end}}{{$p.Host}}:{{$p.Container}}{{end}}" placeholder="e.g. 25:25,587:587"
                        class="w-full font-mono text-[12px] text-slate-600 bg-slate-50/80 border border-slate-200/60 rounded-lg px-3 py-1.5 focus:outline-none focus:border-indigo-300 focus:ring-1 focus:ring-indigo-100 transition-all" />
                    <p class="text-[10px] text-slate-400 mt-0.5">Host ports to bind directly (for SMTP, etc). Format: host:container. Leave empty for HTTP-only services.</p>
                </div>
                <button type="submit" class="inline-flex items-center px-3 py-1.5 rounded-lg text-[11px] font-medium text-white bg-gradient-to-r from-indigo-500 to-indigo-600 hover:from-indigo-600 hover:to-indigo-700 transition-all shadow-sm shadow-indigo-500/20 btn-press">
                    Save Settings
                </button>
                <p class="text-[10px] text-slate-400">Changes are saved to infra.json. Redeploy to apply.</p>
            </form>
            <div class="border-t border-slate-100/60 mx-0 my-3"></div>
            <div class="px-4 pb-4">
                <label class="text-[10px] font-medium text-slate-500 block mb-1.5">Volumes</label>
                {{render "VolumeEditor" (dict "volumes" services.VolumesJSON "actionUrl" (printf "/services/%s/%s/settings" .RepoName .Name))}}
            </div>
        </div>

        <!-- Runtime Info -->
        <div class="panel-card">
            <div class="px-4 pt-3 pb-2">
                <h3 class="text-[11px] font-semibold uppercase tracking-wider text-slate-400">Runtime</h3>
            </div>
            <div class="px-4 pb-3 space-y-1.5">
                {{if .Mode}}
                <div class="flex items-center justify-between py-1">
                    <span class="text-[11px] text-slate-400">Mode</span>
                    <span class="text-[11px] font-mono text-slate-600 bg-slate-100/80 px-2 py-0.5 rounded-md">{{.Mode}}</span>
                </div>
                {{end}}
                <div class="flex items-center justify-between py-1">
                    <span class="text-[11px] text-slate-400">{{if eq .Mode "binary"}}Process{{else}}Container{{end}}</span>
                    <span class="text-[11px] font-mono text-slate-600 bg-slate-100/80 px-2 py-0.5 rounded-md">{{if eq .Mode "binary"}}{{.RepoName}}-{{.Name}}{{else}}{{.ContainerName}}{{end}}</span>
                </div>
                <div class="flex items-center justify-between py-1">
                    <span class="text-[11px] text-slate-400">Listen Port</span>
                    <span class="text-[11px] font-mono text-slate-600 bg-slate-100/80 px-2 py-0.5 rounded-md">{{if .ContainerPort}}{{.ContainerPort}}{{else}}5000{{end}}</span>
                </div>
                {{if .ExposedPorts}}
                <div class="flex items-center justify-between py-1">
                    <span class="text-[11px] text-slate-400">Exposed</span>
                    <span class="text-[11px] font-mono text-slate-600 bg-slate-100/80 px-2 py-0.5 rounded-md">{{range $i, $p := .ExposedPorts}}{{if $i}} {{end}}:{{$p.Host}}&rarr;:{{$p.Container}}{{end}}</span>
                </div>
                {{end}}
                <div class="flex items-center justify-between py-1">
                    <span class="text-[11px] text-slate-400">Image</span>
                    <span class="text-[11px] font-mono text-slate-600 bg-slate-100/80 px-2 py-0.5 rounded-md truncate ml-4">{{.Image}}</span>
                </div>
                {{if .Spec.Source}}
                <div class="flex items-center justify-between py-1">
                    <span class="text-[11px] text-slate-400">Source</span>
                    <span class="text-[11px] font-mono text-slate-600 bg-slate-100/80 px-2 py-0.5 rounded-md">{{.Spec.Source}}</span>
                </div>
                {{end}}
                {{with services.ServiceUptime}}
                <div class="flex items-center justify-between py-1">
                    <span class="text-[11px] text-slate-400">Uptime</span>
                    <span class="text-[11px] font-mono text-emerald-600 bg-emerald-50 px-2 py-0.5 rounded-md">{{.}}</span>
                </div>
                {{end}}
            </div>
        </div>
    </div>
</div>
</div>
{{else}}
<div class="text-center py-16 fade-up">
    <div class="inline-flex items-center justify-center w-12 h-12 rounded-2xl bg-slate-50 mb-3">
        <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 text-slate-300" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5"><path stroke-linecap="round" stroke-linejoin="round" d="M9.75 9.75l4.5 4.5m0-4.5l-4.5 4.5M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>
    </div>
    <p class="text-slate-400 mb-3 text-sm">Service not found</p>
    <a href="/" class="text-indigo-500 hover:text-indigo-600 text-sm transition-colors">Back to Dashboard</a>
</div>
{{end}}
{{end}}