Skip to content

Commit

Permalink
NO-ISSUE: Cherry-pick kie-issues#281 fix to 0.29.0-prerelease (#1684)
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagoelg authored May 30, 2023
1 parent d40a925 commit 3a39765
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 58 deletions.
8 changes: 4 additions & 4 deletions packages/dmn-dev-deployment-base-image/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ ARG ROOT_PATH

USER 1000

RUN mkdir /tmp/kogito/
RUN mkdir -p -m 777 /tmp/kogito

COPY --chown=1000:1000 --chmod=775 dist-dev/dmn-dev-deployment-quarkus-app /tmp/kogito/dmn-dev-deployment-quarkus-app/
COPY --chown=1000:1000 --chmod=775 dist-dev/dmn-dev-deployment-form-webapp/ /tmp/kogito/dmn-dev-deployment-quarkus-app/src/main/resources/META-INF/resources/
COPY --chown=1000:1000 --chmod=777 dist-dev/dmn-dev-deployment-quarkus-app /tmp/kogito/dmn-dev-deployment-quarkus-app/
COPY --chown=1000:1000 --chmod=777 dist-dev/dmn-dev-deployment-form-webapp/ /tmp/kogito/dmn-dev-deployment-quarkus-app/src/main/resources/META-INF/resources/

WORKDIR /tmp/kogito/dmn-dev-deployment-quarkus-app/

RUN ./mvnw clean package -B -ntp -Dmaven.test.skip -Dmaven.repo.local=/tmp/kogito/.m2/repository -DQUARKUS_PLATFORM_VERSION=${QUARKUS_PLATFORM_VERSION} -DKOGITO_RUNTIME_VERSION=${KOGITO_RUNTIME_VERSION} -Dquarkus.http.root-path=${ROOT_PATH} \
&& chmod -R 775 /tmp/kogito/
&& chmod -R 777 /tmp/kogito/
ENTRYPOINT ./mvnw quarkus:dev -Ddebug=false -Dmaven.repo.local=/tmp/kogito/.m2/repository -DQUARKUS_PLATFORM_VERSION=${QUARKUS_PLATFORM_VERSION} -DKOGITO_RUNTIME_VERSION=${KOGITO_RUNTIME_VERSION} -Dquarkus.http.root-path=${ROOT_PATH}
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ function buildArchImage(tag, file, context, buildArg, arch) {
createAndUseDockerBuilder();
console.log(buildArg);
execSync(
`docker buildx build --platform ${platform} --load -t ${tag} ${buildArg.map(
(arg) => `--build-arg ${arg} `
)} ${context} -f ${file}`,
`docker buildx build --platform ${platform} --load -t ${tag} ${buildArg
.map((arg) => `--build-arg ${arg} `)
.join(" ")} ${context} -f ${file}`,
{ stdio: "inherit" }
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@

public interface ZipService {

List<String> unzip(String zipFile, String destination) throws IOException;
List<String> unzip(String zipFilePath, String destination) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,55 @@
package org.kie.kogito.service;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipFile;
import java.util.Enumeration;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class ZipServiceImpl implements ZipService {

@Override
public List<String> unzip(final String zipFile, final String destinationPath) throws IOException {
public List<String> unzip(final String zipFilePath, final String destinationPath) throws IOException {
var filePaths = new ArrayList<String>();
var destinationFolder = new File(destinationPath);
var buffer = new byte[1024];
try (var zis = new ZipInputStream(new FileInputStream(zipFile))) {
var zipEntry = zis.getNextEntry();
while (zipEntry != null) {
var newFile = newFile(destinationFolder, zipEntry);
if (zipEntry.isDirectory()) {
if (!newFile.isDirectory() && !newFile.mkdirs()) {
throw new IOException("Failed to create directory " + newFile);
}
} else {
filePaths.add(newFile.getAbsolutePath());
var parent = newFile.getParentFile();
if (!parent.isDirectory() && !parent.mkdirs()) {
throw new IOException("Failed to create directory " + parent);
}
try (var fos = new FileOutputStream(newFile)) {
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);

try (ZipFile zipFile = new ZipFile(zipFilePath)) {
Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();

while (zipEntries.hasMoreElements()) {
var zipEntry = zipEntries.nextElement();

if (zipEntry != null) {
var newFile = newFile(destinationFolder, zipEntry);
if (zipEntry.isDirectory()) {
if (!newFile.isDirectory() && !newFile.mkdirs()) {
throw new IOException("Failed to create directory " + newFile);
}
} else {
filePaths.add(newFile.getAbsolutePath());
var parent = newFile.getParentFile();
if (!parent.isDirectory() && !parent.mkdirs()) {
throw new IOException("Failed to create directory " + parent);
}
try (var fos = new FileOutputStream(newFile)) {
int len;
var inputStream = zipFile.getInputStream(zipEntry);
while ((len = inputStream.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
}
}
}
zipEntry = zis.getNextEntry();
}
zis.closeEntry();
}

return filePaths;
}

Expand Down
24 changes: 13 additions & 11 deletions packages/workspaces-git-fs/src/services/WorkspaceService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { encoder } from "../encoderdecoder/EncoderDecoder";
import { downloadZip } from "client-zip";
import { downloadZip, predictLength } from "client-zip";
import { WorkspaceDescriptor } from "../worker/api/WorkspaceDescriptor";
import { StorageFile, StorageService } from "./StorageService";
import { basename, join, relative } from "path";
Expand Down Expand Up @@ -159,16 +159,18 @@ export class WorkspaceService {
): Promise<Blob> {
const wwfds = await this.getFilteredWorkspaceFileDescriptors(schema, workspaceId);

const filesToZip = await Promise.all(
wwfds
.filter((wwfd) => !onlyExtensions || onlyExtensions.includes(extractExtension(wwfd.relativePath)))
.map(async (wwfd) => ({
relativePath: wwfd.relativePath,
content: await this.storageService.getFileContent(fs, this.getAbsolutePath(wwfd)),
}))
);

return await downloadZip(filesToZip.map((file) => ({ name: file.relativePath, input: file.content }))).blob();
const filesToZip = (
await Promise.all(
wwfds
.filter((wwfd) => !onlyExtensions || onlyExtensions.includes(extractExtension(wwfd.relativePath)))
.map(async (wwfd) => ({
relativePath: wwfd.relativePath,
content: await this.storageService.getFileContent(fs, this.getAbsolutePath(wwfd)),
}))
)
).map((file) => ({ name: file.relativePath, input: file.content }));

return downloadZip(filesToZip, { length: predictLength(filesToZip) }).blob();
}

public async createOrOverwriteFile(
Expand Down
22 changes: 6 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3a39765

Please sign in to comment.