|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +describe("Docker Compose Generic Deployment implementation", function() { |
| 4 | + // deps |
| 5 | + const path = require("path"); |
| 6 | + const config = require(path.resolve("src/utils/config")); |
| 7 | + const cst = require(path.resolve("src/const")); |
| 8 | + const dockerCompose = require(path.resolve( |
| 9 | + "src/pipeline3/impl/dockerComposeFromArtifact" |
| 10 | + )); |
| 11 | + |
| 12 | + const scripts = require(path.resolve( |
| 13 | + "src/" + config.getJobNameForPipeline3() + "/scripts" |
| 14 | + )); |
| 15 | + |
| 16 | + var instanceDef = { |
| 17 | + uuid: "336af1ee-90a1-4d1b-baaf-db12c84deec0", |
| 18 | + name: "cambodia1", |
| 19 | + type: "dev", |
| 20 | + group: "tlc", |
| 21 | + deployment: { |
| 22 | + hostDir: "/var/docker-volumes/", |
| 23 | + type: "dockerComposeFromArtifact", |
| 24 | + composePlugin: true, |
| 25 | + dockerComposeFiles: ["docker-compose.yml", "docker-compose-2.yml"], |
| 26 | + envFiles: ["env-file-1", "env-file-2"], |
| 27 | + value: { |
| 28 | + projectPath: "/var/docker-volumes/artifacts/run/docker", |
| 29 | + services: ["proxy", "openmrs", "mysql"] |
| 30 | + }, |
| 31 | + timezone: "Europe/Amsterdam", |
| 32 | + host: { |
| 33 | + type: "ssh", |
| 34 | + value: { |
| 35 | + ip: "hsc-dev.mekomsolutions.net", |
| 36 | + user: "mekom", |
| 37 | + port: "22" |
| 38 | + } |
| 39 | + } |
| 40 | + }, |
| 41 | + data: [ |
| 42 | + { |
| 43 | + type: "sqlDocker", |
| 44 | + value: { |
| 45 | + service: "mysql", |
| 46 | + sourceFile: "/var/instance-data/sql-script.sql" |
| 47 | + } |
| 48 | + } |
| 49 | + ] |
| 50 | + }; |
| 51 | + it("should use the correct compose command if composePlugin is set to true", () => { |
| 52 | + var expected = "docker compose"; |
| 53 | + expect(dockerCompose.composeExec(true)).toEqual(expected); |
| 54 | + }); |
| 55 | + |
| 56 | + it("should use the correct compose command if composePlugin is set to false", () => { |
| 57 | + var expected = "docker-compose"; |
| 58 | + expect(dockerCompose.composeExec(false)).toEqual(expected); |
| 59 | + }); |
| 60 | + |
| 61 | + it("should generate the correct compose command given multiple docker compose files", () => { |
| 62 | + var expected = " -f docker-compose.yml -f docker-compose-2.yml "; |
| 63 | + expect( |
| 64 | + dockerCompose.combineComposeFiles( |
| 65 | + instanceDef.deployment.dockerComposeFiles |
| 66 | + ) |
| 67 | + ).toEqual(expected); |
| 68 | + }); |
| 69 | + it("should generate Pre-Host Preparation deployment script", () => { |
| 70 | + var expected = ""; |
| 71 | + expected += scripts.initFolder( |
| 72 | + config.getCDDockerDirPath(instanceDef.uuid), |
| 73 | + "jenkins", |
| 74 | + "jenkins", |
| 75 | + true |
| 76 | + ); |
| 77 | + |
| 78 | + expect( |
| 79 | + dockerCompose.preHostPreparation.getDeploymentScript(instanceDef) |
| 80 | + ).toEqual(expected); |
| 81 | + }); |
| 82 | + |
| 83 | + it("should generate Host Preparation deployment script", () => { |
| 84 | + var expected = ""; |
| 85 | + |
| 86 | + expected += |
| 87 | + scripts.remote( |
| 88 | + instanceDef.deployment.host.value, |
| 89 | + scripts.writeProperty( |
| 90 | + "TIMEZONE", |
| 91 | + instanceDef.deployment.timezone, |
| 92 | + path |
| 93 | + .resolve(instanceDef.deployment.value.projectPath, ".env") |
| 94 | + .toString() |
| 95 | + ) |
| 96 | + ) + "\n"; |
| 97 | + |
| 98 | + expected += |
| 99 | + scripts.remote( |
| 100 | + instanceDef.deployment.host.value, |
| 101 | + scripts.createEnvVarFileDockerGeneric(instanceDef) |
| 102 | + ) + |
| 103 | + "\n" + |
| 104 | + scripts.remote( |
| 105 | + instanceDef.deployment.host.value, |
| 106 | + "cd " + |
| 107 | + path.resolve(instanceDef.deployment.value.projectPath).toString() + |
| 108 | + " && docker compose -p " + |
| 109 | + instanceDef.name + |
| 110 | + " -f docker-compose.yml -f docker-compose-2.yml " + |
| 111 | + " --env-file=env-file-1 --env-file=env-file-2 --env-file=/var/docker-volumes/artifacts/run/docker/cambodia1.env" + |
| 112 | + " build --pull proxy openmrs mysql" + |
| 113 | + "\n" |
| 114 | + ) + |
| 115 | + scripts.remote( |
| 116 | + instanceDef.deployment.host.value, |
| 117 | + "cd " + |
| 118 | + path.resolve(instanceDef.deployment.value.projectPath).toString() + |
| 119 | + " && docker compose -p " + |
| 120 | + instanceDef.name + |
| 121 | + " -f docker-compose.yml -f docker-compose-2.yml " + |
| 122 | + " --env-file=env-file-1 --env-file=env-file-2 --env-file=/var/docker-volumes/artifacts/run/docker/cambodia1.env" + |
| 123 | + " pull proxy openmrs mysql" + |
| 124 | + "\n" |
| 125 | + ) + |
| 126 | + scripts.remote( |
| 127 | + instanceDef.deployment.host.value, |
| 128 | + "sudo chown -R root:root " + |
| 129 | + path |
| 130 | + .resolve(instanceDef.deployment.hostDir, instanceDef.name) |
| 131 | + .toString() |
| 132 | + ); |
| 133 | + let generated = dockerCompose.hostPreparation.getDeploymentScript( |
| 134 | + instanceDef |
| 135 | + ); |
| 136 | + expect(generated).toEqual(expected); |
| 137 | + }); |
| 138 | +}); |
0 commit comments