From a904c74fbbddfc22eb042e1fe45efc52bd2cb41a Mon Sep 17 00:00:00 2001 From: LP B Date: Thu, 24 Oct 2024 05:09:34 +0200 Subject: [PATCH] fix(app): deploy container app template (#59) Co-authored-by: oscarzhou --- app/docker/services/containerService.js | 9 ++++++++- app/docker/services/volumeService.js | 2 +- .../accessControlForm/porAccessControlFormModel.js | 13 +++++++++++++ .../views/templates/templatesController.js | 4 ++-- .../containers/CreateView/useCreateMutation.tsx | 4 ++++ .../volumes/queries/useCreateVolumeMutation.ts | 2 +- .../volumes/queries/useRemoveVolumeMutation.ts | 2 +- 7 files changed, 30 insertions(+), 6 deletions(-) diff --git a/app/docker/services/containerService.js b/app/docker/services/containerService.js index ed808f11c..d9eb7999b 100644 --- a/app/docker/services/containerService.js +++ b/app/docker/services/containerService.js @@ -19,6 +19,7 @@ import { createExec } from '@/react/docker/containers/queries/useCreateExecMutat import { containerStats } from '@/react/docker/containers/queries/useContainerStats'; import { containerTop } from '@/react/docker/containers/queries/useContainerTop'; import { createOrReplace } from '@/react/docker/containers/CreateView/useCreateMutation'; +import { toReactAccessControlFormData } from '@/portainer/components/accessControlForm/porAccessControlFormModel'; import { ContainerDetailsViewModel } from '../models/containerDetails'; import { ContainerStatsViewModel } from '../models/containerStats'; @@ -91,11 +92,17 @@ function ContainerServiceFactory(AngularToReact) { /** * @param {Environment} environment * @param {*} configuration + * @param {AccessControlFormData} accessControlFormData */ - async function createAndStartContainer(environment, configuration) { + async function createAndStartContainer(environment, configuration, accessControlFormData) { return createOrReplace({ config: configuration, environment, + values: { + name: configuration.name, + imageName: configuration.Image, + accessControl: toReactAccessControlFormData(accessControlFormData), + }, }); } diff --git a/app/docker/services/volumeService.js b/app/docker/services/volumeService.js index b12e6195e..f26f2ee1d 100644 --- a/app/docker/services/volumeService.js +++ b/app/docker/services/volumeService.js @@ -83,7 +83,7 @@ function VolumeServiceFactory(AngularToReact) { * @param {number} count */ async function createXAutoGeneratedLocalVolumes(environmentId, count) { - const promises = Array(count).map(createVolume(environmentId, { Driver: 'local' })); + const promises = Array.from({ length: count }).map(() => createAngularJS(environmentId, { Driver: 'local' })); return Promise.all(promises); } } diff --git a/app/portainer/components/accessControlForm/porAccessControlFormModel.js b/app/portainer/components/accessControlForm/porAccessControlFormModel.js index e4c77d961..e7ebeaab5 100644 --- a/app/portainer/components/accessControlForm/porAccessControlFormModel.js +++ b/app/portainer/components/accessControlForm/porAccessControlFormModel.js @@ -9,3 +9,16 @@ export function AccessControlFormData() { this.AuthorizedUsers = []; this.AuthorizedTeams = []; } + +/** + * Transform AngularJS UAC FormData model to React UAC FormData model + * @param {AccessControlFormData} uac AngularJS format (see above) + * @returns {AccessControlFormData} React format (see at @/react/portainer/access-control/types) + */ +export function toReactAccessControlFormData({ Ownership, AuthorizedTeams, AuthorizedUsers }) { + return { + ownership: Ownership, // type: ResourceControlOwnership; + authorizedUsers: AuthorizedUsers, // type: UserId[]; + authorizedTeams: AuthorizedTeams, // type: TeamId[]; + }; +} diff --git a/app/portainer/views/templates/templatesController.js b/app/portainer/views/templates/templatesController.js index 97658cb81..f413363ca 100644 --- a/app/portainer/views/templates/templatesController.js +++ b/app/portainer/views/templates/templatesController.js @@ -114,10 +114,10 @@ angular.module('portainer.app').controller('TemplatesController', [ generatedVolumeIds.push(volumeId); }); TemplateService.updateContainerConfigurationWithVolumes(templateConfiguration, template, data); - return ImageService.pullImage(template.RegistryModel, true); + return ImageService.pullImage(template.RegistryModel); }) .then(function success() { - return ContainerService.createAndStartContainer(endpoint, templateConfiguration); + return ContainerService.createAndStartContainer(endpoint, templateConfiguration, accessControlData); }) .then(function success(data) { const resourceControl = data.Portainer.ResourceControl; diff --git a/app/react/docker/containers/CreateView/useCreateMutation.tsx b/app/react/docker/containers/CreateView/useCreateMutation.tsx index 420daabc1..afd849943 100644 --- a/app/react/docker/containers/CreateView/useCreateMutation.tsx +++ b/app/react/docker/containers/CreateView/useCreateMutation.tsx @@ -118,6 +118,8 @@ async function create({ containerResponse.Portainer?.ResourceControl, registry ); + + return containerResponse; } async function replace({ @@ -163,6 +165,8 @@ async function replace({ await removeContainer(environment.Id, oldContainer.Id, { nodeName: oldContainer.NodeName, }); + + return containerResponse; } /** diff --git a/app/react/docker/volumes/queries/useCreateVolumeMutation.ts b/app/react/docker/volumes/queries/useCreateVolumeMutation.ts index c51c693b3..6d145a9e5 100644 --- a/app/react/docker/volumes/queries/useCreateVolumeMutation.ts +++ b/app/react/docker/volumes/queries/useCreateVolumeMutation.ts @@ -16,7 +16,7 @@ export type VolumeConfiguration = { export async function createVolume( environmentId: EnvironmentId, volumeConfiguration: VolumeConfiguration, - { nodeName }: { nodeName: string } + { nodeName }: { nodeName?: string } = {} ) { try { const { data } = await axios.post( diff --git a/app/react/docker/volumes/queries/useRemoveVolumeMutation.ts b/app/react/docker/volumes/queries/useRemoveVolumeMutation.ts index 1c4720afd..caa3ea81e 100644 --- a/app/react/docker/volumes/queries/useRemoveVolumeMutation.ts +++ b/app/react/docker/volumes/queries/useRemoveVolumeMutation.ts @@ -9,7 +9,7 @@ import { withAgentTargetHeader } from '../../proxy/queries/utils'; export async function removeVolume( environmentId: EnvironmentId, name: Volume['Name'], - { nodeName }: { nodeName: string } + { nodeName }: { nodeName?: string } = {} ) { try { await axios.delete(buildDockerProxyUrl(environmentId, 'volumes', name), {