diff --git a/app/react/edge/components/EdgeScriptForm/__snapshots__/scripts.test.ts.snap b/app/react/edge/components/EdgeScriptForm/__snapshots__/scripts.test.ts.snap index b01f0366e..01e75df7f 100644 --- a/app/react/edge/components/EdgeScriptForm/__snapshots__/scripts.test.ts.snap +++ b/app/react/edge/components/EdgeScriptForm/__snapshots__/scripts.test.ts.snap @@ -1,6 +1,32 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`buildLinuxPodmanCommand > should generate basic command with minimal configuration 1`] = ` +exports[`'buildLinuxKubernetesCommand' > should generate basic command with minimal configuration 1`] = `"curl https://downloads.portainer.io/ee2-19/portainer-edge-agent-setup.sh | bash -s -- "test-edge-id" "test-edge-key" "0" "test-secret" """`; + +exports[`'buildLinuxKubernetesCommand' > should generate command with all meta variables 1`] = `"curl https://downloads.portainer.io/ee2-19/portainer-edge-agent-setup.sh | bash -s -- "test-edge-id" "test-edge-key" "0" "test-secret" "EDGE_GROUPS=1:2,PORTAINER_GROUP=5,PORTAINER_TAGS=10:20""`; + +exports[`'buildLinuxKubernetesCommand' > should generate command with async mode enabled 1`] = `"curl https://downloads.portainer.io/ee2-19/portainer-edge-agent-setup.sh | bash -s -- "test-edge-id" "test-edge-key" "0" "test-secret" "EDGE_ASYNC=1""`; + +exports[`'buildLinuxKubernetesCommand' > should generate command with custom environment variables 1`] = `"curl https://downloads.portainer.io/ee2-19/portainer-edge-agent-setup.sh | bash -s -- "test-edge-id" "test-edge-key" "0" "test-secret" "MY_VAR=value1,ANOTHER_VAR=value2""`; + +exports[`'buildLinuxKubernetesCommand' > should generate command with edge ID generator 1`] = ` +"PORTAINER_EDGE_ID=$(uuidgen) + +curl https://downloads.portainer.io/ee2-19/portainer-edge-agent-setup.sh | bash -s -- "$PORTAINER_EDGE_ID" "test-edge-key" "0" "test-secret" """ +`; + +exports[`'buildLinuxKubernetesCommand' > should generate command with edge groups 1`] = `"curl https://downloads.portainer.io/ee2-19/portainer-edge-agent-setup.sh | bash -s -- "test-edge-id" "test-edge-key" "0" "test-secret" "EDGE_GROUPS=1:2:3""`; + +exports[`'buildLinuxKubernetesCommand' > should generate command with empty agent secret 1`] = `"curl https://downloads.portainer.io/ee2-19/portainer-edge-agent-setup.sh | bash -s -- "test-edge-id" "test-edge-key" "0" "" """`; + +exports[`'buildLinuxKubernetesCommand' > should generate command with portainer group 1`] = `"curl https://downloads.portainer.io/ee2-19/portainer-edge-agent-setup.sh | bash -s -- "test-edge-id" "test-edge-key" "0" "test-secret" "PORTAINER_GROUP=5""`; + +exports[`'buildLinuxKubernetesCommand' > should generate command with self-signed certificates allowed 1`] = `"curl https://downloads.portainer.io/ee2-19/portainer-edge-agent-setup.sh | bash -s -- "test-edge-id" "test-edge-key" "1" "test-secret" """`; + +exports[`'buildLinuxKubernetesCommand' > should generate command with tags 1`] = `"curl https://downloads.portainer.io/ee2-19/portainer-edge-agent-setup.sh | bash -s -- "test-edge-id" "test-edge-key" "0" "test-secret" "PORTAINER_TAGS=10:20:30""`; + +exports[`'buildLinuxKubernetesCommand' > should generate command without agent secret 1`] = `"curl https://downloads.portainer.io/ee2-19/portainer-edge-agent-setup.sh | bash -s -- "test-edge-id" "test-edge-key" "0" "undefined" """`; + +exports[`'buildLinuxPodmanCommand' > should generate basic command with minimal configuration 1`] = ` "sudo systemctl enable --now podman.socket sudo podman volume create portainer_agent_data @@ -22,7 +48,7 @@ sudo podman run -d \\ " `; -exports[`buildLinuxPodmanCommand > should generate command with all meta variables 1`] = ` +exports[`'buildLinuxPodmanCommand' > should generate command with all meta variables 1`] = ` "sudo systemctl enable --now podman.socket sudo podman volume create portainer_agent_data @@ -47,7 +73,7 @@ sudo podman run -d \\ " `; -exports[`buildLinuxPodmanCommand > should generate command with async mode enabled 1`] = ` +exports[`'buildLinuxPodmanCommand' > should generate command with async mode enabled 1`] = ` "sudo systemctl enable --now podman.socket sudo podman volume create portainer_agent_data @@ -70,7 +96,7 @@ sudo podman run -d \\ " `; -exports[`buildLinuxPodmanCommand > should generate command with custom environment variables 1`] = ` +exports[`'buildLinuxPodmanCommand' > should generate command with custom environment variables 1`] = ` "sudo systemctl enable --now podman.socket sudo podman volume create portainer_agent_data @@ -94,7 +120,7 @@ sudo podman run -d \\ " `; -exports[`buildLinuxPodmanCommand > should generate command with edge ID generator 1`] = ` +exports[`'buildLinuxPodmanCommand' > should generate command with edge ID generator 1`] = ` "PORTAINER_EDGE_ID=$(uuidgen) sudo systemctl enable --now podman.socket @@ -118,7 +144,7 @@ sudo podman run -d \\ " `; -exports[`buildLinuxPodmanCommand > should generate command with edge groups 1`] = ` +exports[`'buildLinuxPodmanCommand' > should generate command with edge groups 1`] = ` "sudo systemctl enable --now podman.socket sudo podman volume create portainer_agent_data @@ -141,7 +167,7 @@ sudo podman run -d \\ " `; -exports[`buildLinuxPodmanCommand > should generate command with empty agent secret 1`] = ` +exports[`'buildLinuxPodmanCommand' > should generate command with empty agent secret 1`] = ` "sudo systemctl enable --now podman.socket sudo podman volume create portainer_agent_data @@ -162,7 +188,7 @@ sudo podman run -d \\ " `; -exports[`buildLinuxPodmanCommand > should generate command with portainer group 1`] = ` +exports[`'buildLinuxPodmanCommand' > should generate command with portainer group 1`] = ` "sudo systemctl enable --now podman.socket sudo podman volume create portainer_agent_data @@ -185,7 +211,7 @@ sudo podman run -d \\ " `; -exports[`buildLinuxPodmanCommand > should generate command with self-signed certificates allowed 1`] = ` +exports[`'buildLinuxPodmanCommand' > should generate command with self-signed certificates allowed 1`] = ` "sudo systemctl enable --now podman.socket sudo podman volume create portainer_agent_data @@ -207,7 +233,7 @@ sudo podman run -d \\ " `; -exports[`buildLinuxPodmanCommand > should generate command with tags 1`] = ` +exports[`'buildLinuxPodmanCommand' > should generate command with tags 1`] = ` "sudo systemctl enable --now podman.socket sudo podman volume create portainer_agent_data @@ -230,7 +256,7 @@ sudo podman run -d \\ " `; -exports[`buildLinuxPodmanCommand > should generate command without agent secret 1`] = ` +exports[`'buildLinuxPodmanCommand' > should generate command without agent secret 1`] = ` "sudo systemctl enable --now podman.socket sudo podman volume create portainer_agent_data @@ -250,3 +276,919 @@ sudo podman run -d \\ portainer/agent:2.19.0 " `; + +exports[`'buildLinuxStandaloneCommand' > should generate basic command with minimal configuration 1`] = ` +"docker run -d \\ + -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=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + -e AGENT_SECRET=test-secret \\ + --name portainer_edge_agent \\ + portainer/agent:2.19.0 + " +`; + +exports[`'buildLinuxStandaloneCommand' > should generate command with all meta variables 1`] = ` +"docker run -d \\ + -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=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + -e AGENT_SECRET=test-secret \\ + -e EDGE_GROUPS=1:2 \\ + -e PORTAINER_GROUP=5 \\ + -e PORTAINER_TAGS=10:20 \\ + --name portainer_edge_agent \\ + portainer/agent:2.19.0 + " +`; + +exports[`'buildLinuxStandaloneCommand' > should generate command with async mode enabled 1`] = ` +"docker run -d \\ + -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=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + -e AGENT_SECRET=test-secret \\ + -e EDGE_ASYNC=1 \\ + --name portainer_edge_agent \\ + portainer/agent:2.19.0 + " +`; + +exports[`'buildLinuxStandaloneCommand' > should generate command with custom environment variables 1`] = ` +"docker run -d \\ + -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=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + -e AGENT_SECRET=test-secret \\ + -e MY_VAR=value1 \\ + -e ANOTHER_VAR=value2 \\ + --name portainer_edge_agent \\ + portainer/agent:2.19.0 + " +`; + +exports[`'buildLinuxStandaloneCommand' > should generate command with edge ID generator 1`] = ` +"PORTAINER_EDGE_ID=$(uuidgen) + +docker run -d \\ + -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=$PORTAINER_EDGE_ID \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + -e AGENT_SECRET=test-secret \\ + --name portainer_edge_agent \\ + portainer/agent:2.19.0 + " +`; + +exports[`'buildLinuxStandaloneCommand' > should generate command with edge groups 1`] = ` +"docker run -d \\ + -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=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + -e AGENT_SECRET=test-secret \\ + -e EDGE_GROUPS=1:2:3 \\ + --name portainer_edge_agent \\ + portainer/agent:2.19.0 + " +`; + +exports[`'buildLinuxStandaloneCommand' > should generate command with empty agent secret 1`] = ` +"docker run -d \\ + -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=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + --name portainer_edge_agent \\ + portainer/agent:2.19.0 + " +`; + +exports[`'buildLinuxStandaloneCommand' > should generate command with portainer group 1`] = ` +"docker run -d \\ + -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=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + -e AGENT_SECRET=test-secret \\ + -e PORTAINER_GROUP=5 \\ + --name portainer_edge_agent \\ + portainer/agent:2.19.0 + " +`; + +exports[`'buildLinuxStandaloneCommand' > should generate command with self-signed certificates allowed 1`] = ` +"docker run -d \\ + -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=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=1 \\ + -e AGENT_SECRET=test-secret \\ + --name portainer_edge_agent \\ + portainer/agent:2.19.0 + " +`; + +exports[`'buildLinuxStandaloneCommand' > should generate command with tags 1`] = ` +"docker run -d \\ + -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=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + -e AGENT_SECRET=test-secret \\ + -e PORTAINER_TAGS=10:20:30 \\ + --name portainer_edge_agent \\ + portainer/agent:2.19.0 + " +`; + +exports[`'buildLinuxStandaloneCommand' > should generate command without agent secret 1`] = ` +"docker run -d \\ + -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=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + --name portainer_edge_agent \\ + portainer/agent:2.19.0 + " +`; + +exports[`'buildLinuxSwarmCommand' > should generate basic command with minimal configuration 1`] = ` +"docker network create \\ + --driver overlay \\ + portainer_agent_network; + +docker service create \\ + --name portainer_edge_agent \\ + --network portainer_agent_network \\ + -e EDGE=1 \\ + -e EDGE_ID=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + -e AGENT_SECRET=test-secret \\ + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \\ + --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:2.19.0 +" +`; + +exports[`'buildLinuxSwarmCommand' > should generate command with all meta variables 1`] = ` +"docker network create \\ + --driver overlay \\ + portainer_agent_network; + +docker service create \\ + --name portainer_edge_agent \\ + --network portainer_agent_network \\ + -e EDGE=1 \\ + -e EDGE_ID=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + -e AGENT_SECRET=test-secret \\ + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \\ + -e EDGE_GROUPS=1:2 \\ + -e PORTAINER_GROUP=5 \\ + -e PORTAINER_TAGS=10:20 \\ + --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:2.19.0 +" +`; + +exports[`'buildLinuxSwarmCommand' > should generate command with async mode enabled 1`] = ` +"docker network create \\ + --driver overlay \\ + portainer_agent_network; + +docker service create \\ + --name portainer_edge_agent \\ + --network portainer_agent_network \\ + -e EDGE=1 \\ + -e EDGE_ID=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + -e AGENT_SECRET=test-secret \\ + -e EDGE_ASYNC=1 \\ + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \\ + --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:2.19.0 +" +`; + +exports[`'buildLinuxSwarmCommand' > should generate command with custom environment variables 1`] = ` +"docker network create \\ + --driver overlay \\ + portainer_agent_network; + +docker service create \\ + --name portainer_edge_agent \\ + --network portainer_agent_network \\ + -e EDGE=1 \\ + -e EDGE_ID=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + -e AGENT_SECRET=test-secret \\ + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \\ + -e MY_VAR=value1 \\ + -e ANOTHER_VAR=value2 \\ + --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:2.19.0 +" +`; + +exports[`'buildLinuxSwarmCommand' > should generate command with edge ID generator 1`] = ` +"PORTAINER_EDGE_ID=$(uuidgen) + +docker network create \\ + --driver overlay \\ + portainer_agent_network; + +docker service create \\ + --name portainer_edge_agent \\ + --network portainer_agent_network \\ + -e EDGE=1 \\ + -e EDGE_ID=$PORTAINER_EDGE_ID \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + -e AGENT_SECRET=test-secret \\ + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \\ + --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:2.19.0 +" +`; + +exports[`'buildLinuxSwarmCommand' > should generate command with edge groups 1`] = ` +"docker network create \\ + --driver overlay \\ + portainer_agent_network; + +docker service create \\ + --name portainer_edge_agent \\ + --network portainer_agent_network \\ + -e EDGE=1 \\ + -e EDGE_ID=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + -e AGENT_SECRET=test-secret \\ + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \\ + -e EDGE_GROUPS=1:2:3 \\ + --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:2.19.0 +" +`; + +exports[`'buildLinuxSwarmCommand' > should generate command with empty agent secret 1`] = ` +"docker network create \\ + --driver overlay \\ + portainer_agent_network; + +docker service create \\ + --name portainer_edge_agent \\ + --network portainer_agent_network \\ + -e EDGE=1 \\ + -e EDGE_ID=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \\ + --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:2.19.0 +" +`; + +exports[`'buildLinuxSwarmCommand' > should generate command with portainer group 1`] = ` +"docker network create \\ + --driver overlay \\ + portainer_agent_network; + +docker service create \\ + --name portainer_edge_agent \\ + --network portainer_agent_network \\ + -e EDGE=1 \\ + -e EDGE_ID=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + -e AGENT_SECRET=test-secret \\ + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \\ + -e PORTAINER_GROUP=5 \\ + --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:2.19.0 +" +`; + +exports[`'buildLinuxSwarmCommand' > should generate command with self-signed certificates allowed 1`] = ` +"docker network create \\ + --driver overlay \\ + portainer_agent_network; + +docker service create \\ + --name portainer_edge_agent \\ + --network portainer_agent_network \\ + -e EDGE=1 \\ + -e EDGE_ID=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=1 \\ + -e AGENT_SECRET=test-secret \\ + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \\ + --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:2.19.0 +" +`; + +exports[`'buildLinuxSwarmCommand' > should generate command with tags 1`] = ` +"docker network create \\ + --driver overlay \\ + portainer_agent_network; + +docker service create \\ + --name portainer_edge_agent \\ + --network portainer_agent_network \\ + -e EDGE=1 \\ + -e EDGE_ID=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + -e AGENT_SECRET=test-secret \\ + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \\ + -e PORTAINER_TAGS=10:20:30 \\ + --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:2.19.0 +" +`; + +exports[`'buildLinuxSwarmCommand' > should generate command without agent secret 1`] = ` +"docker network create \\ + --driver overlay \\ + portainer_agent_network; + +docker service create \\ + --name portainer_edge_agent \\ + --network portainer_agent_network \\ + -e EDGE=1 \\ + -e EDGE_ID=test-edge-id \\ + -e EDGE_KEY=test-edge-key \\ + -e EDGE_INSECURE_POLL=0 \\ + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \\ + --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:2.19.0 +" +`; + +exports[`'buildWindowsStandaloneCommand' > should generate basic command with minimal configuration 1`] = ` +"docker run -d \` + --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 \` + --restart always \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + -e AGENT_SECRET=test-secret \` + --name portainer_edge_agent \` + portainer/agent:2.19.0 + " +`; + +exports[`'buildWindowsStandaloneCommand' > should generate command with all meta variables 1`] = ` +"docker run -d \` + --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 \` + --restart always \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + -e AGENT_SECRET=test-secret \` + -e EDGE_GROUPS=1:2 \` + -e PORTAINER_GROUP=5 \` + -e PORTAINER_TAGS=10:20 \` + --name portainer_edge_agent \` + portainer/agent:2.19.0 + " +`; + +exports[`'buildWindowsStandaloneCommand' > should generate command with async mode enabled 1`] = ` +"docker run -d \` + --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 \` + --restart always \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + -e AGENT_SECRET=test-secret \` + -e EDGE_ASYNC=1 \` + --name portainer_edge_agent \` + portainer/agent:2.19.0 + " +`; + +exports[`'buildWindowsStandaloneCommand' > should generate command with custom environment variables 1`] = ` +"docker run -d \` + --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 \` + --restart always \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + -e AGENT_SECRET=test-secret \` + -e MY_VAR=value1 \` + -e ANOTHER_VAR=value2 \` + --name portainer_edge_agent \` + portainer/agent:2.19.0 + " +`; + +exports[`'buildWindowsStandaloneCommand' > should generate command with edge ID generator 1`] = ` +"$Env:PORTAINER_EDGE_ID = "@(Get-MachineGUID)" + +docker run -d \` + --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 \` + --restart always \` + -e EDGE=1 \` + -e EDGE_ID=$Env:PORTAINER_EDGE_ID \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + -e AGENT_SECRET=test-secret \` + --name portainer_edge_agent \` + portainer/agent:2.19.0 + " +`; + +exports[`'buildWindowsStandaloneCommand' > should generate command with edge groups 1`] = ` +"docker run -d \` + --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 \` + --restart always \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + -e AGENT_SECRET=test-secret \` + -e EDGE_GROUPS=1:2:3 \` + --name portainer_edge_agent \` + portainer/agent:2.19.0 + " +`; + +exports[`'buildWindowsStandaloneCommand' > should generate command with empty agent secret 1`] = ` +"docker run -d \` + --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 \` + --restart always \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + --name portainer_edge_agent \` + portainer/agent:2.19.0 + " +`; + +exports[`'buildWindowsStandaloneCommand' > should generate command with portainer group 1`] = ` +"docker run -d \` + --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 \` + --restart always \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + -e AGENT_SECRET=test-secret \` + -e PORTAINER_GROUP=5 \` + --name portainer_edge_agent \` + portainer/agent:2.19.0 + " +`; + +exports[`'buildWindowsStandaloneCommand' > should generate command with self-signed certificates allowed 1`] = ` +"docker run -d \` + --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 \` + --restart always \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=1 \` + -e AGENT_SECRET=test-secret \` + --name portainer_edge_agent \` + portainer/agent:2.19.0 + " +`; + +exports[`'buildWindowsStandaloneCommand' > should generate command with tags 1`] = ` +"docker run -d \` + --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 \` + --restart always \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + -e AGENT_SECRET=test-secret \` + -e PORTAINER_TAGS=10:20:30 \` + --name portainer_edge_agent \` + portainer/agent:2.19.0 + " +`; + +exports[`'buildWindowsStandaloneCommand' > should generate command without agent secret 1`] = ` +"docker run -d \` + --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 \` + --restart always \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + --name portainer_edge_agent \` + portainer/agent:2.19.0 + " +`; + +exports[`'buildWindowsSwarmCommand' > should generate basic command with minimal configuration 1`] = ` +"docker network create \` + --driver overlay \` + portainer_agent_network; + +docker service create \` + --name portainer_edge_agent \` + --network portainer_agent_network \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + -e AGENT_SECRET=test-secret \` + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \` + --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:2.19.0 +" +`; + +exports[`'buildWindowsSwarmCommand' > should generate command with all meta variables 1`] = ` +"docker network create \` + --driver overlay \` + portainer_agent_network; + +docker service create \` + --name portainer_edge_agent \` + --network portainer_agent_network \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + -e AGENT_SECRET=test-secret \` + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \` + -e EDGE_GROUPS=1:2 \` + -e PORTAINER_GROUP=5 \` + -e PORTAINER_TAGS=10:20 \` + --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:2.19.0 +" +`; + +exports[`'buildWindowsSwarmCommand' > should generate command with async mode enabled 1`] = ` +"docker network create \` + --driver overlay \` + portainer_agent_network; + +docker service create \` + --name portainer_edge_agent \` + --network portainer_agent_network \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + -e AGENT_SECRET=test-secret \` + -e EDGE_ASYNC=1 \` + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \` + --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:2.19.0 +" +`; + +exports[`'buildWindowsSwarmCommand' > should generate command with custom environment variables 1`] = ` +"docker network create \` + --driver overlay \` + portainer_agent_network; + +docker service create \` + --name portainer_edge_agent \` + --network portainer_agent_network \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + -e AGENT_SECRET=test-secret \` + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \` + -e MY_VAR=value1 \` + -e ANOTHER_VAR=value2 \` + --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:2.19.0 +" +`; + +exports[`'buildWindowsSwarmCommand' > should generate command with edge ID generator 1`] = ` +"$Env:PORTAINER_EDGE_ID = "@(Get-MachineGUID)" + +docker network create \` + --driver overlay \` + portainer_agent_network; + +docker service create \` + --name portainer_edge_agent \` + --network portainer_agent_network \` + -e EDGE=1 \` + -e EDGE_ID=$Env:PORTAINER_EDGE_ID \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + -e AGENT_SECRET=test-secret \` + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \` + --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:2.19.0 +" +`; + +exports[`'buildWindowsSwarmCommand' > should generate command with edge groups 1`] = ` +"docker network create \` + --driver overlay \` + portainer_agent_network; + +docker service create \` + --name portainer_edge_agent \` + --network portainer_agent_network \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + -e AGENT_SECRET=test-secret \` + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \` + -e EDGE_GROUPS=1:2:3 \` + --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:2.19.0 +" +`; + +exports[`'buildWindowsSwarmCommand' > should generate command with empty agent secret 1`] = ` +"docker network create \` + --driver overlay \` + portainer_agent_network; + +docker service create \` + --name portainer_edge_agent \` + --network portainer_agent_network \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \` + --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:2.19.0 +" +`; + +exports[`'buildWindowsSwarmCommand' > should generate command with portainer group 1`] = ` +"docker network create \` + --driver overlay \` + portainer_agent_network; + +docker service create \` + --name portainer_edge_agent \` + --network portainer_agent_network \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + -e AGENT_SECRET=test-secret \` + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \` + -e PORTAINER_GROUP=5 \` + --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:2.19.0 +" +`; + +exports[`'buildWindowsSwarmCommand' > should generate command with self-signed certificates allowed 1`] = ` +"docker network create \` + --driver overlay \` + portainer_agent_network; + +docker service create \` + --name portainer_edge_agent \` + --network portainer_agent_network \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=1 \` + -e AGENT_SECRET=test-secret \` + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \` + --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:2.19.0 +" +`; + +exports[`'buildWindowsSwarmCommand' > should generate command with tags 1`] = ` +"docker network create \` + --driver overlay \` + portainer_agent_network; + +docker service create \` + --name portainer_edge_agent \` + --network portainer_agent_network \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + -e AGENT_SECRET=test-secret \` + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \` + -e PORTAINER_TAGS=10:20:30 \` + --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:2.19.0 +" +`; + +exports[`'buildWindowsSwarmCommand' > should generate command without agent secret 1`] = ` +"docker network create \` + --driver overlay \` + portainer_agent_network; + +docker service create \` + --name portainer_edge_agent \` + --network portainer_agent_network \` + -e EDGE=1 \` + -e EDGE_ID=test-edge-id \` + -e EDGE_KEY=test-edge-key \` + -e EDGE_INSECURE_POLL=0 \` + -e AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent \` + --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:2.19.0 +" +`; diff --git a/app/react/edge/components/EdgeScriptForm/scripts.test.ts b/app/react/edge/components/EdgeScriptForm/scripts.test.ts index 7de85ca77..8412d6c01 100644 --- a/app/react/edge/components/EdgeScriptForm/scripts.test.ts +++ b/app/react/edge/components/EdgeScriptForm/scripts.test.ts @@ -1,22 +1,119 @@ -import { buildLinuxPodmanCommand } from './scripts'; +import { + buildLinuxPodmanCommand, + buildLinuxStandaloneCommand, + buildLinuxSwarmCommand, + buildLinuxKubernetesCommand, + buildWindowsStandaloneCommand, + buildWindowsSwarmCommand, +} from './scripts'; import { ScriptFormValues } from './types'; -describe('buildLinuxPodmanCommand', () => { - const defaultProperties: ScriptFormValues = { - allowSelfSignedCertificates: false, - authEnabled: false, - edgeGroupsIds: [], - edgeIdGenerator: '', - envVars: '', - group: 0, - os: 'linux', - platform: 'podman', - tagsIds: [], - tlsEnabled: false, - }; - +describe.each([ + { + name: 'buildLinuxStandaloneCommand', + builder: buildLinuxStandaloneCommand, + defaultProperties: { + allowSelfSignedCertificates: false, + authEnabled: false, + edgeGroupsIds: [], + edgeIdGenerator: '', + envVars: '', + group: 0, + os: 'linux' as const, + platform: 'standalone' as const, + tagsIds: [], + tlsEnabled: false, + }, + edgeIdGeneratorValue: 'uuidgen', + }, + { + name: 'buildLinuxPodmanCommand', + builder: buildLinuxPodmanCommand, + defaultProperties: { + allowSelfSignedCertificates: false, + authEnabled: false, + edgeGroupsIds: [], + edgeIdGenerator: '', + envVars: '', + group: 0, + os: 'linux' as const, + platform: 'podman' as const, + tagsIds: [], + tlsEnabled: false, + }, + edgeIdGeneratorValue: 'uuidgen', + }, + { + name: 'buildLinuxSwarmCommand', + builder: buildLinuxSwarmCommand, + defaultProperties: { + allowSelfSignedCertificates: false, + authEnabled: false, + edgeGroupsIds: [], + edgeIdGenerator: '', + envVars: '', + group: 0, + os: 'linux' as const, + platform: 'swarm' as const, + tagsIds: [], + tlsEnabled: false, + }, + edgeIdGeneratorValue: 'uuidgen', + }, + { + name: 'buildLinuxKubernetesCommand', + builder: buildLinuxKubernetesCommand, + defaultProperties: { + allowSelfSignedCertificates: false, + authEnabled: false, + edgeGroupsIds: [], + edgeIdGenerator: '', + envVars: '', + group: 0, + os: 'linux' as const, + platform: 'k8s' as const, + tagsIds: [], + tlsEnabled: false, + }, + edgeIdGeneratorValue: 'uuidgen', + }, + { + name: 'buildWindowsStandaloneCommand', + builder: buildWindowsStandaloneCommand, + defaultProperties: { + allowSelfSignedCertificates: false, + authEnabled: false, + edgeGroupsIds: [], + edgeIdGenerator: '', + envVars: '', + group: 0, + os: 'win' as const, + platform: 'standalone' as const, + tagsIds: [], + tlsEnabled: false, + }, + edgeIdGeneratorValue: 'Get-MachineGUID', + }, + { + name: 'buildWindowsSwarmCommand', + builder: buildWindowsSwarmCommand, + defaultProperties: { + allowSelfSignedCertificates: false, + authEnabled: false, + edgeGroupsIds: [], + edgeIdGenerator: '', + envVars: '', + group: 0, + os: 'win' as const, + platform: 'swarm' as const, + tagsIds: [], + tlsEnabled: false, + }, + edgeIdGeneratorValue: 'Get-MachineGUID', + }, +])('$name', ({ builder, defaultProperties, edgeIdGeneratorValue }) => { it('should generate basic command with minimal configuration', () => { - const command = buildLinuxPodmanCommand( + const command = builder( '2.19.0', 'test-edge-key', defaultProperties, @@ -29,11 +126,11 @@ describe('buildLinuxPodmanCommand', () => { }); it('should generate command with async mode enabled', () => { - const command = buildLinuxPodmanCommand( + const command = builder( '2.19.0', 'test-edge-key', defaultProperties, - true, // async mode + true, 'test-edge-id', 'test-secret' ); @@ -42,12 +139,12 @@ describe('buildLinuxPodmanCommand', () => { }); it('should generate command with self-signed certificates allowed', () => { - const properties = { + const properties: ScriptFormValues = { ...defaultProperties, allowSelfSignedCertificates: true, }; - const command = buildLinuxPodmanCommand( + const command = builder( '2.19.0', 'test-edge-key', properties, @@ -60,17 +157,17 @@ describe('buildLinuxPodmanCommand', () => { }); it('should generate command with edge ID generator', () => { - const properties = { + const properties: ScriptFormValues = { ...defaultProperties, - edgeIdGenerator: 'uuidgen', + edgeIdGenerator: edgeIdGeneratorValue, }; - const command = buildLinuxPodmanCommand( + const command = builder( '2.19.0', 'test-edge-key', properties, false, - undefined, // no edgeId when using generator + undefined, 'test-secret' ); @@ -78,12 +175,12 @@ describe('buildLinuxPodmanCommand', () => { }); it('should generate command with custom environment variables', () => { - const properties = { + const properties: ScriptFormValues = { ...defaultProperties, envVars: 'MY_VAR=value1,ANOTHER_VAR=value2', }; - const command = buildLinuxPodmanCommand( + const command = builder( '2.19.0', 'test-edge-key', properties, @@ -96,12 +193,12 @@ describe('buildLinuxPodmanCommand', () => { }); it('should generate command with edge groups', () => { - const properties = { + const properties: ScriptFormValues = { ...defaultProperties, edgeGroupsIds: [1, 2, 3], }; - const command = buildLinuxPodmanCommand( + const command = builder( '2.19.0', 'test-edge-key', properties, @@ -114,12 +211,12 @@ describe('buildLinuxPodmanCommand', () => { }); it('should generate command with portainer group', () => { - const properties = { + const properties: ScriptFormValues = { ...defaultProperties, group: 5, }; - const command = buildLinuxPodmanCommand( + const command = builder( '2.19.0', 'test-edge-key', properties, @@ -132,12 +229,12 @@ describe('buildLinuxPodmanCommand', () => { }); it('should generate command with tags', () => { - const properties = { + const properties: ScriptFormValues = { ...defaultProperties, tagsIds: [10, 20, 30], }; - const command = buildLinuxPodmanCommand( + const command = builder( '2.19.0', 'test-edge-key', properties, @@ -150,14 +247,14 @@ describe('buildLinuxPodmanCommand', () => { }); it('should generate command with all meta variables', () => { - const properties = { + const properties: ScriptFormValues = { ...defaultProperties, edgeGroupsIds: [1, 2], group: 5, tagsIds: [10, 20], }; - const command = buildLinuxPodmanCommand( + const command = builder( '2.19.0', 'test-edge-key', properties, @@ -170,7 +267,7 @@ describe('buildLinuxPodmanCommand', () => { }); it('should generate command without agent secret', () => { - const command = buildLinuxPodmanCommand( + const command = builder( '2.19.0', 'test-edge-key', defaultProperties, @@ -183,7 +280,7 @@ describe('buildLinuxPodmanCommand', () => { }); it('should generate command with empty agent secret', () => { - const command = buildLinuxPodmanCommand( + const command = builder( '2.19.0', 'test-edge-key', defaultProperties, diff --git a/app/react/edge/components/EdgeScriptForm/scripts.ts b/app/react/edge/components/EdgeScriptForm/scripts.ts index 457994160..8b4bf94b5 100644 --- a/app/react/edge/components/EdgeScriptForm/scripts.ts +++ b/app/react/edge/components/EdgeScriptForm/scripts.ts @@ -139,29 +139,33 @@ export function buildWindowsStandaloneCommand( ) { const { allowSelfSignedCertificates, edgeIdGenerator, envVars } = properties; - const env = buildDockerEnvVars(envVars, [ - ...buildDefaultDockerEnvVars( - edgeKey, - allowSelfSignedCertificates, - edgeIdGenerator ? '$Env:PORTAINER_EDGE_ID' : edgeId, - agentSecret, - useAsyncMode - ), - ...metaEnvVars(properties), - ]); + const env = buildDockerEnvVars( + envVars, + [ + ...buildDefaultDockerEnvVars( + edgeKey, + allowSelfSignedCertificates, + edgeIdGenerator ? '$Env:PORTAINER_EDGE_ID' : edgeId, + agentSecret, + useAsyncMode + ), + ...metaEnvVars(properties), + ], + '`' + ); return `${ edgeIdGenerator ? `$Env:PORTAINER_EDGE_ID = "@(${edgeIdGenerator})" \n\n` : '' }\ -docker run -d \\ - --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 \\ - --restart always \\ - ${env} \\ - --name portainer_edge_agent \\ +docker run -d \` + --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 \` + --restart always \` + ${env} \` + --name portainer_edge_agent \` portainer/agent:${agentVersion} `; } @@ -219,36 +223,40 @@ export function buildWindowsSwarmCommand( ) { const { allowSelfSignedCertificates, edgeIdGenerator, envVars } = properties; - const env = buildDockerEnvVars(envVars, [ - ...buildDefaultDockerEnvVars( - edgeKey, - allowSelfSignedCertificates, - edgeIdGenerator ? '$Env:PORTAINER_EDGE_ID' : edgeId, - agentSecret, - useAsyncMode - ), - 'AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent', - ...metaEnvVars(properties), - ]); + const env = buildDockerEnvVars( + envVars, + [ + ...buildDefaultDockerEnvVars( + edgeKey, + allowSelfSignedCertificates, + edgeIdGenerator ? '$Env:PORTAINER_EDGE_ID' : edgeId, + agentSecret, + useAsyncMode + ), + 'AGENT_CLUSTER_ADDR=tasks.portainer_edge_agent', + ...metaEnvVars(properties), + ], + '`' + ); return `${ edgeIdGenerator ? `$Env:PORTAINER_EDGE_ID = "@(${edgeIdGenerator})" \n\n` : '' }\ -docker network create \\ - --driver overlay \\ +docker network create \` + --driver overlay \` portainer_agent_network; -docker service create \\ - --name portainer_edge_agent \\ - --network portainer_agent_network \\ - ${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 \\ +docker service create \` + --name portainer_edge_agent \` + --network portainer_agent_network \` + ${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} `; } @@ -278,10 +286,14 @@ export function buildLinuxKubernetesCommand( return `${idEnvVar}curl https://downloads.portainer.io/ee${agentShortVersion}/portainer-edge-agent-setup.sh | bash -s -- "${edgeIdVar}" "${edgeKey}" "${selfSigned}" "${agentSecret}" "${allEnvVars}"`; } -function buildDockerEnvVars(envVars: string, moreVars: string[]) { +function buildDockerEnvVars( + envVars: string, + moreVars: string[], + lineContinuationToken = '\\' +) { const vars = moreVars.concat(envVars.split(',').filter((s) => s.length > 0)); - return vars.map((s) => `-e ${s}`).join(' \\\n '); + return vars.map((s) => `-e ${s}`).join(` ${lineContinuationToken}\n `); } function buildDefaultDockerEnvVars( diff --git a/app/react/portainer/environments/wizard/EnvironmentsCreationView/WizardDocker/AgentTab/DeploymentScripts.tsx b/app/react/portainer/environments/wizard/EnvironmentsCreationView/WizardDocker/AgentTab/DeploymentScripts.tsx index 14f31a687..9f6bd85b1 100644 --- a/app/react/portainer/environments/wizard/EnvironmentsCreationView/WizardDocker/AgentTab/DeploymentScripts.tsx +++ b/app/react/portainer/environments/wizard/EnvironmentsCreationView/WizardDocker/AgentTab/DeploymentScripts.tsx @@ -129,34 +129,35 @@ docker service create \\ function winStandaloneCommand(agentVersion: string, agentSecret: string) { const secret = - agentSecret === '' ? '' : `\\\n -e AGENT_SECRET=${agentSecret} `; + agentSecret === '' ? '' : `\`\n -e AGENT_SECRET=${agentSecret} `; - return `docker run -d \\ - -p 9001:9001 ${secret}\\ - --name portainer_agent \\ - --restart=always \\ - -v C:\\:C:\\host \\ - -v C:\\ProgramData\\docker\\volumes:C:\\ProgramData\\docker\\volumes \\ - -v \\\\.\\pipe\\docker_engine:\\\\.\\pipe\\docker_engine \\ + return `docker run -d \` + -p 9001:9001 ${secret}\` + --name portainer_agent \` + --restart=always \` + -v C:\\:C:\\host \` + -v C:\\ProgramData\\docker\\volumes:C:\\ProgramData\\docker\\volumes \` + -v \\\\.\\pipe\\docker_engine:\\\\.\\pipe\\docker_engine \` portainer/agent:${agentVersion} `; } function winSwarmCommand(agentVersion: string, agentSecret: string) { const secret = - agentSecret === '' ? '' : `\\\n -e AGENT_SECRET=${agentSecret} `; + agentSecret === '' ? '' : `\`\n -e AGENT_SECRET=${agentSecret} `; - return `docker network create \\ ---driver overlay \\ - portainer_agent_network && \\ -docker service create \\ - --name portainer_agent \\ - --network portainer_agent_network \\ - -p 9001:9001/tcp ${secret}\\ - --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 \\ + return `docker network create \` +--driver overlay \` + portainer_agent_network + +docker service create \` + --name portainer_agent \` + --network portainer_agent_network \` + -p 9001:9001/tcp ${secret}\` + --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 \` portainer/agent:${agentVersion} `; }