From 61e60019228c1872c9a320ee3be56af728692735 Mon Sep 17 00:00:00 2001 From: Shawn Hurley Date: Wed, 29 Nov 2023 14:06:09 -0500 Subject: [PATCH] :bug: adding entrypoint to copy source from mount to container (#127) Signed-off-by: Shawn Hurley --- Dockerfile | 1 + cmd/analyze.go | 21 +++++++++++++-------- entrypoint.sh | 7 +++++++ test-data/analysis-output.yaml | 4 ++-- 4 files changed, 23 insertions(+), 10 deletions(-) create mode 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 54593c0..9c8e6fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,5 +40,6 @@ COPY --from=rulesets /rulesets/default/generated /opt/rulesets COPY --from=rulesets /windup-rulesets/rules/rules-reviewed/openrewrite /opt/openrewrite COPY --from=static-report /usr/bin/js-bundle-generator /usr/local/bin COPY --from=static-report /usr/local/static-report /usr/local/static-report +COPY entrypoint.sh /usr/bin/entrypoint.sh ENTRYPOINT ["kantra"] diff --git a/cmd/analyze.go b/cmd/analyze.go index ef8fa14..a7cad34 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -10,6 +10,7 @@ import ( "io/fs" "os" "path" + "runtime" "path/filepath" "sort" @@ -463,15 +464,19 @@ func (a *analyzeCommand) getConfigVolumes() (map[string]string, error) { vols := map[string]string{ tempDir: ConfigMountPath, } + // attempt to create a .m2 directory we can use to speed things a bit // this will be shared between analyze and dep command containers - m2Dir, err := os.MkdirTemp("", "m2-repo-") - if err != nil { - a.log.V(1).Error(err, "failed to create m2 repo", "dir", m2Dir) - } else { - vols[m2Dir] = M2Dir - a.log.V(1).Info("created directory for maven repo", "dir", m2Dir) - a.tempDirs = append(a.tempDirs, m2Dir) + // TODO: when this is fixed on mac and windows for podman machine volume access remove this check. + if runtime.GOOS == "linux" { + m2Dir, err := os.MkdirTemp("", "m2-repo-") + if err != nil { + a.log.V(1).Error(err, "failed to create m2 repo", "dir", m2Dir) + } else { + vols[m2Dir] = M2Dir + a.log.V(1).Info("created directory for maven repo", "dir", m2Dir) + a.tempDirs = append(a.tempDirs, m2Dir) + } } return vols, nil @@ -638,7 +643,7 @@ func (a *analyzeCommand) RunAnalysis(ctx context.Context, xmlOutputDir string) e WithStdout(analysisLog), WithStderr(analysisLog), WithEntrypointArgs(args...), - WithEntrypointBin("/usr/bin/konveyor-analyzer"), + WithEntrypointBin("/usr/bin/entrypoint.sh"), WithCleanup(a.cleanup), ) if err != nil { diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..6567778 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -x + +cp -r /opt/input/source /tmp/source-code +sed -i 's|/opt/input/source|/tmp/source-code|g' /opt/input/config/settings.json +/usr/bin/konveyor-analyzer "$@" +sed -i 's|/tmp/source-code|/opt/input/source|g' /opt/input/config/settings.json diff --git a/test-data/analysis-output.yaml b/test-data/analysis-output.yaml index ba78282..bf4d0bb 100644 --- a/test-data/analysis-output.yaml +++ b/test-data/analysis-output.yaml @@ -240,7 +240,7 @@ - konveyor.io/target=cloud-readiness - discovery incidents: - - uri: file:///opt/input/source/target/classes/persistence.properties + - uri: file:///tmp/source-code/target/classes/persistence.properties message: When migrating environments, hard-coded IP addresses may need to be modified or eliminated. codeSnip: |2 1 jdbc.driverClassName=oracle.jdbc.driver.OracleDriver @@ -252,7 +252,7 @@ lineNumber: 2 variables: matchingText: 169.60.225.216 - - uri: file:///opt/input/source/src/main/resources/persistence.properties + - uri: file:///tmp/source-code/src/main/resources/persistence.properties message: When migrating environments, hard-coded IP addresses may need to be modified or eliminated. codeSnip: |2 1 jdbc.driverClassName=oracle.jdbc.driver.OracleDriver