feat(docker): add local development setup with Docker for AML_Backend

main
fengruixiang 2026-07-02 11:01:14 +08:00
parent 90b929b081
commit c6bff91c45
5 changed files with 165 additions and 0 deletions

View File

@ -1,6 +1,7 @@
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
需要遵守:@AGENTS.md
## Repository Overview

View File

@ -0,0 +1,68 @@
# syntax=docker/dockerfile:1
#
# Local-development image for iCON.Abp.FX.HttpApi.Host (+ DbMigrator).
#
# Differs from src/iCON.Abp.FX.HttpApi.Host/Dockerfile (CI):
# - Targets .NET 6 (the projects are net6.0; the CI Dockerfile still says 5.0).
# - Does not COPY the non-existent src/access-token.bin.
# - Produces two runtime targets: `host` (the API) and `migrator` (data init).
#
# Build context = repository root (AML_Backend). See Dockerfile.local.dockerignore.
############################
# Restore + build (whole solution available)
############################
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
# NuGet.Config carries the ABP commercial feed (the account key is embedded in the URL).
COPY NuGet.Config ./
COPY . .
# Cache the NuGet global-packages folder so context changes don't force a re-download.
RUN --mount=type=cache,target=/root/.nuget/packages \
dotnet restore "src/iCON.Abp.FX.HttpApi.Host/iCON.Abp.FX.HttpApi.Host.csproj" && \
dotnet restore "src/iCON.Abp.FX.DbMigrator/iCON.Abp.FX.DbMigrator.csproj"
############################
# Publish API host
############################
FROM build AS publish-host
ARG BUILD_CONFIGURATION=Release
# -m:1 builds one project at a time to keep peak memory down (this solution's
# DbMigrations project is large enough to OOM Roslyn when compiled in parallel).
RUN --mount=type=cache,target=/root/.nuget/packages \
dotnet publish "src/iCON.Abp.FX.HttpApi.Host/iCON.Abp.FX.HttpApi.Host.csproj" \
-c "$BUILD_CONFIGURATION" -o /app/host /p:UseAppHost=false -m:1
############################
# Publish DbMigrator (schema migration + data seeding)
############################
FROM build AS publish-migrator
ARG BUILD_CONFIGURATION=Release
RUN --mount=type=cache,target=/root/.nuget/packages \
dotnet publish "src/iCON.Abp.FX.DbMigrator/iCON.Abp.FX.DbMigrator.csproj" \
-c "$BUILD_CONFIGURATION" -o /app/migrator /p:UseAppHost=false -m:1
############################
# Runtime: API host
############################
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS host
WORKDIR /app
COPY --from=publish-host /app/host ./
EXPOSE 44331
ENTRYPOINT ["dotnet", "iCON.Abp.FX.HttpApi.Host.dll"]
############################
# Runtime: DbMigrator
# Seed contributors read data files and the full AppConfig relative to the
# app base directory, so we reuse the host's appsettings.json / Data / wwwroot.
############################
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS migrator
WORKDIR /app
COPY --from=publish-migrator /app/migrator ./
COPY --from=publish-host /app/host/appsettings.json ./appsettings.json
COPY --from=publish-host /app/host/Data ./Data
COPY --from=publish-host /app/host/wwwroot ./wwwroot
ENTRYPOINT ["dotnet", "iCON.Abp.FX.DbMigrator.dll"]

View File

@ -0,0 +1,10 @@
# Dedicated ignore file for Dockerfile.local (BuildKit picks <dockerfile>.dockerignore).
# Unlike the repo .dockerignore, this one keeps appsettings*.json so the local
# image is self-contained (config is then overridden via env vars in compose).
**/bin
**/obj
**/.git
**/.vs
**/.vscode
**/node_modules
**/*.user

View File

@ -0,0 +1,86 @@
# Local development stack for iCON.Abp.FX.HttpApi.Host
#
# docker compose -f docker-compose.local.yml up -d --build
#
# Services:
# mssql - SQL Server 2022 (amd64 under Rosetta on Apple Silicon)
# db-migrator - runs once: applies EF migrations + seeds data, then exits
# httpapi-host - the API; waits for a successful migration before starting
#
# After it is up:
# Swagger : http://localhost:44331/swagger
# DB : localhost,11433 (sa / Aml@Local2026)
# Admin : admin / 1q2w3E*
name: aml-local
services:
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
platform: linux/amd64 # Apple Silicon: requires Rosetta emulation in Docker Desktop
container_name: aml-mssql
environment:
ACCEPT_EULA: "Y"
MSSQL_SA_PASSWORD: "Aml@Local2026"
MSSQL_PID: "Developer"
ports:
- "11433:1433"
volumes:
- mssql-data:/var/opt/mssql
healthcheck:
test: ["CMD-SHELL", "/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P \"$$MSSQL_SA_PASSWORD\" -C -Q \"SELECT 1\" -b"]
interval: 10s
timeout: 5s
retries: 30
start_period: 60s
db-migrator:
build:
context: .
dockerfile: Dockerfile.local
target: migrator
image: aml-dbmigrator:local
container_name: aml-dbmigrator
depends_on:
mssql:
condition: service_healthy
environment:
DOTNET_ENVIRONMENT: "Development"
ConnectionStrings__Default: "Server=mssql,1433;Database=AbpAML;User Id=sa;Password=Aml@Local2026;TrustServerCertificate=True;Encrypt=False;"
restart: "no"
httpapi-host:
build:
context: .
dockerfile: Dockerfile.local
target: host
image: aml-httpapi-host:local
container_name: aml-httpapi-host
depends_on:
mssql:
condition: service_healthy
db-migrator:
condition: service_completed_successfully
ports:
- "44331:44331"
volumes:
# ABP commercial license token (from `abp login`). The runtime license
# check reads /root/.abp/cli/access-token.bin; without it the host aborts
# (ABP-LIC-0008). Generate once with: abp login <user> -o <org> -p <pwd>
- "${HOME}/.abp/cli:/root/.abp/cli:ro"
environment:
ASPNETCORE_ENVIRONMENT: "Development"
ASPNETCORE_URLS: "http://+:44331"
ConnectionStrings__Default: "Server=mssql,1433;Database=AbpAML;User Id=sa;Password=Aml@Local2026;TrustServerCertificate=True;Encrypt=False;"
# IdentityServer issuer / self URL must match the URL used by the browser.
App__SelfUrl: "http://localhost:44331"
AuthServer__Authority: "http://localhost:44331"
AuthServer__RequireHttpsMetadata: "false"
# Silence integrations that point at unreachable infra in local dev.
AppConfig__RabbitMQConfig__EnableConsumer: "false"
AppConfig__RabbitMQConfig__HostName: "127.0.0.1"
AppConfig__JobConfig__SanctionJob__Enabled: "false"
AppConfig__JobConfig__EngineListSyncJob__Enabled: "false"
restart: unless-stopped
volumes:
mssql-data: