feat(frontend) auto generate agent version EE-1266 (#5794)

Co-authored-by: Simon Meng <simon.meng@portainer.io>
pull/5553/head
cong meng 2021-09-30 21:07:13 +13:00 committed by GitHub
parent e4fd43e4fc
commit 0cb5656db6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 24 deletions

View File

@ -1,4 +1,5 @@
import { PortainerEndpointCreationTypes, PortainerEndpointTypes } from 'Portainer/models/endpoint/models';
import { getAgentShortVersion } from 'Portainer/views/endpoints/helpers';
import { EndpointSecurityFormData } from '../../../components/endpointSecurity/porEndpointSecurityModel';
angular
@ -16,7 +17,8 @@ angular
TagService,
SettingsService,
Notifications,
Authentication
Authentication,
StateManager
) {
$scope.state = {
EnvironmentType: 'agent',
@ -44,11 +46,14 @@ angular
],
};
const agentVersion = StateManager.getState().application.version;
const agentShortVersion = getAgentShortVersion(agentVersion);
const deployCommands = {
kubeLoadBalancer: `curl -L https://downloads.portainer.io/portainer-agent-k8s-lb.yaml -o portainer-agent-k8s.yaml; kubectl apply -f portainer-agent-k8s.yaml`,
kubeNodePort: `curl -L https://downloads.portainer.io/portainer-agent-k8s-nodeport.yaml -o portainer-agent-k8s.yaml; kubectl apply -f portainer-agent-k8s.yaml`,
agentLinux: `curl -L https://downloads.portainer.io/agent-stack.yml -o agent-stack.yml && docker stack deploy --compose-file=agent-stack.yml portainer-agent`,
agentWindows: `curl -L https://downloads.portainer.io/agent-stack-windows.yml -o agent-stack-windows.yml && docker stack deploy --compose-file=agent-stack-windows.yml portainer-agent`,
kubeLoadBalancer: `curl -L https://downloads.portainer.io/portainer-agent-ce${agentShortVersion}-k8s-lb.yaml -o portainer-agent-k8s.yaml; kubectl apply -f portainer-agent-k8s.yaml`,
kubeNodePort: `curl -L https://downloads.portainer.io/portainer-agent-ce${agentShortVersion}-k8s-nodeport.yaml -o portainer-agent-k8s.yaml; kubectl apply -f portainer-agent-k8s.yaml`,
agentLinux: `curl -L https://downloads.portainer.io/agent-stack-ce${agentShortVersion}.yml -o agent-stack.yml && docker stack deploy --compose-file=agent-stack.yml portainer-agent`,
agentWindows: `curl -L https://downloads.portainer.io/agent-stack-ce${agentShortVersion}-windows.yml -o agent-stack-windows.yml && docker stack deploy --compose-file=agent-stack-windows.yml portainer-agent`,
};
$scope.deployCommands = deployCommands;

View File

@ -62,17 +62,17 @@
<uib-tabset active="state.deploymentTab">
<uib-tab index="'kubernetes'" heading="Kubernetes" ng-if="state.platformType === 'linux'">
<code style="display: block; white-space: pre-wrap; padding: 16px 45px;">
{{ dockerCommands[state.deploymentTab][state.platformType](randomEdgeID, endpoint.EdgeKey, state.allowSelfSignedCerts) }}
{{ dockerCommands[state.deploymentTab][state.platformType](agentVersion, agentShortVersion, randomEdgeID, endpoint.EdgeKey, state.allowSelfSignedCerts) }}
</code>
</uib-tab>
<uib-tab index="'swarm'" heading="Docker Swarm">
<code style="display: block; white-space: pre-wrap; padding: 16px 45px;">
{{ dockerCommands[state.deploymentTab][state.platformType](randomEdgeID, endpoint.EdgeKey, state.allowSelfSignedCerts) }}
{{ dockerCommands[state.deploymentTab][state.platformType](agentVersion, agentShortVersion, randomEdgeID, endpoint.EdgeKey, state.allowSelfSignedCerts) }}
</code>
</uib-tab>
<uib-tab index="'standalone'" heading="Docker Standalone">
<code style="display: block; white-space: pre-wrap; padding: 16px 45px;">
{{ dockerCommands[state.deploymentTab][state.platformType](randomEdgeID, endpoint.EdgeKey, state.allowSelfSignedCerts) }}
{{ dockerCommands[state.deploymentTab][state.platformType](agentVersion, agentShortVersion, randomEdgeID, endpoint.EdgeKey, state.allowSelfSignedCerts) }}
</code>
</uib-tab>
</uib-tabset>

