Skip to content

Commit

Permalink
🐛 Add static-report capability to kantra for .net framework
Browse files Browse the repository at this point in the history
Also adds windows container build to image build workflow.

Signed-off-by: David Zager <[email protected]>
  • Loading branch information
djzager committed Jun 26, 2024
1 parent f6f8cce commit a2f50ba
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 10 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/multi-arch-image-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ concurrency:
group: march-build-${{ github.ref }}
cancel-in-progress: true

env:
tag: ${{ github.ref == 'refs/heads/main' && 'latest' || github.ref_name }}

jobs:
image-build:
uses: konveyor/release-tools/.github/workflows/build-push-images.yaml@main
Expand All @@ -26,3 +29,40 @@ jobs:
secrets:
registry_username: ${{ secrets.QUAY_PUBLISH_ROBOT }}
registry_password: ${{ secrets.QUAY_PUBLISH_TOKEN }}

windows-image-build:
runs-on: windows-latest
steps:
- uses: actions/checkout@main
- name: Login to Docker Hub
uses: docker/login-action@master
with:
registry: "quay.io/konveyor"
username: ${{ secrets.QUAY_PUBLISH_ROBOT }}
password: ${{ secrets.QUAY_PUBLISH_TOKEN }}
- name: Build static-report
run: |
docker build -f ./Dockerfile.windows -t quay.io/konveyor/kantra:$env:tag-windowsservercore-ltsc2022 .
docker push quay.io/konveyor/kantra:$env:tag-windowsservercore-ltsc2022
update-manifest:
needs:
- image-build
- windows-image-build
runs-on: ubuntu-latest
steps:
- name: update manifest
run: |
podman manifest create temp
podman manifest add temp --all quay.io/konveyor/kantra:${tag}
podman manifest add temp --all quay.io/konveyor/kantra:${tag}-windowsservercore-ltsc2022
podman tag temp quay.io/konveyor/kantra:${tag}
- name: Push manifest to Quay
uses: redhat-actions/push-to-registry@main
id: push
with:
image: konveyor/kantra
tags: ${{ env.tag }}
username: ${{ secrets.QUAY_PUBLISH_ROBOT }}
password: ${{ secrets.QUAY_PUBLISH_TOKEN }}
registry: quay.io
6 changes: 3 additions & 3 deletions Dockerfile.windows
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG VERSION=latest

# FROM quay.io/konveyor/static-report:${VERSION} as static-report
FROM quay.io/konveyor/static-report:${VERSION} as static-report

FROM mcr.microsoft.com/windows/servercore:ltsc2022 AS rulesets
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
Expand Down Expand Up @@ -61,8 +61,8 @@ RUN md C:\opt\rulesets\input C:\opt\rulesets\convert C:\opt\openrewrite C:\opt\i
# Copy the executable from the builder stage
COPY --from=builder /workspace/kantra.exe .
COPY --from=rulesets /rulesets/default/generated/dotnet8 /opt/rulesets
#COPY --from=static-report /usr/bin/js-bundle-generator .
#COPY --from=static-report /usr/local/static-report .
COPY --from=static-report /usr/bin/js-bundle-generator .
COPY --from=static-report /usr/local/static-report ./static-report

# Command to run the executable
ENTRYPOINT ["kantra.exe"]
56 changes: 49 additions & 7 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -2017,11 +2017,16 @@ func (a *analyzeCommand) analyzeDotnetFramework(ctx context.Context) error {
return err
}

// TODO(djzager): uncomment when provider handles mode correctly
//if a.mode == string(provider.FullAnalysisMode) {
// a.log.V(1).Info("Only source mode analysis is supported")
// a.mode = string(provider.SourceOnlyAnalysisMode)
//}
if a.bulk {
err := fmt.Errorf("Unsupported option")
a.log.Error(err, "Bulk analysis not supported for .NET Framework projects")
return err
}

if a.mode == string(provider.FullAnalysisMode) {
a.log.V(1).Info("Only source mode analysis is supported")
a.mode = string(provider.SourceOnlyAnalysisMode)
}

var err error

Expand Down Expand Up @@ -2215,11 +2220,48 @@ func (a *analyzeCommand) analyzeDotnetFramework(ctx context.Context) error {
}

// Generate Static Report
err = a.GenerateStaticReport(ctx)
if a.skipStaticReport {
return nil
}

err = container.NewContainer().Run(
ctx,
container.WithImage(Settings.RunnerImage),
container.WithLog(a.log.V(1)),
container.WithContainerToolBin(Settings.PodmanBinary),
container.WithEntrypointBin("powershell"),
container.WithEntrypointArgs("Copy-Item", `C:\app\static-report\`, "-Recurse", filepath.FromSlash(OutputPath)),
container.WithVolumes(volumes),
container.WithCleanup(a.cleanup),
)
if err != nil {
return err
}

staticReportArgs := []string{
fmt.Sprintf(`-output-path=C:\%s\static-report\output.js`, filepath.FromSlash(OutputPath)),
fmt.Sprintf("-analysis-output-list=C:%s", filepath.FromSlash(AnalysisOutputMountPath)),
fmt.Sprintf("-application-name-list=%s", filepath.Base(a.input)),
}

//staticReportContainer := container.NewContainer()
a.log.Info("generating static report", "output", a.output, "args", staticReportArgs)
err = container.NewContainer().Run(
ctx,
container.WithImage(Settings.RunnerImage),
container.WithLog(a.log.V(1)),
container.WithContainerToolBin(Settings.PodmanBinary),
container.WithEntrypointBin(`C:\app\js-bundle-generator`),
container.WithEntrypointArgs(staticReportArgs...),
container.WithVolumes(volumes),
container.WithCleanup(a.cleanup),
)
if err != nil {
a.log.Error(err, "failed to generate static report")
return err
}

uri := uri.File(filepath.Join(a.output, "static-report", "index.html"))
a.log.Info("Static report created. Access it at this URL:", "URL", string(uri))

return nil
}

0 comments on commit a2f50ba

Please sign in to comment.