feat(endpoint): add an input to source env vars [EE-2436] (#6517)

* feat(endpoint): add an input to source env vars

* fix(endpoint): fix invalid version in deployment instructions

* fix(endpoint): fix copy Edge command

* fix(endpoint): fix invalid Edge deployment instruction

* feat(endpoint): add missing parameter to edge deploy script

* feat(edge): use temporary manifest url

* refactor(endpoint): update method and placeholder

* fix(endpoint): fix missing agent name in Edge deployment instructions on Swarm

* fix(endpoint): fix invalid Edge deployment instructions for Kubernetes

* fix(build): commit yarn.lock

* chore(deps): run yarn

* feat(endpoint): do not support kubernetes with Edge env vars

Co-authored-by: Chaim Lev-Ari <chiptus@gmail.com>
pull/6574/head
Anthony Lapenna 2022-02-17 10:25:59 +13:00 committed by GitHub
parent 5de7ecb5f0
commit bd679ae806
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 146 additions and 91 deletions

View File

@ -54,29 +54,44 @@
</div> </div>
</div> </div>
<div class="form-group">
<por-switch-field <por-switch-field
label="'Allow self-signed certs'" label="'Allow self-signed certs'"
checked="state.allowSelfSignedCerts" checked="state.allowSelfSignedCerts"
tooltip="'When allowing self-signed certificates the edge agent will ignore the domain validation when connecting to Portainer via HTTPS'" tooltip="'When allowing self-signed certificates the edge agent will ignore the domain validation when connecting to Portainer via HTTPS'"
on-change="(onToggleAllowSelfSignedCerts)" on-change="(onToggleAllowSelfSignedCerts)"
></por-switch-field> ></por-switch-field>
</div>
<div class="form-group" ng-if="!isKubernetesDeploymentTabSelected()" style="margin-bottom: 60px">
<label for="env_vars" class="col-sm-3 col-lg-2 control-label text-left" style="padding-left: 0; padding-top: 5px">
Environment variables
<portainer-tooltip
position="bottom"
message="Comma separated list of environment variables that will be sourced from the host where the agent is deployed."
></portainer-tooltip>
</label>
<div class="col-sm-9 col-lg-10">
<input type="text" class="form-control" id="env_vars" ng-model="formValues.EnvVarSource" placeholder="foo=bar,myvar" />
</div>
</div>
<div style="margin-top: 10px"> <div style="margin-top: 10px">
<uib-tabset active="state.deploymentTab"> <uib-tabset active="state.deploymentTab">
<uib-tab index="'kubernetes'" heading="Kubernetes" ng-if="state.platformType === 'linux'"> <uib-tab index="'kubernetes'" heading="Kubernetes" ng-if="state.platformType === 'linux'">
<code style="display: block; white-space: pre-wrap; padding: 16px 45px"> <code style="display: block; white-space: pre-wrap; padding: 16px 45px">{{
{{ dockerCommands[state.deploymentTab][state.platformType](agentVersion, agentShortVersion, endpoint.EdgeID, endpoint.EdgeKey, state.allowSelfSignedCerts) }} dockerCommands[state.deploymentTab][state.platformType](agentShortVersion, endpoint.EdgeID, endpoint.EdgeKey, state.allowSelfSignedCerts)
</code> }}</code>
</uib-tab> </uib-tab>
<uib-tab index="'swarm'" heading="Docker Swarm"> <uib-tab index="'swarm'" heading="Docker Swarm">
<code style="display: block; white-space: pre-wrap; padding: 16px 45px"> <code style="display: block; white-space: pre-wrap; padding: 16px 45px">{{
{{ dockerCommands[state.deploymentTab][state.platformType](agentVersion, agentShortVersion, endpoint.EdgeID, endpoint.EdgeKey, state.allowSelfSignedCerts) }} dockerCommands[state.deploymentTab][state.platformType](agentVersion, endpoint.EdgeID, endpoint.EdgeKey, state.allowSelfSignedCerts)
</code> }}</code>
</uib-tab> </uib-tab>
<uib-tab index="'standalone'" heading="Docker Standalone"> <uib-tab index="'standalone'" heading="Docker Standalone">
<code style="display: block; white-space: pre-wrap; padding: 16px 45px"> <code style="display: block; white-space: pre-wrap; padding: 16px 45px">{{
{{ dockerCommands[state.deploymentTab][state.platformType](agentVersion, agentShortVersion, endpoint.EdgeID, endpoint.EdgeKey, state.allowSelfSignedCerts) }} dockerCommands[state.deploymentTab][state.platformType](agentVersion, endpoint.EdgeID, endpoint.EdgeKey, state.allowSelfSignedCerts)
</code> }}</code>
</uib-tab> </uib-tab>
</uib-tabset> </uib-tabset>
<div style="margin-top: 10px"> <div style="margin-top: 10px">

View File

@ -90,13 +90,22 @@ function EndpointController(
$scope.formValues = { $scope.formValues = {
SecurityFormData: new EndpointSecurityFormData(), SecurityFormData: new EndpointSecurityFormData(),
EnvVarSource: '',
};
$scope.isKubernetesDeploymentTabSelected = function () {
return $scope.state.deploymentTab === DEPLOYMENT_TABS.KUBERNETES;
}; };
$scope.copyEdgeAgentDeploymentCommand = copyEdgeAgentDeploymentCommand; $scope.copyEdgeAgentDeploymentCommand = copyEdgeAgentDeploymentCommand;
function copyEdgeAgentDeploymentCommand() { function copyEdgeAgentDeploymentCommand() {
let agentVersion = $scope.agentVersion;
if ($scope.state.deploymentTab == DEPLOYMENT_TABS.KUBERNETES) {
agentVersion = $scope.agentShortVersion;
}
const command = $scope.dockerCommands[$scope.state.deploymentTab][$scope.state.platformType]( const command = $scope.dockerCommands[$scope.state.deploymentTab][$scope.state.platformType](
$scope.agentVersion, agentVersion,
$scope.agentShortVersion,
$scope.endpoint.EdgeID, $scope.endpoint.EdgeID,
$scope.endpoint.EdgeKey, $scope.endpoint.EdgeKey,
$scope.state.allowSelfSignedCerts $scope.state.allowSelfSignedCerts
@ -314,89 +323,120 @@ function EndpointController(
$scope.endpoint.ManagementInfo['DNS Suffix'] = '-'; $scope.endpoint.ManagementInfo['DNS Suffix'] = '-';
} }
function buildLinuxStandaloneCommand(agentVersion, agentShortVersion, edgeId, edgeKey, allowSelfSignedCerts) { function buildEnvironmentSubCommand() {
return ` if ($scope.formValues.EnvVarSource === '') {
docker run -d \\ return [];
-v /var/run/docker.sock:/var/run/docker.sock \\
-v /var/lib/docker/volumes:/var/lib/docker/volumes \\
-v /:/host \\
-v portainer_agent_data:/data \\
--restart always \\
-e EDGE=1 \\
-e EDGE_ID=${edgeId} \\
-e EDGE_KEY=${edgeKey} \\
-e CAP_HOST_MANAGEMENT=1 \\
-e EDGE_INSECURE_POLL=${allowSelfSignedCerts ? 1 : 0} \\
--name portainer_edge_agent \\
portainer/agent:${agentVersion}`;
} }
function buildWindowsStandaloneCommand(agentVersion, agentShortVersion, edgeId, edgeKey, allowSelfSignedCerts) { return $scope.formValues.EnvVarSource.split(',')
return ` .map(function (s) {
docker run -d \\ if (s !== '') {
--mount type=npipe,src=\\\\.\\pipe\\docker_engine,dst=\\\\.\\pipe\\docker_engine \\ return `-e ${s} \\`;
--mount type=bind,src=C:\\ProgramData\\docker\\volumes,dst=C:\\ProgramData\\docker\\volumes \\ }
--mount type=volume,src=portainer_agent_data,dst=C:\\data \\ })
--restart always \\ .filter((s) => s !== undefined);
-e EDGE=1 \\
-e EDGE_ID=${edgeId} \\
-e EDGE_KEY=${edgeKey} \\
-e CAP_HOST_MANAGEMENT=1 \\
-e EDGE_INSECURE_POLL=${allowSelfSignedCerts ? 1 : 0} \\
--name portainer_edge_agent \\
portainer/agent:${agentVersion}`;
} }
function buildLinuxSwarmCommand(agentVersion, agentShortVersion, edgeId, edgeKey, allowSelfSignedCerts) { function buildLinuxStandaloneCommand(agentVersion, edgeId, edgeKey, allowSelfSignedCerts) {
return ` const env = buildEnvironmentSubCommand();
docker network create \\
--driver overlay \\
portainer_agent_network;
docker service create \\ return [
--name portainer_edge_agent \\ 'docker run -d \\',
--network portainer_agent_network \\ '-v /var/run/docker.sock:/var/run/docker.sock \\',
-e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \\ '-v /var/lib/docker/volumes:/var/lib/docker/volumes \\',
-e EDGE=1 \\ '-v /:/host \\',
-e EDGE_ID=${edgeId} \\ '-v portainer_agent_data:/data \\',
-e EDGE_KEY=${edgeKey} \\ '--restart always \\',
-e CAP_HOST_MANAGEMENT=1 \\ '-e EDGE=1 \\',
-e EDGE_INSECURE_POLL=${allowSelfSignedCerts ? 1 : 0} \\ `-e EDGE_ID=${edgeId} \\`,
--mode global \\ `-e EDGE_KEY=${edgeKey} \\`,
--constraint 'node.platform.os == linux' \\ '-e CAP_HOST_MANAGEMENT=1 \\',
--mount type=bind,src=//var/run/docker.sock,dst=/var/run/docker.sock \\ `-e EDGE_INSECURE_POLL=${allowSelfSignedCerts ? 1 : 0} \\`,
--mount type=bind,src=//var/lib/docker/volumes,dst=/var/lib/docker/volumes \\ ...env,
--mount type=bind,src=//,dst=/host \\ '--name portainer_edge_agent \\',
--mount type=volume,src=portainer_agent_data,dst=/data \\ `portainer/agent:${agentVersion}`,
portainer/agent:${agentVersion}`; ].join('\r\n');
} }
function buildWindowsSwarmCommand(agentVersion, agentShortVersion, edgeId, edgeKey, allowSelfSignedCerts) { function buildWindowsStandaloneCommand(agentVersion, edgeId, edgeKey, allowSelfSignedCerts) {
return ` const env = buildEnvironmentSubCommand();
docker network create \\
--driver overlay \\ return [
portainer_edge_agent_network && \\ 'docker run -d \\',
docker service create \\ '--mount type=npipe,src=\\\\.\\pipe\\docker_engine,dst=\\\\.\\pipe\\docker_engine \\',
--name portainer_edge_agent \\ '--mount type=bind,src=C:\\ProgramData\\docker\\volumes,dst=C:\\ProgramData\\docker\\volumes \\',
--network portainer_edge_agent_network \\ '--mount type=volume,src=portainer_agent_data,dst=C:\\data \\',
-e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \\ '--restart always \\',
-e EDGE=1 \\ '-e EDGE=1 \\',
-e EDGE_ID=${edgeId} \\ `-e EDGE_ID=${edgeId} \\`,
-e EDGE_KEY=${edgeKey} \\ `-e EDGE_KEY=${edgeKey} \\`,
-e CAP_HOST_MANAGEMENT=1 \\ '-e CAP_HOST_MANAGEMENT=1 \\',
-e EDGE_INSECURE_POLL=${allowSelfSignedCerts ? 1 : 0} \\ `-e EDGE_INSECURE_POLL=${allowSelfSignedCerts ? 1 : 0} \\`,
--mode global \\ ...env,
--constraint node.platform.os==windows \\ '--name portainer_edge_agent \\',
--mount type=npipe,src=\\\\.\\pipe\\docker_engine,dst=\\\\.\\pipe\\docker_engine \\ `portainer/agent:${agentVersion}`,
--mount type=bind,src=C:\\ProgramData\\docker\\volumes,dst=C:\\ProgramData\\docker\\volumes \\ ].join('\r\n');
--mount type=volume,src=portainer_agent_data,dst=C:\\data \\
portainer/agent:${agentVersion}`;
} }
function buildKubernetesCommand(agentVersion, agentShortVersion, edgeId, edgeKey, allowSelfSignedCerts) { function buildLinuxSwarmCommand(agentVersion, edgeId, edgeKey, allowSelfSignedCerts) {
return ` const env = buildEnvironmentSubCommand();
curl https://downloads.portainer.io/portainer-ce${agentShortVersion}-edge-agent-setup.sh | bash -s -- ${edgeId} ${edgeKey} ${allowSelfSignedCerts ? '1' : ''}
`; return [
'docker network create \\',
'--driver overlay \\',
'portainer_agent_network;',
'',
'docker service create \\',
'--name portainer_edge_agent \\',
'--network portainer_agent_network \\',
'-e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \\',
'-e EDGE=1 \\',
`-e EDGE_ID=${edgeId} \\`,
`-e EDGE_KEY=${edgeKey} \\`,
'-e CAP_HOST_MANAGEMENT=1 \\',
`-e EDGE_INSECURE_POLL=${allowSelfSignedCerts ? 1 : 0} \\`,
...env,
'--mode global \\',
"--constraint 'node.platform.os == linux' \\",
'--mount type=bind,src=//var/run/docker.sock,dst=/var/run/docker.sock \\',
'--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:${agentVersion}`,
].join('\r\n');
}
function buildWindowsSwarmCommand(agentVersion, edgeId, edgeKey, allowSelfSignedCerts) {
const env = buildEnvironmentSubCommand();
return [
'docker network create \\',
'--driver overlay \\',
'portainer_agent_network;',
'',
'docker service create \\',
'--name portainer_edge_agent \\',
'--network portainer_agent_network \\',
'-e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \\',
'-e EDGE=1 \\',
`-e EDGE_ID=${edgeId} \\`,
`-e EDGE_KEY=${edgeKey} \\`,
'-e CAP_HOST_MANAGEMENT=1 \\',
`-e EDGE_INSECURE_POLL=${allowSelfSignedCerts ? 1 : 0} \\`,
...env,
'--mode global \\',
"--constraint 'node.platform.os == windows' \\",
'--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:${agentVersion}`,
].join('\r\n');
}
function buildKubernetesCommand(agentVersion, edgeId, edgeKey, allowSelfSignedCerts) {
return `curl https://downloads.portainer.io/portainer-ce${agentVersion}-edge-agent-setup.sh | bash -s -- ${edgeId} ${edgeKey} ${allowSelfSignedCerts ? '1' : '0'}`;
} }
initView(); initView();