mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
refactor(edge): move edge codebase to react (#7781)
This commit is contained in:
parent
75f40fe485
commit
1e4c4e2616
54 changed files with 254 additions and 187 deletions
|
@ -14,18 +14,21 @@ const edgePropertiesFormInitialValues: ScriptFormValues = {
|
|||
platform: 'k8s' as Platform,
|
||||
nomadToken: '',
|
||||
authEnabled: true,
|
||||
tlsEnabled: false,
|
||||
};
|
||||
|
||||
interface Props {
|
||||
edgeInfo: EdgeInfo;
|
||||
commands: CommandTab[] | Partial<Record<OS, CommandTab[]>>;
|
||||
isNomadTokenVisible?: boolean;
|
||||
hideAsyncMode?: boolean;
|
||||
}
|
||||
|
||||
export function EdgeScriptForm({
|
||||
edgeInfo,
|
||||
commands,
|
||||
isNomadTokenVisible,
|
||||
hideAsyncMode,
|
||||
}: Props) {
|
||||
const showOsSelector = !(commands instanceof Array);
|
||||
|
||||
|
@ -60,6 +63,7 @@ export function EdgeScriptForm({
|
|||
onPlatformChange={(platform) =>
|
||||
setFieldValue('platform', platform)
|
||||
}
|
||||
hideAsyncMode={hideAsyncMode}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
|
|
|
@ -6,6 +6,17 @@ export function validationSchema(isNomadTokenVisible?: boolean) {
|
|||
return object().shape({
|
||||
allowSelfSignedCertificates: boolean(),
|
||||
envVars: string(),
|
||||
...(isNomadTokenVisible ? nomadTokenValidation() : {}),
|
||||
...nomadValidation(isNomadTokenVisible),
|
||||
});
|
||||
}
|
||||
|
||||
function nomadValidation(isNomadTokenVisible?: boolean) {
|
||||
if (!isNomadTokenVisible) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return {
|
||||
tlsEnabled: boolean().default(false),
|
||||
...nomadTokenValidation(),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Field, useFormikContext } from 'formik';
|
||||
import { useFormikContext, Field } from 'formik';
|
||||
|
||||
import { FormControl } from '@@/form-components/FormControl';
|
||||
import { Input } from '@@/form-components/Input';
|
||||
|
@ -47,7 +47,22 @@ export function EdgeScriptSettingsFieldset({
|
|||
</>
|
||||
)}
|
||||
|
||||
{isNomadTokenVisible && <NomadTokenField />}
|
||||
{isNomadTokenVisible && (
|
||||
<>
|
||||
<NomadTokenField />
|
||||
|
||||
<div className="form-group">
|
||||
<div className="col-sm-12">
|
||||
<SwitchField
|
||||
label="TLS"
|
||||
labelClass="col-sm-3 col-lg-2"
|
||||
checked={values.tlsEnabled}
|
||||
onChange={(checked) => setFieldValue('tlsEnabled', checked)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
<FormControl
|
||||
label="Environment variables"
|
||||
|
|
|
@ -16,6 +16,7 @@ interface Props {
|
|||
commands: CommandTab[];
|
||||
platform?: Platform;
|
||||
onPlatformChange?(platform: Platform): void;
|
||||
hideAsyncMode?: boolean;
|
||||
}
|
||||
|
||||
export function ScriptTabs({
|
||||
|
@ -24,6 +25,7 @@ export function ScriptTabs({
|
|||
edgeId,
|
||||
commands,
|
||||
platform,
|
||||
hideAsyncMode = false,
|
||||
onPlatformChange = () => {},
|
||||
}: Props) {
|
||||
const agentDetails = useAgentDetails();
|
||||
|
@ -38,10 +40,17 @@ export function ScriptTabs({
|
|||
return null;
|
||||
}
|
||||
|
||||
const { agentSecret, agentVersion } = agentDetails;
|
||||
const { agentSecret, agentVersion, useEdgeAsyncMode } = agentDetails;
|
||||
|
||||
const options = commands.map((c) => {
|
||||
const cmd = c.command(agentVersion, edgeKey, values, edgeId, agentSecret);
|
||||
const cmd = c.command(
|
||||
agentVersion,
|
||||
edgeKey,
|
||||
values,
|
||||
!hideAsyncMode && useEdgeAsyncMode,
|
||||
edgeId,
|
||||
agentSecret
|
||||
);
|
||||
|
||||
return {
|
||||
id: c.id,
|
||||
|
|
|
@ -8,6 +8,7 @@ type CommandGenerator = (
|
|||
agentVersion: string,
|
||||
edgeKey: string,
|
||||
properties: ScriptFormValues,
|
||||
useAsyncMode: boolean,
|
||||
edgeId?: string,
|
||||
agentSecret?: string
|
||||
) => string;
|
||||
|
@ -34,6 +35,11 @@ export const commandsTabs: Record<string, CommandTab> = {
|
|||
label: 'Docker Standalone',
|
||||
command: buildLinuxStandaloneCommand,
|
||||
},
|
||||
nomadLinux: {
|
||||
id: 'nomad',
|
||||
label: 'Nomad',
|
||||
command: buildLinuxNomadCommand,
|
||||
},
|
||||
swarmWindows: {
|
||||
id: 'swarm',
|
||||
label: 'Docker Swarm',
|
||||
|
@ -58,6 +64,7 @@ export function buildLinuxStandaloneCommand(
|
|||
agentVersion: string,
|
||||
edgeKey: string,
|
||||
properties: ScriptFormValues,
|
||||
useAsyncMode: boolean,
|
||||
edgeId?: string,
|
||||
agentSecret?: string
|
||||
) {
|
||||
|
@ -69,7 +76,8 @@ export function buildLinuxStandaloneCommand(
|
|||
edgeKey,
|
||||
allowSelfSignedCertificates,
|
||||
!edgeIdGenerator ? edgeId : undefined,
|
||||
agentSecret
|
||||
agentSecret,
|
||||
useAsyncMode
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -92,6 +100,7 @@ export function buildWindowsStandaloneCommand(
|
|||
agentVersion: string,
|
||||
edgeKey: string,
|
||||
properties: ScriptFormValues,
|
||||
useAsyncMode: boolean,
|
||||
edgeId?: string,
|
||||
agentSecret?: string
|
||||
) {
|
||||
|
@ -103,7 +112,8 @@ export function buildWindowsStandaloneCommand(
|
|||
edgeKey,
|
||||
allowSelfSignedCertificates,
|
||||
edgeIdGenerator ? '$Env:PORTAINER_EDGE_ID' : edgeId,
|
||||
agentSecret
|
||||
agentSecret,
|
||||
useAsyncMode
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -127,6 +137,7 @@ export function buildLinuxSwarmCommand(
|
|||
agentVersion: string,
|
||||
edgeKey: string,
|
||||
properties: ScriptFormValues,
|
||||
useAsyncMode: boolean,
|
||||
edgeId?: string,
|
||||
agentSecret?: string
|
||||
) {
|
||||
|
@ -137,7 +148,8 @@ export function buildLinuxSwarmCommand(
|
|||
edgeKey,
|
||||
allowSelfSignedCertificates,
|
||||
!edgeIdGenerator ? edgeId : undefined,
|
||||
agentSecret
|
||||
agentSecret,
|
||||
useAsyncMode
|
||||
),
|
||||
'AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent',
|
||||
]);
|
||||
|
@ -167,6 +179,7 @@ export function buildWindowsSwarmCommand(
|
|||
agentVersion: string,
|
||||
edgeKey: string,
|
||||
properties: ScriptFormValues,
|
||||
useAsyncMode: boolean,
|
||||
edgeId?: string,
|
||||
agentSecret?: string
|
||||
) {
|
||||
|
@ -177,7 +190,8 @@ export function buildWindowsSwarmCommand(
|
|||
edgeKey,
|
||||
allowSelfSignedCertificates,
|
||||
edgeIdGenerator ? '$Env:PORTAINER_EDGE_ID' : edgeId,
|
||||
agentSecret
|
||||
agentSecret,
|
||||
useAsyncMode
|
||||
),
|
||||
'AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent',
|
||||
]);
|
||||
|
@ -208,13 +222,17 @@ export function buildLinuxKubernetesCommand(
|
|||
agentVersion: string,
|
||||
edgeKey: string,
|
||||
properties: ScriptFormValues,
|
||||
useAsyncMode: boolean,
|
||||
edgeId?: string,
|
||||
agentSecret?: string
|
||||
) {
|
||||
const { allowSelfSignedCertificates, edgeIdGenerator, envVars } = properties;
|
||||
|
||||
const agentShortVersion = getAgentShortVersion(agentVersion);
|
||||
const envVarsTrimmed = envVars.trim();
|
||||
let envVarsTrimmed = envVars.trim();
|
||||
if (useAsyncMode) {
|
||||
envVarsTrimmed += `EDGE_ASYNC=1`;
|
||||
}
|
||||
const idEnvVar = edgeIdGenerator
|
||||
? `PORTAINER_EDGE_ID=$(${edgeIdGenerator}) \n\n`
|
||||
: '';
|
||||
|
@ -224,11 +242,43 @@ export function buildLinuxKubernetesCommand(
|
|||
return `${idEnvVar}curl https://downloads.portainer.io/ee${agentShortVersion}/portainer-edge-agent-setup.sh | bash -s -- "${edgeIdVar}" "${edgeKey}" "${selfSigned}" "${agentSecret}" "${envVarsTrimmed}"`;
|
||||
}
|
||||
|
||||
export function buildLinuxNomadCommand(
|
||||
agentVersion: string,
|
||||
edgeKey: string,
|
||||
properties: ScriptFormValues,
|
||||
useAsyncMode: boolean,
|
||||
edgeId?: string,
|
||||
agentSecret?: string
|
||||
) {
|
||||
const {
|
||||
allowSelfSignedCertificates,
|
||||
edgeIdGenerator,
|
||||
envVars,
|
||||
nomadToken = '',
|
||||
tlsEnabled,
|
||||
} = properties;
|
||||
|
||||
const agentShortVersion = getAgentShortVersion(agentVersion);
|
||||
let envVarsTrimmed = envVars.trim();
|
||||
if (useAsyncMode) {
|
||||
envVarsTrimmed += `EDGE_ASYNC=1`;
|
||||
}
|
||||
|
||||
const selfSigned = allowSelfSignedCertificates ? '1' : '0';
|
||||
const idEnvVar = edgeIdGenerator
|
||||
? `PORTAINER_EDGE_ID=$(${edgeIdGenerator}) \n\n`
|
||||
: '';
|
||||
const edgeIdVar = !edgeIdGenerator && edgeId ? edgeId : '$PORTAINER_EDGE_ID';
|
||||
|
||||
return `${idEnvVar}curl https://downloads.portainer.io/ee${agentShortVersion}/portainer-edge-agent-nomad-setup.sh | bash -s -- "${nomadToken}" "${edgeIdVar}" "${edgeKey}" "${selfSigned}" "${envVarsTrimmed}" "${agentSecret}" "${tlsEnabled}"`;
|
||||
}
|
||||
|
||||
function buildDefaultEnvVars(
|
||||
edgeKey: string,
|
||||
allowSelfSignedCerts: boolean,
|
||||
edgeId = '$PORTAINER_EDGE_ID',
|
||||
agentSecret = ''
|
||||
agentSecret = '',
|
||||
useAsyncMode = false
|
||||
) {
|
||||
return _.compact([
|
||||
'EDGE=1',
|
||||
|
@ -236,5 +286,6 @@ function buildDefaultEnvVars(
|
|||
`EDGE_KEY=${edgeKey}`,
|
||||
`EDGE_INSECURE_POLL=${allowSelfSignedCerts ? 1 : 0}`,
|
||||
agentSecret ? `AGENT_SECRET=${agentSecret}` : ``,
|
||||
useAsyncMode ? 'EDGE_ASYNC=1' : '',
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ export type OS = 'win' | 'linux';
|
|||
export interface ScriptFormValues {
|
||||
nomadToken: string;
|
||||
authEnabled: boolean;
|
||||
tlsEnabled: boolean;
|
||||
|
||||
allowSelfSignedCertificates: boolean;
|
||||
envVars: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue