Azure / iotedgedev

The Azure IoT Edge Dev Tool greatly simplifies your Azure IoT Edge development process. It has everything you need to get started and helps with your day-to-day Edge development.
https://aka.ms/iotedgedev
Other
160 stars 71 forks source link

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

Open bqstony opened 2 years ago

bqstony commented 2 years ago

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?

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"
}
marianan commented 2 years ago

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

marianan commented 2 years ago

@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?