mirror of https://github.com/portainer/portainer
fix: windows container capability [EE-5814] (#11764)
parent
14a365045d
commit
e75e6cb7f7
|
@ -20,7 +20,7 @@ import { TextTip } from '@@/Tip/TextTip';
|
||||||
import { HelpLink } from '@@/HelpLink';
|
import { HelpLink } from '@@/HelpLink';
|
||||||
|
|
||||||
import { useContainers } from '../queries/containers';
|
import { useContainers } from '../queries/containers';
|
||||||
import { useSystemLimits } from '../../proxy/queries/useInfo';
|
import { useSystemLimits, useIsWindows } from '../../proxy/queries/useInfo';
|
||||||
|
|
||||||
import { useCreateOrReplaceMutation } from './useCreateMutation';
|
import { useCreateOrReplaceMutation } from './useCreateMutation';
|
||||||
import { useValidation } from './validation';
|
import { useValidation } from './validation';
|
||||||
|
@ -48,6 +48,7 @@ export function CreateView() {
|
||||||
function CreateForm() {
|
function CreateForm() {
|
||||||
const environmentId = useEnvironmentId();
|
const environmentId = useEnvironmentId();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const isWindows = useIsWindows(environmentId);
|
||||||
const { trackEvent } = useAnalytics();
|
const { trackEvent } = useAnalytics();
|
||||||
const isAdminQuery = useIsEdgeAdmin();
|
const isAdminQuery = useIsEdgeAdmin();
|
||||||
const { authorized: isEnvironmentAdmin } = useIsEnvironmentAdmin({
|
const { authorized: isEnvironmentAdmin } = useIsEnvironmentAdmin({
|
||||||
|
@ -57,7 +58,8 @@ function CreateForm() {
|
||||||
|
|
||||||
const mutation = useCreateOrReplaceMutation();
|
const mutation = useCreateOrReplaceMutation();
|
||||||
const initialValuesQuery = useInitialValues(
|
const initialValuesQuery = useInitialValues(
|
||||||
mutation.isLoading || mutation.isSuccess
|
mutation.isLoading || mutation.isSuccess,
|
||||||
|
isWindows
|
||||||
);
|
);
|
||||||
const registriesQuery = useEnvironmentRegistries(environmentId);
|
const registriesQuery = useEnvironmentRegistries(environmentId);
|
||||||
|
|
||||||
|
@ -84,9 +86,11 @@ function CreateForm() {
|
||||||
|
|
||||||
const environment = envQuery.data;
|
const environment = envQuery.data;
|
||||||
|
|
||||||
|
// if windows, hide capabilities. this is because capadd and capdel are not supported on windows
|
||||||
const hideCapabilities =
|
const hideCapabilities =
|
||||||
!environment.SecuritySettings.allowContainerCapabilitiesForRegularUsers &&
|
(!environment.SecuritySettings.allowContainerCapabilitiesForRegularUsers &&
|
||||||
!isEnvironmentAdmin;
|
!isEnvironmentAdmin) ||
|
||||||
|
isWindows;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isDuplicating = false,
|
isDuplicating = false,
|
||||||
|
|
|
@ -5,9 +5,10 @@ import { DockerContainer } from '../../types';
|
||||||
|
|
||||||
import { CONTAINER_MODE, Values } from './types';
|
import { CONTAINER_MODE, Values } from './types';
|
||||||
|
|
||||||
export function getDefaultViewModel() {
|
export function getDefaultViewModel(isWindows: boolean) {
|
||||||
|
const networkMode = isWindows ? 'nat' : 'bridge';
|
||||||
return {
|
return {
|
||||||
networkMode: 'bridge',
|
networkMode,
|
||||||
hostname: '',
|
hostname: '',
|
||||||
domain: '',
|
domain: '',
|
||||||
macAddress: '',
|
macAddress: '',
|
||||||
|
|
|
@ -57,7 +57,7 @@ export interface Values extends BaseFormValues {
|
||||||
env: EnvVarValues;
|
env: EnvVarValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useInitialValues(submitting: boolean) {
|
export function useInitialValues(submitting: boolean, isWindows: boolean) {
|
||||||
const {
|
const {
|
||||||
params: { nodeName, from },
|
params: { nodeName, from },
|
||||||
} = useCurrentStateAndParams();
|
} = useCurrentStateAndParams();
|
||||||
|
@ -86,7 +86,7 @@ export function useInitialValues(submitting: boolean) {
|
||||||
|
|
||||||
if (!from) {
|
if (!from) {
|
||||||
return {
|
return {
|
||||||
initialValues: defaultValues(isPureAdmin, user.Id, nodeName),
|
initialValues: defaultValues(isPureAdmin, user.Id, nodeName, isWindows),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,12 +151,13 @@ export function useInitialValues(submitting: boolean) {
|
||||||
function defaultValues(
|
function defaultValues(
|
||||||
isPureAdmin: boolean,
|
isPureAdmin: boolean,
|
||||||
currentUserId: UserId,
|
currentUserId: UserId,
|
||||||
nodeName: string
|
nodeName: string,
|
||||||
|
isWindows: boolean
|
||||||
): Values {
|
): Values {
|
||||||
return {
|
return {
|
||||||
commands: commandsTabUtils.getDefaultViewModel(),
|
commands: commandsTabUtils.getDefaultViewModel(),
|
||||||
volumes: volumesTabUtils.getDefaultViewModel(),
|
volumes: volumesTabUtils.getDefaultViewModel(),
|
||||||
network: networkTabUtils.getDefaultViewModel(),
|
network: networkTabUtils.getDefaultViewModel(isWindows), // windows containers should default to the nat network, not the bridge
|
||||||
labels: labelsTabUtils.getDefaultViewModel(),
|
labels: labelsTabUtils.getDefaultViewModel(),
|
||||||
restartPolicy: restartPolicyTabUtils.getDefaultViewModel(),
|
restartPolicy: restartPolicyTabUtils.getDefaultViewModel(),
|
||||||
resources: resourcesTabUtils.getDefaultViewModel(),
|
resources: resourcesTabUtils.getDefaultViewModel(),
|
||||||
|
|
|
@ -34,6 +34,14 @@ export function useInfo<TSelect = SystemInfo>(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useIsWindows(environmentId: EnvironmentId) {
|
||||||
|
const query = useInfo(environmentId, {
|
||||||
|
select: (info) => info.OSType === 'windows',
|
||||||
|
});
|
||||||
|
|
||||||
|
return !!query.data;
|
||||||
|
}
|
||||||
|
|
||||||
export function useIsStandAlone(environmentId: EnvironmentId) {
|
export function useIsStandAlone(environmentId: EnvironmentId) {
|
||||||
const query = useInfo(environmentId, {
|
const query = useInfo(environmentId, {
|
||||||
select: (info) => !info.Swarm?.NodeID,
|
select: (info) => !info.Swarm?.NodeID,
|
||||||
|
|
Loading…
Reference in New Issue