Skip to content

Commit 1a8b1ed

Browse files
authored
Merge pull request #51 from flatrun/feat/container-name-resolution
enh(api): Add getServices endpoint and delegate container naming
2 parents ef57429 + 4259b06 commit 1a8b1ed

3 files changed

Lines changed: 44 additions & 14 deletions

File tree

src/components/NewDeploymentModal.vue

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,6 @@ const getDatabaseServiceYaml = () => {
19511951
return `
19521952
db:
19531953
image: mysql:8
1954-
container_name: ${form.name}-db
19551954
environment:
19561955
MYSQL_ROOT_PASSWORD: ${rootPassword}
19571956
MYSQL_DATABASE: ${dbName}
@@ -1966,7 +1965,6 @@ const getDatabaseServiceYaml = () => {
19661965
return `
19671966
db:
19681967
image: mariadb:10
1969-
container_name: ${form.name}-db
19701968
environment:
19711969
MYSQL_ROOT_PASSWORD: ${rootPassword}
19721970
MYSQL_DATABASE: ${dbName}
@@ -1981,7 +1979,6 @@ const getDatabaseServiceYaml = () => {
19811979
return `
19821980
db:
19831981
image: postgres:15
1984-
container_name: ${form.name}-db
19851982
environment:
19861983
POSTGRES_DB: ${dbName}
19871984
POSTGRES_USER: ${db.dbUser || "app"}
@@ -1995,7 +1992,6 @@ const getDatabaseServiceYaml = () => {
19951992
return `
19961993
db:
19971994
image: mongo:6
1998-
container_name: ${form.name}-db
19991995
environment:
20001996
MONGO_INITDB_ROOT_USERNAME: ${db.dbUser || "app"}
20011997
MONGO_INITDB_ROOT_PASSWORD: ${db.dbPassword}
@@ -2032,7 +2028,6 @@ const buildComposeTemplate = (name: string, ports: { containerPort: number; host
20322028
services:
20332029
app:
20342030
image: nginx:alpine
2035-
container_name: ${name}
20362031
${portConfig}
20372032
networks:
20382033
- ${networkName}
@@ -2072,7 +2067,6 @@ const buildComposeFromImage = () => {
20722067
services:
20732068
app:
20742069
image: ${image}
2075-
container_name: ${name}
20762070
${portConfig}
20772071
networks:
20782072
- ${networkName}

src/services/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import axios from "axios";
22
import type {
33
Deployment,
4+
Service,
45
Network,
56
Certificate,
67
ProxyStatus,
@@ -83,6 +84,7 @@ export const deploymentsApi = {
8384
const queryString = params.toString();
8485
return apiClient.delete(`/deployments/${name}${queryString ? `?${queryString}` : ""}`);
8586
},
87+
getServices: (name: string) => apiClient.get<{ services: Service[] }>(`/deployments/${name}/services`),
8688
start: (name: string) => apiClient.post(`/deployments/${name}/start`),
8789
stop: (name: string) => apiClient.post(`/deployments/${name}/stop`),
8890
restart: (name: string) => apiClient.post(`/deployments/${name}/restart`),

src/views/CronJobsView.vue

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,21 @@
229229
</div>
230230

231231
<div class="form-group">
232-
<label for="service">Service (optional)</label>
233-
<input
232+
<label for="service">
233+
Service
234+
<i v-if="loadingServices" class="pi pi-spin pi-spinner" style="margin-left: 4px" />
235+
</label>
236+
<select
234237
id="service"
235238
v-model="form.service"
236-
type="text"
237-
placeholder="web, app, worker..."
238-
:disabled="saving"
239-
/>
240-
<span class="hint">Leave empty to use deployment name as container</span>
239+
:disabled="saving || loadingServices || !form.deployment_name"
240+
>
241+
<option value="">Default ({{ form.deployment_name || "select deployment" }})</option>
242+
<option v-for="svc in deploymentServices" :key="svc.name" :value="svc.name">
243+
{{ svc.name }}
244+
</option>
245+
</select>
246+
<span class="hint">Target service container for the command</span>
241247
</div>
242248

243249
<div class="form-group">
@@ -374,7 +380,7 @@
374380
import { ref, computed, onMounted, watch } from "vue";
375381
import { schedulerApi, deploymentsApi } from "@/services/api";
376382
import type { ScheduledTask, TaskExecution } from "@/services/api";
377-
import type { Deployment } from "@/types";
383+
import type { Deployment, Service } from "@/types";
378384
import { useNotificationsStore } from "@/stores/notifications";
379385
import { useAuthStore } from "@/stores/auth";
380386
import ConfirmModal from "@/components/ConfirmModal.vue";
@@ -512,6 +518,34 @@ const defaultForm = (): CronJobForm => ({
512518
});
513519
514520
const form = ref<CronJobForm>(defaultForm());
521+
const deploymentServices = ref<Service[]>([]);
522+
const loadingServices = ref(false);
523+
524+
const fetchDeploymentServices = async (deploymentName: string) => {
525+
if (!deploymentName) {
526+
deploymentServices.value = [];
527+
return;
528+
}
529+
loadingServices.value = true;
530+
try {
531+
const response = await deploymentsApi.getServices(deploymentName);
532+
deploymentServices.value = response.data.services || [];
533+
} catch {
534+
deploymentServices.value = [];
535+
} finally {
536+
loadingServices.value = false;
537+
}
538+
};
539+
540+
watch(
541+
() => form.value.deployment_name,
542+
(name, oldName) => {
543+
if (oldName) {
544+
form.value.service = "";
545+
}
546+
fetchDeploymentServices(name);
547+
},
548+
);
515549
516550
const isFormValid = computed(() => {
517551
return Boolean(

0 commit comments

Comments
 (0)