View File

@ -3,6 +3,7 @@ import uuidv4 from 'uuid/v4';
import { PortainerEndpointTypes } from '@/portainer/models/endpoint/models';
import { EndpointSecurityFormData } from '@/portainer/components/endpointSecurity/porEndpointSecurityModel';
import { getAgentShortVersion } from 'Portainer/views/endpoints/helpers';
angular.module('portainer.app').controller('EndpointController', EndpointController);
@ -22,7 +23,8 @@ function EndpointController(
Notifications,
Authentication,
SettingsService,
ModalService
ModalService,
StateManager
) {
const DEPLOYMENT_TABS = {
SWARM: 'swarm',
@ -66,6 +68,9 @@ function EndpointController(
allowSelfSignedCerts: true,
};
$scope.agentVersion = StateManager.getState().application.version;
$scope.agentShortVersion = getAgentShortVersion($scope.agentVersion);
$scope.dockerCommands = {
[DEPLOYMENT_TABS.STANDALONE]: {
[PLATFORM_TYPES.LINUX]: buildLinuxStandaloneCommand,
@ -87,7 +92,13 @@ function EndpointController(
$scope.copyEdgeAgentDeploymentCommand = copyEdgeAgentDeploymentCommand;
function copyEdgeAgentDeploymentCommand() {
const command = $scope.dockerCommands[$scope.state.deploymentTab][$scope.state.platformType]($scope.randomEdgeID, $scope.endpoint.EdgeKey, $scope.state.allowSelfSignedCerts);
const command = $scope.dockerCommands[$scope.state.deploymentTab][$scope.state.platformType](
$scope.agentVersion,
$scope.agentShortVersion,
$scope.randomEdgeID,
$scope.endpoint.EdgeKey,
$scope.state.allowSelfSignedCerts
);
clipboard.copyText(command.trim());
$('#copyNotificationDeploymentCommand').show().fadeOut(2500);
}
@ -269,7 +280,7 @@ function EndpointController(
});
}
function buildLinuxStandaloneCommand(edgeId, edgeKey, allowSelfSignedCerts) {
function buildLinuxStandaloneCommand(agentVersion, agentShortVersion, edgeId, edgeKey, allowSelfSignedCerts) {
return `
docker run -d \\
-v /var/run/docker.sock:/var/run/docker.sock \\
@ -283,10 +294,10 @@ docker run -d \\
-e CAP_HOST_MANAGEMENT=1 \\
-e EDGE_INSECURE_POLL=${allowSelfSignedCerts ? 1 : 0} \\
--name portainer_edge_agent \\
portainer/agent`;
portainer/agent:${agentVersion}`;
}
function buildWindowsStandaloneCommand(edgeId, edgeKey, allowSelfSignedCerts) {
function buildWindowsStandaloneCommand(agentVersion, agentShortVersion, edgeId, edgeKey, allowSelfSignedCerts) {
return `
docker run -d \\
--mount type=npipe,src=\\\\.\\pipe\\docker_engine,dst=\\\\.\\pipe\\docker_engine \\
@ -299,10 +310,10 @@ docker run -d \\
-e CAP_HOST_MANAGEMENT=1 \\
-e EDGE_INSECURE_POLL=${allowSelfSignedCerts ? 1 : 0} \\
--name portainer_edge_agent \\
portainer/agent`;
portainer/agent:${agentVersion}`;
}
function buildLinuxSwarmCommand(edgeId, edgeKey, allowSelfSignedCerts) {
function buildLinuxSwarmCommand(agentVersion, agentShortVersion, edgeId, edgeKey, allowSelfSignedCerts) {
return `
docker network create \\
--driver overlay \\
@ -323,10 +334,10 @@ docker service create \\
--mount type=bind,src=//var/lib/docker/volumes,dst=/var/lib/docker/volumes \\
--mount type=bind,src=//,dst=/host \\
--mount type=volume,src=portainer_agent_data,dst=/data \\
portainer/agent`;
portainer/agent:${agentVersion}`;
}
function buildWindowsSwarmCommand(edgeId, edgeKey, allowSelfSignedCerts) {
function buildWindowsSwarmCommand(agentVersion, agentShortVersion, edgeId, edgeKey, allowSelfSignedCerts) {
return `
docker network create \\
--driver overlay \\
@ -345,12 +356,12 @@ docker service create \\
--mount type=npipe,src=\\\\.\\pipe\\docker_engine,dst=\\\\.\\pipe\\docker_engine \\
--mount type=bind,src=C:\\ProgramData\\docker\\volumes,dst=C:\\ProgramData\\docker\\volumes \\
--mount type=volume,src=portainer_agent_data,dst=C:\\data \\
portainer/agent`;
portainer/agent:${agentVersion}`;
}
function buildKubernetesCommand(edgeId, edgeKey, allowSelfSignedCerts) {
function buildKubernetesCommand(agentVersion, agentShortVersion, edgeId, edgeKey, allowSelfSignedCerts) {
return `
curl https://downloads.portainer.io/portainer-ce29-edge-agent-setup.sh | bash -s -- ${edgeId} ${edgeKey} ${allowSelfSignedCerts ? '1' : ''}
curl https://downloads.portainer.io/portainer-ce${agentShortVersion}-edge-agent-setup.sh | bash -s -- ${edgeId} ${edgeKey} ${allowSelfSignedCerts ? '1' : ''}
`;
}

View File

@ -0,0 +1,4 @@
export function getAgentShortVersion(agentVersion) {
const numbers = agentVersion.split('.');
return numbers[0] + numbers[1];
}

View File

@ -2,6 +2,7 @@
import { PortainerEndpointCreationTypes } from 'Portainer/models/endpoint/models';
import { buildOption } from '@/portainer/components/box-selector';
import { EndpointSecurityFormData } from 'Portainer/components/endpointSecurity/porEndpointSecurityModel';
import { getAgentShortVersion } from 'Portainer/views/endpoints/helpers';
export default class WizardDockerController {
/* @ngInject */
@ -200,9 +201,12 @@ export default class WizardDockerController {
securityFormData: new EndpointSecurityFormData(),
};
const agentVersion = this.StateManager.getState().application.version;
const agentShortVersion = getAgentShortVersion(agentVersion);
this.command = {
linuxCommand: `curl -L https://downloads.portainer.io/agent-stack.yml -o agent-stack.yml && docker stack deploy --compose-file=agent-stack.yml portainer-agent `,
winCommand: `curl -L https://downloads.portainer.io/agent-stack-windows.yml -o agent-stack-windows.yml && docker stack deploy --compose-file=agent-stack-windows.yml portainer-agent `,
linuxCommand: `curl -L https://downloads.portainer.io/agent-stack-ce${agentShortVersion}.yml -o agent-stack.yml && docker stack deploy --compose-file=agent-stack.yml portainer-agent `,
winCommand: `curl -L https://downloads.portainer.io/agent-stack-ce${agentShortVersion}-windows.yml -o agent-stack-windows.yml && docker stack deploy --compose-file=agent-stack-windows.yml portainer-agent `,
linuxSocket: `-v "/var/run/docker.sock:/var/run/docker.sock" `,
winSocket: `-v \.\pipe\docker_engine:\.\pipe\docker_engine `,
};

View File

@ -1,6 +1,7 @@
import { PortainerEndpointCreationTypes } from 'Portainer/models/endpoint/models';
//import { getAgentShortVersion } from 'Portainer/views/endpoints/helpers';
import { buildOption } from '@/portainer/components/box-selector';
import { getAgentShortVersion } from 'Portainer/views/endpoints/helpers';
export default class WizardKubernetesController {
/* @ngInject */
@ -96,9 +97,12 @@ export default class WizardKubernetesController {
availableOptions: [buildOption('Agent', 'fa fa-bolt', 'Agent', '', 'agent')],
};
const agentVersion = this.StateManager.getState().application.version;
const agentShortVersion = getAgentShortVersion(agentVersion);
this.command = {
loadBalancer: `curl -L https://downloads.portainer.io/portainer-agent-k8s-lb.yaml -o portainer-agent-k8s.yaml; kubectl apply -f portainer-agent-k8s.yaml `,
nodePort: `curl -L https://downloads.portainer.io/portainer-agent-k8s-nodeport.yaml -o portainer-agent-k8s.yaml; kubectl apply -f portainer-agent-k8s.yaml `,
loadBalancer: `curl -L https://downloads.portainer.io/portainer-agent-ce${agentShortVersion}-k8s-lb.yaml -o portainer-agent-k8s.yaml; kubectl apply -f portainer-agent-k8s.yaml `,
nodePort: `curl -L https://downloads.portainer.io/portainer-agent-ce${agentShortVersion}-k8s-nodeport.yaml -o portainer-agent-k8s.yaml; kubectl apply -f portainer-agent-k8s.yaml `,
};
});
}