This is an automated email from the ASF dual-hosted git repository.

tiagobento pushed a commit to branch 10.0.x
in repository https://gitbox.apache.org/repos/asf/incubator-kie-tools.git


The following commit(s) were added to refs/heads/10.0.x by this push:
     new a17692ef212 [10.0.x] NO-ISSUE: Build for linux-arm64 and improve/fix 
tests for dev-deployment-upload-service (#2502)
a17692ef212 is described below

commit a17692ef21252df68c53980ae3ec85297ac83225
Author: Thiago Lugli <[email protected]>
AuthorDate: Wed Jul 31 19:11:46 2024 -0300

    [10.0.x] NO-ISSUE: Build for linux-arm64 and improve/fix tests for 
dev-deployment-upload-service (#2502)
---
 packages/dev-deployment-upload-service/Makefile    |  6 +-
 .../dev/Containerfile.ddus-fileserver              |  2 +-
 .../getDevDeploymentUploadService.sh               |  2 +-
 .../dev-deployment-upload-service/package.json     |  4 +-
 .../scripts/runTestServers.js                      | 65 ++++++++++++++++------
 .../__snapshots__/integrationTest.test.js.snap     |  4 +-
 .../tests/integrationTest.test.js                  |  9 ++-
 7 files changed, 67 insertions(+), 25 deletions(-)

diff --git a/packages/dev-deployment-upload-service/Makefile 
b/packages/dev-deployment-upload-service/Makefile
index 0b57edda99d..ccd759783ad 100644
--- a/packages/dev-deployment-upload-service/Makefile
+++ b/packages/dev-deployment-upload-service/Makefile
@@ -1,12 +1,16 @@
 LDFLAGS := "-w"
 DDUS_VERSION?=0.0.0
 
-build-all: linux-amd64 darwin-amd64 darwin-arm64 win32-amd64 checksum
+build-all: linux-amd64 linux-arm64 darwin-amd64 darwin-arm64 win32-amd64 
checksum
 
 linux-amd64:
        cross-env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags 
$(LDFLAGS) -o dist/dev-deployment-upload-service-linux-amd64 main.go
        tar -zcvf 
dist/dev-deployment-upload-service-linux-amd64-$(DDUS_VERSION).tar.gz -C dist 
dev-deployment-upload-service-linux-amd64
 
+linux-arm64:
+       cross-env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags 
$(LDFLAGS) -o dist/dev-deployment-upload-service-linux-arm64 main.go
+       tar -zcvf 
dist/dev-deployment-upload-service-linux-arm64-$(DDUS_VERSION).tar.gz -C dist 
dev-deployment-upload-service-linux-arm64
+
 darwin-amd64:
        cross-env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags 
$(LDFLAGS) -o dist/dev-deployment-upload-service-darwin-amd64 main.go
        tar -zcvf 
dist/dev-deployment-upload-service-darwin-amd64-$(DDUS_VERSION).tar.gz -C dist 
dev-deployment-upload-service-darwin-amd64
diff --git 
a/packages/dev-deployment-upload-service/dev/Containerfile.ddus-fileserver 
b/packages/dev-deployment-upload-service/dev/Containerfile.ddus-fileserver
index 1b7441db6d4..317871ea51c 100644
--- a/packages/dev-deployment-upload-service/dev/Containerfile.ddus-fileserver
+++ b/packages/dev-deployment-upload-service/dev/Containerfile.ddus-fileserver
@@ -15,7 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
-FROM --platform=linux/amd64 registry.access.redhat.com/ubi9/ubi-minimal:9.4
+FROM registry.access.redhat.com/ubi9/ubi-minimal:9.4
 
 ARG DDUS_VERSION="0.0.0"
 
diff --git 
a/packages/dev-deployment-upload-service/getDevDeploymentUploadService.sh 
b/packages/dev-deployment-upload-service/getDevDeploymentUploadService.sh
index 2a06cfbbaed..db312611f88 100755
--- a/packages/dev-deployment-upload-service/getDevDeploymentUploadService.sh
+++ b/packages/dev-deployment-upload-service/getDevDeploymentUploadService.sh
@@ -73,7 +73,7 @@ runAsRoot() {
 
 # Checks that the necessary tools are present.
 verifySupported() {
-  local supported="darwin-amd64\ndarwin-arm64\nlinux-amd64\nwindows-amd64"
+  local 
supported="darwin-amd64\ndarwin-arm64\nlinux-amd64\nlinux-arm64\nwindows-amd64"
   if ! echo "${supported}" | grep -q "${OS}-${ARCH}"; then
     echo "No prebuilt binary for ${OS}-${ARCH}."
     exit 1
diff --git a/packages/dev-deployment-upload-service/package.json 
b/packages/dev-deployment-upload-service/package.json
index 9eca084176f..ed087b786ce 100644
--- a/packages/dev-deployment-upload-service/package.json
+++ b/packages/dev-deployment-upload-service/package.json
@@ -30,8 +30,8 @@
     "start-test-servers": "run-script-if --bool \"$(build-env 
containerImages.build)\" --then \"node scripts/runTestServers.js\"",
     "stop-test-servers": "run-script-if --bool \"$(build-env 
containerImages.build)\" --then \"node scripts/runTestServers.js --cleanup\"",
     "test": "run-script-os",
-    "test:linux": "run-script-if --bool \"$(build-env containerImages.build)\" 
--bool \"$(build-env endToEndTests.run)\" --ignore-errors \"$(build-env 
tests.ignoreFailures)\" --then  \"jest --verbose --silent=false\"",
-    "test:win32:darwin": "echo 'Not supported'"
+    "test:linux:darwin": "run-script-if --bool \"$(build-env 
containerImages.build)\" --bool \"$(build-env endToEndTests.run)\" 
--ignore-errors \"$(build-env tests.ignoreFailures)\" --then  \"jest --verbose 
--silent=false\"",
+    "test:win32": "echo 'Not supported'"
   },
   "devDependencies": {
     "@kie-tools/jest-base": "workspace:*",
diff --git a/packages/dev-deployment-upload-service/scripts/runTestServers.js 
b/packages/dev-deployment-upload-service/scripts/runTestServers.js
index 43422ec7afa..411e2bf0651 100644
--- a/packages/dev-deployment-upload-service/scripts/runTestServers.js
+++ b/packages/dev-deployment-upload-service/scripts/runTestServers.js
@@ -31,25 +31,42 @@ const containersNames = {
   runTimeInstall: "ddus-runtime-install",
 };
 
+const imagesNames = {
+  fileserver: `${containersNames.fileserver}-image`,
+  buildtimeInstall: `${containersNames.buildtimeInstall}-image`,
+  runTimeInstall: `${containersNames.runTimeInstall}-image`,
+};
+
 const containersPorts = {
   fileserver: buildEnv.env.devDeploymentUploadService.dev.fileServerPort,
   buildtimeInstall: buildEnv.env.devDeploymentUploadService.dev.buildTimePort,
   runTimeInstall: buildEnv.env.devDeploymentUploadService.dev.runtTimePort,
 };
 
+function runCommand(command, returnResult = false) {
+  console.log(`> ${command}`);
+  return execSync(command, returnResult ? {} : { stdio: "inherit" });
+}
+
 function cleanup() {
   try {
-    execSync(`docker stop ${containersNames.fileserver} && docker rm 
${containersNames.fileserver}`);
+    execSync(
+      `docker stop ${containersNames.fileserver} && docker rm 
${containersNames.fileserver} && docker image rm ${imagesNames.fileserver}`
+    );
   } catch (e) {
     // nothing to do
   }
   try {
-    execSync(`docker stop ${containersNames.buildtimeInstall} && docker rm 
${containersNames.buildtimeInstall}`);
+    execSync(
+      `docker stop ${containersNames.buildtimeInstall} && docker rm 
${containersNames.buildtimeInstall} && docker image rm 
${imagesNames.buildtimeInstall}`
+    );
   } catch (e) {
     // nothing to do
   }
   try {
-    execSync(`docker stop ${containersNames.runTimeInstall} && docker rm 
${containersNames.runTimeInstall}`);
+    execSync(
+      `docker stop ${containersNames.runTimeInstall} && docker rm 
${containersNames.runTimeInstall} && docker image rm 
${imagesNames.runTimeInstall}`
+    );
   } catch (e) {
     // nothing to do
   }
@@ -72,21 +89,27 @@ if (argv[2] === "--cleanup") {
 
 try {
   console.info(`Checking existing ${network}...`);
-  execSync(`docker network inspect ${network}`);
+  runCommand(`docker network inspect ${network}`);
   console.info("Netowork found!");
 } catch (e) {
   console.info("Network not found. Creating it!");
-  execSync(`docker network create --ipv6=false ${network}`, { stdio: "inherit" 
});
+  runCommand(`docker network create --ipv6=false ${network}`);
 }
 
 let fileServerIp;
 try {
   console.info(`Starting File Server container: 
${containersNames.fileserver}`);
-  execSync(
-    `docker run -d --name ${containersNames.fileserver} --network ${network} 
-p ${containersPorts.fileserver}:8090 $(docker buildx build -q --build-arg 
DDUS_VERSION=${version} --build-arg 
DDUS_FILESERVER_PORT=${containersPorts.fileserver} . -f 
./dev/Containerfile.${containersNames.fileserver} --load)`,
+  runCommand(
+    `docker buildx build -t ${imagesNames.fileserver} --build-arg 
DDUS_VERSION=${version} --build-arg 
DDUS_FILESERVER_PORT=${containersPorts.fileserver} . -f 
./dev/Containerfile.${containersNames.fileserver} --load`,
+    { stdio: "inherit" }
+  );
+  runCommand(
+    `docker run -d --name ${containersNames.fileserver} --network ${network} 
-p ${containersPorts.fileserver}:8090 ${imagesNames.fileserver}`,
     { stdio: "inherit" }
   );
-  fileServerIp = execSync(`docker exec ${containersNames.fileserver} awk 
'END{print $1}' /etc/hosts`).toString().trim();
+  fileServerIp = runCommand(`docker exec ${containersNames.fileserver} awk 
'END{print $1}' /etc/hosts`, true)
+    .toString()
+    .trim();
 } catch (e) {
   cleanup();
   throw new Error(`Failed to build and start ${containersNames.fileserver}. 
Exiting!`);
@@ -94,10 +117,10 @@ try {
 
 try {
   console.info(`Creating docker builder: ${builder}`);
-  execSync(`docker buildx create --name ${builder} --driver docker-container 
--driver-opt network=${network}`, {
+  runCommand(`docker buildx create --name ${builder} --driver docker-container 
--driver-opt network=${network}`, {
     stdio: "inherit",
   });
-  execSync("docker buildx ls", { stdio: "inherit" });
+  runCommand("docker buildx ls", { stdio: "inherit" });
 } catch (e) {
   cleanup();
   throw new Error(`Failed to create builder ${builder}. Exiting!`);
@@ -105,8 +128,12 @@ try {
 
 try {
   console.info(`Starting BuildTime Install container: 
${containersNames.buildtimeInstall}`);
-  execSync(
-    `docker run -d --name ${containersNames.buildtimeInstall} --network 
${network} -p ${containersPorts.buildtimeInstall}:8091 $(docker buildx 
--builder ${builder} build -q --build-arg DDUS_VERSION=${version} --build-arg 
DDUS_FILESERVER_PORT=8090 --build-arg DDUS_FILESERVER_IP=${fileServerIp} . -f 
./dev/Containerfile.${containersNames.buildtimeInstall} --load)`,
+  runCommand(
+    `docker buildx --builder ${builder} build -t 
${imagesNames.buildtimeInstall} --build-arg DDUS_VERSION=${version} --build-arg 
DDUS_FILESERVER_PORT=8090 --build-arg DDUS_FILESERVER_IP=${fileServerIp} . -f 
./dev/Containerfile.${containersNames.buildtimeInstall} --load`,
+    { stdio: "inherit" }
+  );
+  runCommand(
+    `docker run -d --name ${containersNames.buildtimeInstall} --network 
${network} -p ${containersPorts.buildtimeInstall}:8091 
${imagesNames.buildtimeInstall}`,
     { stdio: "inherit" }
   );
 } catch (e) {
@@ -116,8 +143,12 @@ try {
 
 try {
   console.info(`Starting RunTime Install container: 
${containersNames.runTimeInstall}`);
-  execSync(
-    `docker run -d --name ${containersNames.runTimeInstall} --network 
${network} -p ${containersPorts.runTimeInstall}:8092 -e 
DDUS_FILESERVER_IP=${fileServerIp} -e DDUS_VERSION=${version} -e 
DDUS_FILESERVER_PORT=8090 $(docker buildx --builder ${builder} build -q . -f 
./dev/Containerfile.${containersNames.runTimeInstall} --load)`,
+  runCommand(
+    `docker buildx --builder ${builder} build -t ${imagesNames.runTimeInstall} 
. -f ./dev/Containerfile.${containersNames.runTimeInstall} --load`,
+    { stdio: "inherit" }
+  );
+  runCommand(
+    `docker run -d --name ${containersNames.runTimeInstall} --network 
${network} -p ${containersPorts.runTimeInstall}:8092 -e 
DDUS_FILESERVER_IP=${fileServerIp} -e DDUS_VERSION=${version} -e 
DDUS_FILESERVER_PORT=8090 ${imagesNames.runTimeInstall}`,
     { stdio: "inherit" }
   );
 } catch (e) {
@@ -125,12 +156,12 @@ try {
   throw new Error(`Failed to build and start 
${containersNames.runTimeInstall}. Exiting!`);
 }
 
-execSync("docker ps -f name=ddus", { stdio: "inherit" });
+runCommand("docker ps -f name=ddus", { stdio: "inherit" });
 
-execSync("sleep 10");
+runCommand("sleep 10");
 
 Object.values(containersNames).forEach((name) => {
-  const logs = execSync(`docker logs ${name}`).toString();
+  const logs = runCommand(`docker logs ${name}`, true).toString();
   console.info(`Checking logs for ${name}:`);
   console.info("--------------------------");
   console.info(logs);
diff --git 
a/packages/dev-deployment-upload-service/tests/__snapshots__/integrationTest.test.js.snap
 
b/packages/dev-deployment-upload-service/tests/__snapshots__/integrationTest.test.js.snap
index aa41045e62f..6a0928a71ef 100644
--- 
a/packages/dev-deployment-upload-service/tests/__snapshots__/integrationTest.test.js.snap
+++ 
b/packages/dev-deployment-upload-service/tests/__snapshots__/integrationTest.test.js.snap
@@ -36,9 +36,9 @@ exports[`Test built images individually runtime install 1`] = 
`
 `;
 
 exports[`Test built images individually runtime install 2`] = `
-"Downloading 
<ddus-fileserver-ip>:8090/apache/incubator-kie-tools/releases/download/0.0.0/dev-deployment-upload-service-linux-amd64-0.0.0.tar.gz
+"Downloading 
<ddus-fileserver-ip>:8090/apache/incubator-kie-tools/releases/download/<ddus-version>/dev-deployment-upload-service-<platform-arch>-<ddus-version>.tar.gz
 Verifying checksum... Done.
-Preparing to install dev-deployment-upload-service-linux-amd64 into 
/usr/local/bin
+Preparing to install dev-deployment-upload-service-<platform-arch> into 
/usr/local/bin
 dev-deployment-upload-service installed into 
/usr/local/bin/dev-deployment-upload-service.
 [dev-deployment-upload-service] ✅ Created directory '/tmp/unzip-at'.
 [dev-deployment-upload-service] ℹ️  Starting HTTP server...
diff --git 
a/packages/dev-deployment-upload-service/tests/integrationTest.test.js 
b/packages/dev-deployment-upload-service/tests/integrationTest.test.js
index b4308286770..8c1164b4b9a 100644
--- a/packages/dev-deployment-upload-service/tests/integrationTest.test.js
+++ b/packages/dev-deployment-upload-service/tests/integrationTest.test.js
@@ -20,6 +20,7 @@
 const { execSync, execFileSync } = require("child_process");
 const path = require("path");
 const buildEnv = require("../env");
+const version = require("../package.json").version;
 
 const filePath = path.join(process.cwd(), "tests/test.zip");
 
@@ -29,6 +30,10 @@ const containersPorts = {
   runTimeInstall: buildEnv.env.devDeploymentUploadService.dev.runtTimePort,
 };
 
+const dockerInfo = JSON.parse(execSync(`docker info --format '{{ json . 
}}'`).toString().trim());
+const platform = dockerInfo["OSType"];
+const arch = dockerInfo["Architecture"] === "aarch64" ? "arm64" : "amd64";
+
 describe("Test built images individually", () => {
   beforeAll(() => {
     execSync(
@@ -64,7 +69,9 @@ describe("Test built images individually", () => {
     ]).toString();
     const dockerLogs = execSync(`docker logs ddus-runtime-install`)
       .toString()
-      .replace(/http:\/\/.*:/, "<ddus-fileserver-ip>:");
+      .replace(/http:\/\/.*:/, "<ddus-fileserver-ip>:")
+      .replaceAll(version, "<ddus-version>")
+      .replaceAll(`${platform}-${arch}`, "<platform-arch>");
     expect(response).toMatchSnapshot();
     expect(dockerLogs).toMatchSnapshot();
   });


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to