diff --git a/app/react/edge/components/EdgeScriptForm/__snapshots__/scripts.test.ts.snap b/app/react/edge/components/EdgeScriptForm/__snapshots__/scripts.test.ts.snap new file mode 100644 index 000000000..b01f0366e --- /dev/null +++ b/app/react/edge/components/EdgeScriptForm/__snapshots__/scripts.test.ts.snap @@ -0,0 +1,252 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`buildLinuxPodmanCommand > should generate basic command with minimal configuration 1`] = ` +"sudo systemctl enable --now podman.socket + +sudo podman volume create portainer_agent_data + +sudo podman run -d \\ + -v /run/podman/podman.sock:/var/run/docker.sock \\ + -v /var/lib/containers/storage/volumes:/var/lib/docker/volumes \\ + -v /:/host \\ + -v portainer_agent_data:/data \\ + --restart always \\ + --privileged \\ + -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[`buildLinuxPodmanCommand > should generate command with all meta variables 1`] = ` +"sudo systemctl enable --now podman.socket + +sudo podman volume create portainer_agent_data + +sudo podman run -d \\ + -v /run/podman/podman.sock:/var/run/docker.sock \\ + -v /var/lib/containers/storage/volumes:/var/lib/docker/volumes \\ + -v /:/host \\ + -v portainer_agent_data:/data \\ + --restart always \\ + --privileged \\ + -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[`buildLinuxPodmanCommand > should generate command with async mode enabled 1`] = ` +"sudo systemctl enable --now podman.socket + +sudo podman volume create portainer_agent_data + +sudo podman run -d \\ + -v /run/podman/podman.sock:/var/run/docker.sock \\ + -v /var/lib/containers/storage/volumes:/var/lib/docker/volumes \\ + -v /:/host \\ + -v portainer_agent_data:/data \\ + --restart always \\ + --privileged \\ + -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[`buildLinuxPodmanCommand > should generate command with custom environment variables 1`] = ` +"sudo systemctl enable --now podman.socket + +sudo podman volume create portainer_agent_data + +sudo podman run -d \\ + -v /run/podman/podman.sock:/var/run/docker.sock \\ + -v /var/lib/containers/storage/volumes:/var/lib/docker/volumes \\ + -v /:/host \\ + -v portainer_agent_data:/data \\ + --restart always \\ + --privileged \\ + -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[`buildLinuxPodmanCommand > should generate command with edge ID generator 1`] = ` +"PORTAINER_EDGE_ID=$(uuidgen) + +sudo systemctl enable --now podman.socket + +sudo podman volume create portainer_agent_data + +sudo podman run -d \\ + -v /run/podman/podman.sock:/var/run/docker.sock \\ + -v /var/lib/containers/storage/volumes:/var/lib/docker/volumes \\ + -v /:/host \\ + -v portainer_agent_data:/data \\ + --restart always \\ + --privileged \\ + -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[`buildLinuxPodmanCommand > should generate command with edge groups 1`] = ` +"sudo systemctl enable --now podman.socket + +sudo podman volume create portainer_agent_data + +sudo podman run -d \\ + -v /run/podman/podman.sock:/var/run/docker.sock \\ + -v /var/lib/containers/storage/volumes:/var/lib/docker/volumes \\ + -v /:/host \\ + -v portainer_agent_data:/data \\ + --restart always \\ + --privileged \\ + -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[`buildLinuxPodmanCommand > should generate command with empty agent secret 1`] = ` +"sudo systemctl enable --now podman.socket + +sudo podman volume create portainer_agent_data + +sudo podman run -d \\ + -v /run/podman/podman.sock:/var/run/docker.sock \\ + -v /var/lib/containers/storage/volumes:/var/lib/docker/volumes \\ + -v /:/host \\ + -v portainer_agent_data:/data \\ + --restart always \\ + --privileged \\ + -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[`buildLinuxPodmanCommand > should generate command with portainer group 1`] = ` +"sudo systemctl enable --now podman.socket + +sudo podman volume create portainer_agent_data + +sudo podman run -d \\ + -v /run/podman/podman.sock:/var/run/docker.sock \\ + -v /var/lib/containers/storage/volumes:/var/lib/docker/volumes \\ + -v /:/host \\ + -v portainer_agent_data:/data \\ + --restart always \\ + --privileged \\ + -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[`buildLinuxPodmanCommand > should generate command with self-signed certificates allowed 1`] = ` +"sudo systemctl enable --now podman.socket + +sudo podman volume create portainer_agent_data + +sudo podman run -d \\ + -v /run/podman/podman.sock:/var/run/docker.sock \\ + -v /var/lib/containers/storage/volumes:/var/lib/docker/volumes \\ + -v /:/host \\ + -v portainer_agent_data:/data \\ + --restart always \\ + --privileged \\ + -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[`buildLinuxPodmanCommand > should generate command with tags 1`] = ` +"sudo systemctl enable --now podman.socket + +sudo podman volume create portainer_agent_data + +sudo podman run -d \\ + -v /run/podman/podman.sock:/var/run/docker.sock \\ + -v /var/lib/containers/storage/volumes:/var/lib/docker/volumes \\ + -v /:/host \\ + -v portainer_agent_data:/data \\ + --restart always \\ + --privileged \\ + -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[`buildLinuxPodmanCommand > should generate command without agent secret 1`] = ` +"sudo systemctl enable --now podman.socket + +sudo podman volume create portainer_agent_data + +sudo podman run -d \\ + -v /run/podman/podman.sock:/var/run/docker.sock \\ + -v /var/lib/containers/storage/volumes:/var/lib/docker/volumes \\ + -v /:/host \\ + -v portainer_agent_data:/data \\ + --restart always \\ + --privileged \\ + -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 + " +`; diff --git a/app/react/edge/components/EdgeScriptForm/scripts.test.ts b/app/react/edge/components/EdgeScriptForm/scripts.test.ts new file mode 100644 index 000000000..7de85ca77 --- /dev/null +++ b/app/react/edge/components/EdgeScriptForm/scripts.test.ts @@ -0,0 +1,197 @@ +import { buildLinuxPodmanCommand } 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, + }; + + it('should generate basic command with minimal configuration', () => { + const command = buildLinuxPodmanCommand( + '2.19.0', + 'test-edge-key', + defaultProperties, + false, + 'test-edge-id', + 'test-secret' + ); + + expect(command).toMatchSnapshot(); + }); + + it('should generate command with async mode enabled', () => { + const command = buildLinuxPodmanCommand( + '2.19.0', + 'test-edge-key', + defaultProperties, + true, // async mode + 'test-edge-id', + 'test-secret' + ); + + expect(command).toMatchSnapshot(); + }); + + it('should generate command with self-signed certificates allowed', () => { + const properties = { + ...defaultProperties, + allowSelfSignedCertificates: true, + }; + + const command = buildLinuxPodmanCommand( + '2.19.0', + 'test-edge-key', + properties, + false, + 'test-edge-id', + 'test-secret' + ); + + expect(command).toMatchSnapshot(); + }); + + it('should generate command with edge ID generator', () => { + const properties = { + ...defaultProperties, + edgeIdGenerator: 'uuidgen', + }; + + const command = buildLinuxPodmanCommand( + '2.19.0', + 'test-edge-key', + properties, + false, + undefined, // no edgeId when using generator + 'test-secret' + ); + + expect(command).toMatchSnapshot(); + }); + + it('should generate command with custom environment variables', () => { + const properties = { + ...defaultProperties, + envVars: 'MY_VAR=value1,ANOTHER_VAR=value2', + }; + + const command = buildLinuxPodmanCommand( + '2.19.0', + 'test-edge-key', + properties, + false, + 'test-edge-id', + 'test-secret' + ); + + expect(command).toMatchSnapshot(); + }); + + it('should generate command with edge groups', () => { + const properties = { + ...defaultProperties, + edgeGroupsIds: [1, 2, 3], + }; + + const command = buildLinuxPodmanCommand( + '2.19.0', + 'test-edge-key', + properties, + false, + 'test-edge-id', + 'test-secret' + ); + + expect(command).toMatchSnapshot(); + }); + + it('should generate command with portainer group', () => { + const properties = { + ...defaultProperties, + group: 5, + }; + + const command = buildLinuxPodmanCommand( + '2.19.0', + 'test-edge-key', + properties, + false, + 'test-edge-id', + 'test-secret' + ); + + expect(command).toMatchSnapshot(); + }); + + it('should generate command with tags', () => { + const properties = { + ...defaultProperties, + tagsIds: [10, 20, 30], + }; + + const command = buildLinuxPodmanCommand( + '2.19.0', + 'test-edge-key', + properties, + false, + 'test-edge-id', + 'test-secret' + ); + + expect(command).toMatchSnapshot(); + }); + + it('should generate command with all meta variables', () => { + const properties = { + ...defaultProperties, + edgeGroupsIds: [1, 2], + group: 5, + tagsIds: [10, 20], + }; + + const command = buildLinuxPodmanCommand( + '2.19.0', + 'test-edge-key', + properties, + false, + 'test-edge-id', + 'test-secret' + ); + + expect(command).toMatchSnapshot(); + }); + + it('should generate command without agent secret', () => { + const command = buildLinuxPodmanCommand( + '2.19.0', + 'test-edge-key', + defaultProperties, + false, + 'test-edge-id', + undefined + ); + + expect(command).toMatchSnapshot(); + }); + + it('should generate command with empty agent secret', () => { + const command = buildLinuxPodmanCommand( + '2.19.0', + 'test-edge-key', + defaultProperties, + false, + 'test-edge-id', + '' + ); + + expect(command).toMatchSnapshot(); + }); +}); diff --git a/app/react/edge/components/EdgeScriptForm/scripts.ts b/app/react/edge/components/EdgeScriptForm/scripts.ts index 2e005b2fb..457994160 100644 --- a/app/react/edge/components/EdgeScriptForm/scripts.ts +++ b/app/react/edge/components/EdgeScriptForm/scripts.ts @@ -88,7 +88,7 @@ docker run -d \\ `; } -function buildLinuxPodmanCommand( +export function buildLinuxPodmanCommand( agentVersion: string, edgeKey: string, properties: ScriptFormValues, @@ -113,7 +113,9 @@ function buildLinuxPodmanCommand( edgeIdGenerator ? `PORTAINER_EDGE_ID=$(${edgeIdGenerator}) \n\n` : '' }\ sudo systemctl enable --now podman.socket -sudo podman volume create portainer + +sudo podman volume create portainer_agent_data + sudo podman run -d \\ -v /run/podman/podman.sock:/var/run/docker.sock \\ -v /var/lib/containers/storage/volumes:/var/lib/docker/volumes \\ diff --git a/app/react/portainer/environments/EdgeAutoCreateScriptView/AutomaticEdgeEnvCreation/AutomaticEdgeEnvCreation.tsx b/app/react/portainer/environments/EdgeAutoCreateScriptView/AutomaticEdgeEnvCreation/AutomaticEdgeEnvCreation.tsx index 2671cf6a9..86294b73f 100644 --- a/app/react/portainer/environments/EdgeAutoCreateScriptView/AutomaticEdgeEnvCreation/AutomaticEdgeEnvCreation.tsx +++ b/app/react/portainer/environments/EdgeAutoCreateScriptView/AutomaticEdgeEnvCreation/AutomaticEdgeEnvCreation.tsx @@ -23,6 +23,7 @@ const commands = { commandsTabs.k8sLinux, commandsTabs.swarmLinux, commandsTabs.standaloneLinux, + commandsTabs.podmanLinux, ], win: [commandsTabs.swarmWindows, commandsTabs.standaloneWindow], };