Skip to content

Conversation

@timdinh
Copy link

@timdinh timdinh commented Jan 25, 2025

Add ability to build docker image

@kiapanahi kiapanahi self-requested a review January 25, 2025 08:24
Comment on lines +36 to +43

resource-server:
image: aspire-resource-server:latest
ports:
- "8043:80"
volumes:
- /var/run/docker.sock:/var/run/docker.sock # This is important so that the resource server can query docker engine

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I created this docker-compose file, the main reason was to create a sample environment from which the resource server could inspect and collect information. I don't see how adding the resource server to the compose file would help. Would you care to shine some light on why this is helpful?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to show how the resource server can be configured with docker compose as an example. User can then point their service to the docker container instance of resource server or the executable.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, I'd appreciate it if you could move this sample compose file into a separate samples directory, preferably with a README.md file describing what the sample directory contains and why it's there.

@kiapanahi kiapanahi linked an issue Jan 25, 2025 that may be closed by this pull request
@kiapanahi
Copy link
Owner

I would also suggest that you add a docker-build.ps1 for PowerShell users as well.
Here's my suggestion:

$ErrorActionPreference = 'Stop'

$current_date = Get-Date -Format "yyyyMMdd"

docker pull mcr.microsoft.com/dotnet/sdk:9.0
docker pull mcr.microsoft.com/dotnet/aspnet:9.0

docker buildx build --platform linux/arm64,linux/amd64 -f Dockerfile `
  -t aspire-resource-server:latest `
  -t aspire-resource-server:$current_date `
  ..

@timdinh
Copy link
Author

timdinh commented Jan 26, 2025

I would also suggest that you add a docker-build.ps1 for PowerShell users as well. Here's my suggestion:

$ErrorActionPreference = 'Stop'

$current_date = Get-Date -Format "yyyyMMdd"

docker pull mcr.microsoft.com/dotnet/sdk:9.0
docker pull mcr.microsoft.com/dotnet/aspnet:9.0

docker buildx build --platform linux/arm64,linux/amd64 -f Dockerfile `
  -t aspire-resource-server:latest `
  -t aspire-resource-server:$current_date `
  ..

I don't have Windows machine to test PowerShell so will leave it to someone else.

@codingzerotohero
Copy link
Contributor

I would also suggest that you add a docker-build.ps1 for PowerShell users as well. Here's my suggestion:

$ErrorActionPreference = 'Stop'

$current_date = Get-Date -Format "yyyyMMdd"

docker pull mcr.microsoft.com/dotnet/sdk:9.0
docker pull mcr.microsoft.com/dotnet/aspnet:9.0

docker buildx build --platform linux/arm64,linux/amd64 -f Dockerfile `
  -t aspire-resource-server:latest `
  -t aspire-resource-server:$current_date `
  ..

I don't have Windows machine to test PowerShell so will leave it to someone else.

I can take a look at setting up this for PowerShell.

@codingzerotohero
Copy link
Contributor

codingzerotohero commented Mar 13, 2025

$ErrorActionPreference = "Stop"

$currentDate = Get-Date -Format "yyyyMMdd"

docker pull mcr.microsoft.com/dotnet/sdk:9.0
docker pull mcr.microsoft.com/dotnet/aspnet:9.0

docker buildx build --platform linux/amd64 -f Dockerfile `
  --build-arg BUILD_CONFIGURATION=Release `
  -t aspire-resource-server:latest `
  -t aspire-resource-server:$currentDate `
  .

@kiapanahi This works fine on my end. However I had to modify the compose.yaml file slightly, to point the Aspire Dashboard to the Resource service container, as well as adding the container to the dev_network:

version: '3.8'

services:
  redis:
    image: redis:latest
    ports:
      - "6379:6379"
    networks:
      - dev_network
  rabbitmq:
    image: rabbitmq:management
    ports:
      - "5672:5672"
      - "15672:15672"
    networks:
      - dev_network
  mongodb:
    image: mongo:latest
    ports:
      - "27017:27017"
    volumes:
      - mongo_data:/data/db
    networks:
      - dev_network
  aspire_dashboard:
    image: mcr.microsoft.com/dotnet/aspire-dashboard:8.2
    environment:
      DASHBOARD__FRONTEND__AUTHMODE: "Unsecured"
      DASHBOARD__RESOURCESERVICECLIENT__URL: "http://resource-server:80"
      DASHBOARD__RESOURCESERVICECLIENT__AUTHMODE: "Unsecured"
    ports:
      - "18888:18888"
      - "4317:18889"
    networks:
      - dev_network
  resource-server:
    image: aspire-resource-server:latest
    ports:
      - "8043:80"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - dev_network
networks:
  dev_network:
    driver: bridge
volumes:
  mysql_data:
  mongo_data:

Also slightly modified the Dockerfile so it works for both Powershell and Bash

FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
WORKDIR /app
EXPOSE 80

ENV DOTNET_CLI_TELEMETRY_OPTOUT=true \
    DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true \
    ASPNETCORE_URLS=http://+:80 \
    ASPNETCORE_ENVIRONMENT=Production

FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
ARG BUILD_CONFIGURATION=Release

WORKDIR /src

COPY src/Aspire.ResourceService.Standalone.Server/Aspire.ResourceService.Standalone.Server.csproj Aspire.ResourceService.Standalone.Server/
COPY src/Aspire.ResourceService.Standalone.ServiceDefaults/Aspire.ResourceService.Standalone.ServiceDefaults.csproj Aspire.ResourceService.Standalone.ServiceDefaults/
COPY Directory.Build.props ./

RUN dotnet restore Aspire.ResourceService.Standalone.Server/Aspire.ResourceService.Standalone.Server.csproj

COPY src/ .

RUN dotnet build Aspire.ResourceService.Standalone.Server/Aspire.ResourceService.Standalone.Server.csproj -f net9.0 -c ${BUILD_CONFIGURATION} -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release

RUN dotnet publish Aspire.ResourceService.Standalone.Server/Aspire.ResourceService.Standalone.Server.csproj -f net9.0 -c ${BUILD_CONFIGURATION} -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .

ENTRYPOINT ["dotnet", "Aspire.ResourceService.Standalone.Server.dll"]

For the purposes I'm using the ResourceService, it would actually be great to have it published to a public image registry. Would you be open to that?

And possibly we should add support for adding settings through environment variables rather than just through appsettings.json, so it would work when running as an image in container. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dockerize the project

3 participants