iotedgedev icon indicating copy to clipboard operation
iotedgedev copied to clipboard

How To copy unittest result out of the container without --output argument

Open bqstony opened this issue 3 years ago • 2 comments

I would like to copy out the unit test results from my docker stage. Normaly i would use for this docker build --target export-test-results --output type=local,dest=testresults . But the --output parameter in the module.json doesent work.

Do you have any other idea to acomplise this?

  • iotedgedev Version: iotedgedev, version 3.3.3

my Dockerfile.amd64

# Build Context is ./../../../
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

HEALTHCHECK --interval=30s --timeout=10s --retries=3 CMD curl --fail http://localhost:80/health || exit 1

# Install prerequisites for healthcheck
RUN apt-get update && apt-get install -y \
    curl && \
    rm -rf /var/lib/apt/lists/*

RUN useradd -ms /bin/bash moduleuser
USER moduleuser

#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim AS build-stage
WORKDIR /app
COPY . ./
RUN dotnet restore ./IotEdge/modules/MyModule.IntegrationTest
RUN dotnet restore ./IotEdge/modules/MyModule.Test

#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
FROM build-stage AS test-stage
RUN dotnet test ./IotEdge/modules/MyModule.IntegrationTest -c Release --logger "console;verbosity=detailed" --logger "trx" --results-directory testresults
RUN dotnet test ./IotEdge/modules/MyModule.Test -c Release --logger "console;verbosity=detailed" --logger "trx" --results-directory testresults

#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
FROM scratch as export-test-results
# it possible to export the files to dockerhost with: docker build --target export-test-results --output type=local,dest=testresults .
COPY --from=test-stage /app/testresults/*.trx .

#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
FROM test-stage AS publish-stage
# Publish this module
RUN dotnet publish ./IotEdge/modules/MyModule -c Release -o out

#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
FROM base as final
WORKDIR /app
COPY --from=publish-stage /app/out ./

ENTRYPOINT ["dotnet", "MyModule.dll"]

my mdoule.json

{
  "$schema-version": "0.0.1",
  "description": "This module receives beacon telemetry messages and observers the individual beacon and his state for generating state messages.",
  "image": {
    "repository": "someregistry.azurecr.io/beaconobserverservice",
    "tag": {
      "version": "22.03.18",
      "platforms": {
        "amd64": "./Dockerfile.amd64",
        "amd64.debug": "./Dockerfile.amd64.debug"
      }
    },
    "buildOptions": [
      "--pull"
    ],
    "contextPath": "./../../../"
  },
  "language": "csharp"
}

bqstony avatar Mar 28 '22 12:03 bqstony

@bqstony thanks for your question, it was added to our backlog.

marianan avatar Apr 01 '22 21:04 marianan

@bqstony - based on https://docs.docker.com/engine/reference/commandline/build/#custom-build-outputs , if your tests are producing the outputs, docker should copy them out to local filesystem without issues. Why do you need to update the module.json?

marianan avatar May 26 '22 17:05 marianan